lamp构建

安装apache

//下载epel源
[root@lzx ~]# yum -y install epel-release
//安装工具包
[root@lzx ~]# yum groups mark install 'Development Tools' -y
//创建用户
[root@lzx ~]# useradd -r -M -s /sbin/nologin apache
//安装依赖包
[root@lzx ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

下载和解压httpd、apr以及apr-util
[root@lzx src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.49.tar.gz
[root@lzx src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz
[root@lzx src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@lzx src]# tar xf httpd-2.4.49.tar.gz 
[root@lzx src]# tar xf apr-util-1.6.1.tar.gz 
[root@lzx src]# tar xf apr-1.7.0.tar.gz 
// 安装EPEL rpm 包
[root@lzx apr-1.7.0]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
[root@lzx apr-1.7.0]# ls /etc/yum.repos.d/epel-modular.repo     epel-testing-modular.repo  wjj.repo
epel-playground.repo  epel-testing.repo
epel.repo             redhat.repo
[root@lzx apr-1.7.0]# yum clean all    //清理缓存
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
33 文件已删除
[root@lzx apr-1.7.0]# yum makecache   //重新建立缓存
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Extra Packages for Enterprise Linux  563 kB/s | 955 kB     00:01    
Extra Packages for Enterprise Linux  616 kB/s |  10 MB     00:17    
BaseOS                               164 MB/s | 2.3 MB     00:00    
AppStream                            126 MB/s | 5.8 MB     00:00    
元数据缓存已建立。

// 安装开发工具包
[root@lzx apr-1.7.0]# yum groups mark install 'Development Tools' -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
上次元数据过期检查:0:01:26 前,执行于 2021年09月23日 星期四 17时49分10秒。
依赖关系解决。
=====================================================================
 软件包         架构          版本              仓库            大小
=====================================================================
安装组:
 Development Tools


事务概要
=====================================================================

完毕!

// 创建apache服务的用户和组
[root@lzx src]# useradd -r -M -s /sbin/nologin apache

// 安装依赖包
[root@lzx src]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make

// 编译安装apr-1.7.0、apr-util-1.6.1、httpd-2.4.49
[root@lzx apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@lzx apr-1.7.0]# make && make install
[root@lzx apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@lzx apr-util-1.6.1]# make && make install
[root@lzx httpd-2.4.49]# ./configure --prefix=/usr/local/apache \
> --enable-so \
> --enable-ssl \
> --enable-cgi \
> --enable-rewrite \
> --with-zlib \
> --with-pcre \
> --with-apr=/usr/local/apr/ \
> --with-apr-util=/usr/local/apr-util/ \
> --enable-modules=most \
> --enable-mpms-shared=all \
> --with-mpm=prefork
[root@lzx httpd-2.4.49]# make && make install

// 安装后配置
[root@lzx ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@lzx ~]# source /etc/profile.d/httpd.sh 
[root@lzx ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@lzx ~]# vim /etc/man_db.conf 
20 MANDATORY_MANPATH                       /usr/man
21 MANDATORY_MANPATH                       /usr/share/man
22 MANDATORY_MANPATH                       /usr/local/share/man
23 MANDATORY_MANPATH                       /usr/local/apache/man     // 把apache加进去

//取消ServerName前面的注释
[root@lzx ~]# vim /usr/local/apache/conf/httpd.conf
203 ServerName www.example.com:80

//启动apache
[root@lzx ~]# apachectl start
[root@lzx ~]# ss -antl
State   Recv-Q  Send-Q     Local Address:Port     Peer Address:Port  
LISTEN  0       80                     *:3306                *:*     

// 配置开机自启
[root@lzx ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/httpd.service
[root@lzx ~]# vim /usr/lib/systemd/system/httpd.service
[root@lzx ~]# cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=Httpd server daemon
Documentation=man:httpd(8)
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecStop=/usr/local/apache/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@lzx ~]# systemctl daemon-reload 
[root@lzx ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@lzx ~]# systemctl status httpd.service 
● httpd.service - Httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; v>
   Active: active (running) since Thu 2021-09-23 18:47:11 CST; 10s a>
     Docs: man:httpd(8)

安装mysql

// 安装依赖包
[root@lzx ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

// 下载mysql软件包
[root@lzx src]# ls
apr-1.7.0              httpd-2.4.49
apr-1.7.0.tar.gz       httpd-2.4.49.tar.gz
apr-util-1.6.1         kernels
apr-util-1.6.1.tar.gz  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
debug

//创建用户和组
[root@lzx ~]# useradd -r -M -s /sbin/nologin mysql

//解压软件至/usr/local/
[root@lzx src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@lzxsrc]# cd /usr/local/
[root@lzx local]# mv mysql-5.7.34-linux-glibc2.12-x86_64/ mysql

//修改目录/usr/local/mysql的属主属组
[root@lzx local]# chown -R mysql.mysql mysql/

//添加环境变量
[root@lzx ~]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@lzx ~]# source /etc/profile.d/mysql.sh 
[root@lzx ~]# vim /etc/man_db.conf
20 MANDATORY_MANPATH                       /usr/man
21 MANDATORY_MANPATH                       /usr/share/man
22 MANDATORY_MANPATH                       /usr/local/share/man
23 MANDATORY_MANPATH                       /usr/local/apache/man
24 MANDATORY_MANPATH                       /usr/local/mysql/man      //把mysql加进去
[root@lzx ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql/

// 写一个配置文件,告诉库文件lib在/usr/local/mysql下面
[root@lzx ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@lzx ~]# ldconfig 

//建立数据存放目录
[root@lzx ~]# ldconfig 
[root@lzx ~]# mkdir /opt/data
[root@lzx ~]# chown -R mysql.mysql /opt/data/

//初始化数据库
[root@lzx ~]# mysqld --initialize-insecure --user mysql --datadir /opt/data
2021-09-23T11:04:41.643189Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-23T11:04:41.799190Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-23T11:04:41.821815Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-23T11:04:41.875518Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0d6341e8-1c5e-11ec-b0eb-000c29f6d306.
2021-09-23T11:04:41.876088Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-23T11:04:42.525643Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-23T11:04:42.602903Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

//配置mysql
[root@lzx ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve

//配置服务启动脚本
[root@lzx ~]# vim /usr/local/mysql/support-files/mysql.server
 46 basedir=/usr/local/mysql
 47 datadir=/opt/data
[root@lzx ~]# cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/mysqld.service
[root@lzx ~]# cat /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

//启动mysql
[root@lzx ~]# systemctl daemon-reload 
[root@lzx ~]# systemctl enable --now mysqld.service
[root@lzx ~]# ss -antl
State   Recv-Q  Send-Q     Local Address:Port     Peer Address:Port  
LISTEN  0       80                     *:3306                *:*   
[root@lzx ~]# systemctl status mysqld.service 
● mysqld.service - mysql server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; >
   Active: active (running) since Thu 2021-09-23 19:14:13 CST; 13s a>
  Process: 673923 ExecStart=/usr/local/mysql/support-files/mysql.ser>
 Main PID: 673945 (mysqld_safe)

//修改密码
[root@lzx ~]# yum -y install ncurses-compat-libs
[root@lzx ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('lzx!');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye

安装php

//安装依赖包
[root@lzx ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel
[root@lzx ~]# yum -y install php-mysqlnd

// 在php.net网站上下载php软件包,然后传到/usr/src下面去,再解压
[root@lzx src]# ls
apr-1.7.0              httpd-2.4.49
apr-1.7.0.tar.gz       httpd-2.4.49.tar.gz
apr-util-1.6.1         kernels
apr-util-1.6.1.tar.gz  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
debug                  php-8.0.10.tar.xz
[root@lzx src]# tar xf php-8.0.10.tar.xz 

//编译安装php
[root@lzx php-8.0.10]# yum -y install libsqlite3x-devel
[root@lzx src]# yum install autoconf automake libtool -y
[root@lzx src]# wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
[root@lzx src]# tar xf oniguruma-6.9.4.tar.gz 
[root@lzx src]# cd oniguruma-6.9.4/
[root@lzx src]# ./autogen.sh && ./configure --prefix=/usr
[root@lzx src]# make && make install
[root@lzx php-8.0.10]# yum -y install libzip-devel
[root@lzx php-8.0.10]# ./configure --prefix=/usr/local/php8  \
> --with-config-file-path=/etc \
> --enable-fpm \
> --disable-debug \
> --disable-rpath \
> --enable-shared \
> --enable-soap \
> --with-openssl \
> --enable-bcmath \
> --with-iconv \
> --with-bz2 \
> --enable-calendar \
> --with-curl \
> --enable-exif  \
> --enable-ftp \
> --enable-gd \
> --with-jpeg \
> --with-zlib-dir \
> --with-freetype \
> --with-gettext \
> --enable-mbstring \
> --enable-pdo \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-readline \
> --enable-shmop \
> --enable-simplexml \
> --enable-sockets \
> --with-zip \
> --enable-mysqlnd-compression-support \
> --with-pear \
> --enable-pcntl \
> --enable-posix
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.
[root@lzx php-8.0.10]# make && make install

//安装后配置
[root@lzx ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@lzx ~]# source /etc/profile.d/php.sh 
[root@lzx php-8.0.10]# which php
/usr/local/php8/bin/php
[root@lzx php-8.0.10]# php -v
PHP 8.0.10 (cli) (built: Sep 23 2021 20:29:40) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies

//配置php-fpm
[root@lzx php-8.0.10]# cp php.ini-production /etc/php.ini 
cp:是否覆盖'/etc/php.ini'? y
[root@lzx php-8.0.10]# cd sapi/
[root@lzx sapi]# cp fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lzx sapi]# chmod +x /etc//init.d/php-fpm 
[root@lzx php-8.0.10]# cd /usr/local/php8/
[root@lzx php8]# cd etc/
[root@lzx etc]# cp php-fpm.conf.default php-fpm.conf
[root@lzx etc]# cd php-fpm.d/
[root@lzx php-fpm.d]# cp www.conf.default www.conf

//启动php-fpm
[root@lzx ~]# cp /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/php-fpm.service
[root@lzx ~]# vim /usr/lib/systemd/system/php-fpm.service
[root@lzx ~]# systemctl daemon-reload 
[root@lzx ~]# systemctl enable --now php-fpm
[root@lzx ~]# ss -antl
State   Recv-Q  Send-Q     Local Address:Port     Peer Address:Port  
LISTEN  0       128            127.0.0.1:9000          0.0.0.0:*     
LISTEN  0       80                     *:3306                *:* 
LISTEN  0       128              0.0.0.0:80            0.0.0.0:* 
LISTEN  0       128                 [::]:22               [::]:*   
LISTEN  0       128              0.0.0.0:22            0.0.0.0:*
//创建虚拟主机目录并生成php测试页面
[root@lzx ~]# cd /usr/local/apache/
[root@lzx apache]# cd htdocs/
[root@lzx htdocs]# mkdir lzx
[root@lzx htdocs]# cat lzx/index.php
<?php
    phpinfo();
?>
[root@lzx apache]# chown -R apache.apache /usr/local/apache/htdocs/

[root@lzx apache]# vim conf/httpd.conf
//在配置文件的最后加入以下内容
514 <VirtualHost *:80>
515     DocumentRoot "/usr/local/apache/htdocs/zrz"
516     ServerName www.zrz.com
517     ProxyRequests Off
518     ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/a    pache/htdocs/zrz/$1
519     <Directory "/usr/local/apache/htdocs/zrz">
520         Options none
521         AllowOverride none
522         Require all granted
523     </Directory>
524 </VirtualHost>

//搜索AddType,添加以下内容
397     AddType application/x-compress .Z
398     AddType application/x-gzip .gz .tgz
399     AddType application/x-httpd-php .php
400     AddType application/x-httpd-php-source .phps

260 <IfModule dir_module>
261     DirectoryIndex index.php index.html    //加上index.php
262 </IfModule>

//重启apache服务
[root@lzx apache]# systemctl restart httpd.service

验证

![在这里插入图片描述](https://www.icode9.com/i/ll/?i=c9c309856c2a42d48f22c3cb20d96cd2.png?,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAbHgtLXl0,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)

上一篇:安卓大作业-校园lbs系统


下一篇:Java -- JDBC学习笔记2、结果集