LAMP部署

本文详细介绍了如何在服务器上编译安装Apache、二进制安装MySQL以及编译安装PHP的过程,包括每个步骤的配置、启动和错误解决,最后验证了PHP服务与MySQL数据库的连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 环境说明
# centos 版本
[root@node1 ~]# cat /etc/redhat-release
CentOS Stream release 8


#Linux内核版本
[root@node1 ~]# uname -r
4.18.0-257.el8.x86_64

#系统位
[root@node1 ~]# file /bin/ls
/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=056dda3f1b77919163a7de5563a2b9d9d245554c, stripped

#apache版本号:2.4.54

#mysql版本号:5.7.37

#php版本号:7.4.29


  • 安装包下载
[root@node1 ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@node1 ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@node1 ~]# wget https://downloads.apache.org/httpd/httpd-2.4.54.tar.gz
[root@node1 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@node1 ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz
[root@node1 ~]# ls
anaconda-ks.cfg   apr-util-1.6.1.tar.gz  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.54.tar.gz    php-7.4.29.tar.xz

1.编译安装Apache

1.1编译安装apache 顺序为apr—>arp-util----->httpd

//安装依赖包 创建用户
[root@node1 ~]yum -y install openssl-devel pcre-devel expat-devel libtool gcc make
[root@node1 ~]useradd -r -M -s /sbin/nologin apache 
[root@node1 ~]id apache



//全部解压缩
[root@node1 ~]# tar -xf apr-1.7.0.tar.gz 
[root@node1 ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@node1 ~]# tar -xf httpd-2.4.54.tar.gz 
[root@node1 ~]# ls
anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.54.tar.gz
apr-1.7.0         apr-util-1.6.1.tar.gz  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
apr-1.7.0.tar.gz  httpd-2.4.54           php-7.4.29.tar.xz
//apr配置文件更改和编译
[root@node1 ~]# cd apr-1.7.0/
[root@node1 apr-1.7.0]# vim configure
 # $RM "$cfgfile"        //将此行加上注释,或者删除此行
[root@node1 apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@node1 apr-1.7.0]# make && make install



//编译安装apr-util
[root@node1 ~]# cd ../apr-util-1.6.1
[root@node1 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
[root@node1 apr-util-1.6.1]# make && make install

//编译安装httpd 
[root@node1 apr-util-1.6.1]# cd ../httpd-2.4.54
[root@node1 httpd-2.4.54]# ./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 
...
Server Version: 2.4.54
    Install prefix: /usr/local/apache
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@node1 httpd-2.4.54]# make && make install

1.2 配置apache

//环境变量设置
[root@node1 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/apache.sh
[root@node1 ~]# source /etc/profile.d/apache.sh 
[root@node1 ~]# which httpd 
/usr/local/apache/bin/httpd
[root@node1 ~]# which apachectl
/usr/local/apache/bin/apachectl

//头文件设置
[root@node1 ~]# ln -s /usr/local/apache/include/ /usr/include/apache 
[root@node1 ~]# ll /usr/include/|grep apache
lrwxrwxrwx.  1 root root     26 Jul  6 00:39 apache -> /usr/local/apache/include/

//man文档
[root@node1 ~]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/local/apache/man  //需要添加的一行


//服务启动与开机自启 
//修改配置文件
[root@node1 ~]# cd /usr/local/apache/conf
[root@node1 conf]# vim httpd.conf
#ServerName www.example.com:80   // 此行取消注释

1.3 启动apache

//设置开机自启 写一个server文件 可以直接复制其他的文件更改 
[root@node1 conf]# cd /usr/lib/systemd/system
[root@node1 system]# ls sshd.service 
sshd.service
[root@node1 system]# cp sshd.service httpd.service
[root@node1 system]# vim httpd.service
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.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@node1 ~]# systemctl disable --now firewalld
[root@node1 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; >
   Active: inactive (dead)


//selinux 设置 
[root@node1 ~]# vim /etc/selinux/config
SELINUX=disabled                 //将enforcing 修改为 disabled



//启动服务
[root@node1 ~]# systemctl daemon-reload
[root@node1 ~]# systemctl status  httpd 
httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disa>
   Active: inactive (dead)
[root@node1 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@node1 ~]# systemctl status httpd 
[root@node1 ~]# ss -antl
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                      [::]:22                     [::]:*                    
LISTEN     0          128                         *:80                        *:*
[root@node1 ~]# apachectl stop
[root@node1 ~]# ss -antl
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                      [::]:22                     [::]:*                    
[root@node1 ~]# apachectl start
[root@node1 ~]# ss -antl
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                      [::]:22                     [::]:*                    
LISTEN     0          128                         *:80                        *:*  

在这里插入图片描述

2.二进制安装mysql

2.1安装mysql

//移动mysql软件包
[root@node1 ~]# cd /usr/src
[root@node1 src]# mv /root/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  .
[root@node1 src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

//系统创建用户和组
[root@node1 src]# useradd -r -M -s  /sbin/nologin mysql
[root@node1 src]# id mysql
uid=993(mysql) gid=990(mysql) groups=990(mysql)

//解压软件至/usr/local/
[root@node1 src]# ls /usr/local/
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@node1 src]# cd /usr/local 
[root@node1 local]# tar xf /usr/src/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C ./
[root@node1 local]# ls
apache  apr-util  etc    include  lib64    mysql-5.7.37-linux-glibc2.12-x86_64  share
apr     bin       games  lib      libexec  sbin   src                        
//创建软链接 直接改名也可以 
[root@node1 local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@node1 local]# ls
apache  apr-util  etc    include  lib64    mysql                                sbin   src
apr     bin       games  lib      libexec  mysql-5.7.37-linux-glibc2.12-x86_64  share

//修改目录/usr/local/mysql的属主属组
[root@node1 local]# chown -R mysql.mysql /usr/local/mysql
[root@node1 local]# ll -d mysql
lrwxrwxrwx. 1 mysql mysql 36 Jul  6 00:48 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/

//添加环境变量bin
[root@node1 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@node1 local]# source /etc/profile.d/mysql.sh
[root@node1 local]# which mysql
/usr/local/mysql/bin/mysql

//创建软链接 include
[root@node1 local]# cd mysql/
[root@node1 mysql]# ln -s  /usr/local/mysql/include/ /usr/include/mysql 
[root@node1 mysql]# ll /usr/include/mysql
lrwxrwxrwx. 1 root root 25 Jul  6 00:49 /usr/include/mysql -> /usr/local/mysql/include/

2.2 配置mysql

//配置lib库
[root@node1 mysql]# vim /etc/ld.so.conf.d/mysql.conf 
/usr/local/mysql/lib
[root@node1 mysql]# ldconfig

//配置man文档
[root@node1 mysql]# vim /etc/man_db.conf

//建立数据存放目录
[root@node1 mysql]# mkdir -p /opt/data
[root@node1 mysql]# chown -R mysql.mysql /opt/data
[root@node1 mysql]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul  6 00:53 data


//初始化数据库
[root@node1 mysql]# mysqld --initialize --user=mysql --datadir=/opt/data 

2022-07-05T16:54:52.558957Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-05T16:54:52.641610Z 1 [Note] A temporary password is generated for root@localhost: iQBGfK)Hh0Ny
//请注意,这个命令的最后会生成一个临时密码,此处密码是iQBGfK)Hh0Ny,此密码为随机密码,一定要记住这个密码(建议写入文件),便于后续初始登陆
[root@node1 mysql]# echo 'iQBGfK)Hh0Ny' > /root/mysql.passwd
[root@node1 mysql]# cd
[root@node1 ~]# ls |grep  passwd
mysql.passwd

//生成配置文件
[root@node1 ~]# vim /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@node1 ~]# cd /usr/local/mysql 
[root@node1 mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@node1 mysql]# ls support-files/
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@node1 mysql]# cp -a support-files/mysql.server  support-files/mysqld 
[root@node1 mysql]# chown -R mysql.mysql support-files/mysqld
[root@node1 mysql]# ll support-files/
total 36
-rw-r--r--. 1  7161 31415   773 Nov 30  2021 magic
-rwxr-xr-x. 1 mysql mysql 10576 Nov 30  2021 mysqld
-rwxr-xr-x. 1  7161 31415  1061 Nov 30  2021 mysqld_multi.server
-rwxr-xr-x. 1  7161 31415   894 Nov 30  2021 mysql-log-rotate
-rwxr-xr-x. 1  7161 31415 10576 Nov 30  2021 mysql.server
[root@node1 mysql]# cd support-files/
[root@node1 support-files]# vim mysqld 
basedir=/usr/local/mysql
datadir=/opt/data    //补充以上两行的内容 

2.3 启动mysql

//启动mysql
[root@node1 ~]# /usr/local/mysql/support-files/mysqld start 
Starting MySQL.Logging to '/opt/data/node1.lab.example.com.err'.
 SUCCESS! 


 //使用临时密码进行初始登录.
 [root@node1 ~]# cat mysql.passwd 
iQBGfK)Hh0Ny
[root@node1 ~]# mysql -uroot -p'iQBGfK)Hh0Ny'
Copyright (c) 2000, 2022, 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> 
 
 
 //修改密码并使用新密码登录验证
 mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye
[root@node1 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> 

 
 
 //收尾 设置开机自启 ——创建service文件
 [root@node1 ~]# /usr/local/mysql/support-files/mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@node1 ~]# cp /usr/lib/systemd/system/sshd.service  mysqld.service 
[root@node1 ~]# ls |grep mysql
mysqld.service
mysql.passwd
[root@node1 ~]# vim mysqld.service 
[root@node1 ~]# echo > mysqld.service 
[root@node1 ~]# vim mysqld.service 
[Unit]
Description=mysqld server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysqld start
ExecStop=/usr/local/mysql/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@node1 ~]# mv mysqld.service  /usr/lib/systemd/system/


//systemctl启动验证
 [root@node1 ~]# systemctl daemon-reload 
[root@node1 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@node1 ~]# systemctl enable --now  mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@node1 ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-07-06 01:06:22 CST; 4s ago
  Process: 40947 ExecStart=/usr/local/mysql/support-files/mysqld start (code=exited, status=0/SUCCES>
 Main PID: 40960 (mysqld_safe)
    Tasks: 28 (limit: 11195)
   Memory: 180.2M
   CGroup: /system.slice/mysqld.service
           ├─40960 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data>
           └─41150 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plug>

Jul 06 01:06:21 node1.lab.example.com systemd[1]: Starting mysqld server daemon...
Jul 06 01:06:22 node1.lab.example.com mysqld[40947]: Starting MySQL. SUCCESS!
Jul 06 01:06:22 node1.lab.example.com systemd[1]: Started mysqld server daemon.
lines 1-14/14 (END)
^C
[root@node1 ~]# ss -antl
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                   0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                      [::]:22                     [::]:*                    
LISTEN     0          80                          *:3306                      *:*                    
LISTEN     0          128                         *:80                        *:*

3.编译安装php

3.1 解压安装 php

//安装依赖包
[root@node1 ~]# dnf -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

Upgraded:
  libcurl-7.61.1-22.el8.x86_64             libgcrypt-1.8.5-6.el8.x86_64                 
  libjpeg-turbo-1.5.3-12.el8.x86_64        libxml2-2.9.7-9.el8_4.2.x86_64               
  openldap-2.4.46-18.el8.x86_64            python3-libxml2-2.9.7-9.el8_4.2.x86_64       

Installed:
  bzip2-1.0.6-26.el8.x86_64                 bzip2-devel-1.0.6-26.el8.x86_64             
  bzip2-libs-1.0.6-26.el8.i686              cmake-filesystem-3.20.2-4.el8.x86_64        
  cyrus-sasl-2.1.27-5.el8.x86_64            cyrus-sasl-devel-2.1.27-5.el8.x86_64        
  freetype-2.9.1-4.el8_3.1.i686             freetype-devel-2.9.1-4.el8_3.1.x86_64       
  glibc-2.28-164.el8.i686                   gmp-c++-1:6.1.2-10.el8.x86_64               
  gmp-devel-1:6.1.2-10.el8.x86_64           libcurl-devel-7.61.1-22.el8.x86_64          
  libgcrypt-devel-1.8.5-6.el8.x86_64        libgpg-error-devel-1.31-1.el8.x86_64        
  libicu-60.3-2.el8_1.x86_64                libicu-devel-60.3-2.el8_1.x86_64            
  libjpeg-turbo-devel-1.5.3-12.el8.x86_64   libmcrypt-2.5.8-26.el8.x86_64               
  libmcrypt-devel-2.5.8-26.el8.x86_64       libpng-2:1.6.34-5.el8.i686                  
  libpng-devel-2:1.6.34-5.el8.x86_64        libxml2-devel-2.9.7-9.el8_4.2.x86_64        
  libxslt-devel-1.1.32-6.el8.x86_64         mhash-0.9.9.9-20.el8.x86_64                 
  mhash-devel-0.9.9.9-20.el8.x86_64         ncurses-c++-libs-6.1-9.20180224.el8.x86_64  
  ncurses-devel-6.1-9.20180224.el8.x86_64   openldap-devel-2.4.46-18.el8.x86_64         
  readline-devel-7.0-10.el8.x86_64          xz-devel-5.2.4-3.el8.x86_64                 
  zlib-1.2.11-17.el8.i686                  

Complete!

[root@node1 ~]# tar xf php-7.4.29.tar.xz 
[root@node1 ~]# ls
anaconda-ks.cfg   apr-util-1.6.1         httpd-2.4.54.tar.gz  php-7.4.29.tar.xz
apr-1.7.0         apr-util-1.6.1.tar.gz  mysql.passwd
apr-1.7.0.tar.gz  httpd-2.4.54           php-7.4.29
[root@node1 ~]# cd php-7.4.29/
[root@node1 php-7.4.29]#

3.2 编译php前的配置 (包含报错及解决)

[root@node1 php-7.4.29]# ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --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-json --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

# 报错 : Package 'sqlite3'
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
Package 'sqlite3', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if yo
installed software in a non-standard prefix.
Alternatively, you may set the environment variables SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
#解决 :
[root@node1 php-7.4.29]# dnf list all |grep sqlite
[root@node1 php-7.4.29]# dnf -y install sqlite-devel
#继续上面的配置命令 出现报错 : 'oniguruma'
configure: error: Package requirements (oniguruma) were not met:

Package 'oniguruma', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

# 解决 :
[root@node1 php-7.4.29]# dnf list all |grep oniguruma
[root@node1 php-7.4.29]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

#继续上面的配置命令 出现报错 :'libzip'
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

Package 'libzip', required by 'virtual:world', not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBZIP_CFLAGS
and LIBZIP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
# 解决 :
[root@node1 php-7.4.29]# dnf list all |grep libzip
[root@node1 php-7.4.29]# dnf -y install libzip-devel 

#没有报错了 执行编译后的结果如下
+--------------------------------------------------------------------+
| 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@node1 php-7.4.29]# make && make install

3.3 编译php后的配置

//设置环境变量
[root@node1 ~]# echo 'export PATH=/usr/local/php7/bin:/usr/local/php7:sbin:$PATH' > /etc/profile.d/php7.sh
[root@node1 ~]# source /etc/profile.d/php7.sh


//设置头文件
[root@node1 ~]# ln -s /usr/local/php7/include  /usr/include/php



//配置lib库文件
[root@node1 ~]# echo '/usr/local/php7/lib' > /etc/ld.so.conf.d/php.conf 
[root@node1 ~]# ldconfig
 

//验证
[root@node1 ~]# php -v 
PHP 7.4.29 (cli) (built: Jul  6 2022 03:21:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies


//配置php-fpm
[root@node1 ~]# cd php-7.4.29
[root@node1 php-7.4.29]# cp php.ini-production /etc/php.ini 
[root@node1 php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@node1 php-7.4.29]# chmod +x /etc/init.d/php-fpm
[root@node1 php-7.4.29]# cd /usr/local/php7/etc
[root@node1 etc]# cp php-fpm.conf.default  php-fpm.conf
[root@node1 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@node1 etc]# cd php-fpm.d
[root@node1 php-fpm.d]# cp www.conf.default www.conf
[root@node1 php-fpm.d]# ls
www.conf  www.conf.default
[root@node1 php-fpm.d]# 

3.4 启动 php服务后的配置

//直接启动
[root@node1 php-fpm.d]# service  php-fpm start 
Starting php-fpm  done
[root@node1 php-fpm.d]# ss -antl 
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN    0         128              127.0.0.1:9000            0.0.0.0:*                
LISTEN    0         128                      *:80                    *:*                
LISTEN    0         128                   [::]:22                 [::]:*                
LISTEN    0         80                       *:3306                  *:*  

// 开启apache的代理模块
[root@node1 php-fpm.d]# vim /usr/local/apache/conf/httpd.conf 

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so //以上两行取消注释


//创建目录并生成php测试页面
[root@node1 php-fpm.d]# cd /usr/local/apache/htdocs/
[root@node1 htdocs]# ls
index.html
[root@node1 htdocs]# vim index.php
<?php
    phpinfo();
?>
[root@node1 htdocs]# ls
index.html  index.php

//更改虚拟主机配置文件
[root@node1 htdocs]# cd ../conf 
[root@node1 conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@node1 conf]# cd extra/
[root@node1 extra]# ls 
httpd-autoindex.conf  httpd-languages.conf           httpd-ssl.conf
httpd-dav.conf        httpd-manual.conf              httpd-userdir.conf
httpd-default.conf    httpd-mpm.conf                 httpd-vhosts.conf
httpd-info.conf       httpd-multilang-errordoc.conf  proxy-html.conf
[root@node1 extra]# vim httpd-vhosts.conf 
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/"
    ServerName www.example.com
    ErrorLog "logs/www.example.com-error_log"
    CustomLog "logs/www.example.com-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/$1
    <Directory "/usr/local/apache/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>  //保留以上内容即可

//更改Apache主配置文件 使其包含虚拟主机配置文件
[root@node1 extra]# cd ..
[root@node1 conf]# vim httpd.conf 

Include conf/extra/httpd-vhosts.conf //此行取消注释

AddType application/x-httpd-php .php       
AddType application/x-httpd-php-source .phps  
                                    //AddType相应位置添加以上两行      
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
                          //index.html 位置的前面 添加 index.php
                               
//把apache目录改一下属组
[root@node1 conf]# chown -R apache.apache /usr/local/apache
 

//重启服务 后验证 
[root@node1 conf]# apachectl restart

[root@node1 conf]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN    0         128              127.0.0.1:9000            0.0.0.0:*                
LISTEN    0         128                      *:80                    *:*                
LISTEN    0         128                   [::]:22                 [::]:*                
LISTEN    0         80                       *:3306                  *:*   


//配置lamp开机自启
[root@node1 conf]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Dec  2  2020 /etc/rc.local -> rc.d/rc.local
[root@node1 conf]# ll /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 474 Dec  2  2020 /etc/rc.d/rc.local
[root@node1 conf]# chmod +x /etc/rc.d/rc.local 
[root@node1 conf]# vim /etc/rc.d/rc.local

/usr/local/apache/bin/apachectl start 
service mysqld start 
service php-fpm start 
        //添加以上三行 
        
//重启验证
[root@node1 conf]# apachectl stop 
[root@node1 conf]# service mysqld stop  
Redirecting to /bin/systemctl stop mysqld.service
[root@node1 conf]# service  php-fpm stop 
Gracefully shutting down php-fpm . done
[root@node1 conf]# ss -antl 
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN    0         128                   [::]:22                 [::]:* 
[root@node1 ~]# reboot 
[root@node1 ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN    0         128              127.0.0.1:9000            0.0.0.0:*                
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*                
LISTEN    0         80                       *:3306                  *:*                
LISTEN    0         128                      *:80                    *:*                
LISTEN    0         128                   [::]:22                 [::]:* 

3.5 验证测试页面和mysql数据库是否连接

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值