LAMP环境搭建

LAMP

apache

创建apache用户

[root@localhost ~]# useradd -r -M -s /sbin/nologin apache

安装依赖包

[root@localhost ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make 

解压

[root@localhost ~]# ls 
anaconda-ks.cfg    apr-util-1.6.3.tar.bz2  Documents  httpd-2.4.58.tar.bz2  Pictures  Templates
apr-1.7.4.tar.bz2  Desktop                 Downloads  Music                 Public    Videos.
[root@localhost ~]# tar jxf apr-util-1.6.3.tar.bz2 
[root@localhost ~]# tar jxf apr-1.7.4.tar.bz2 
[root@localhost ~]# tar jxf httpd-2.4.58.tar.bz2 
[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.4.tar.bz2  apr-util-1.6.3.tar.bz2  Documents  httpd-2.4.58          Music     Public     Videos
apr-1.7.4        apr-util-1.6.3     Desktop                 Downloads  httpd-2.4.58.tar.bz2  Pictures  Templates
[root@localhost ~]# 

在apr目录下configured中

//# R M " RM " RM"cfgfile"加上注释,或者删除此行

[root@localhost ~]# cd apr-1.7.4/
[root@localhost apr-1.7.4]# ls
apr-config.in  apr.spec          CHANGES         dso         libapr.dep  Makefile.in   NOTICE         README.cmake  threadproc
apr.dep        atomic            CMakeLists.txt  emacs-mode  libapr.dsp  Makefile.win  NWGNUmakefile  shmem         time
apr.dsp        build             config.layout   encoding    libapr.mak  memory        passwd         strings       tools
apr.dsw        build.conf        configure       file_io     libapr.rc   misc          poll           support       user
apr.mak        buildconf         configure.in    helpers     LICENSE     mmap          random         tables
apr.pc.in      build-outputs.mk  docs            include     locks       network_io    README         test
[root@localhost apr-1.7.4]# vim configure


    cfgfile=${ofile}T
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15

    cat <<_LT_EOF >> "$cfgfile"


三部曲

apr
[root@localhost apr-1.7.4]# ./configure  --prefix=/usr/local/apr

[root@localhost apr-1.7.4]# make

[root@localhost apr-1.7.4]# make install

apr-util
[root@localhost apr-1.7.4]# cd ../apr-util-1.6.3/
//apr-util是apr的工具,所以要告诉apr-util 的apr在哪里
// --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.3]# ./configure --prefix=/usr/local/apr-util  --with-apr=/usr/local/apr

[root@localhost apr-util-1.6.3]# make

[root@localhost apr-util-1.6.3]# make install


httpd
[root@localhost httpd-2.4.58]# ./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@localhost httpd-2.4.58]# make


[root@localhost httpd-2.4.58]# make install

 

安装后配置

[root@localhost ~]# ls /usr/local/apache/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[root@localhost ~]# 
//有bin要做环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh

//有include要做软链接
[root@localhost ~]# ln -s /usr/local/apache/include//usr/include/apache


//有man(帮助文档)
[root@localhost ~]# vim /etc/man_db.conf 
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man //添加这行


[root@localhost ~]# source /etc/profile.d/httpd.sh

取消ServerName前面的注释

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
#
ServerName www.example.com:80
#

关闭防火墙,立刻生效 不开机启动

[root@localhost ~]# systemctl disable --now firewalld

关闭selinux

[root@localhost ~]# vim /etc/selinux/config 
SELINUX=disabld

启动apache

[root@localhost ~]# apachectl start
[root@localhost ~]# 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               4096                         127.0.0.1:631                         0.0.0.0:*                            
LISTEN          0               128                          127.0.0.1:6010                        0.0.0.0:*                            
LISTEN          0               511                                  *:80                                *:*                            
LISTEN          0               128                               [::]:22                             [::]:*                            
LISTEN          0               128                              [::1]:6010                           [::]:*                            
LISTEN          0               4096                             [::1]:631                            [::]:*              


开机自启

[root@localhost ~]# apachectl stop
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service  /usr/lib/systemd/system/httpd.service
[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service 

[Unit]
Description=httpd server daemon
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@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status httpd


[root@localhost ~]# systemctl enable --now httpd


[root@localhost ~]# systemctl status httpd
● httpd.service - httpd server daemon
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
     Active: active (running) since Mon 2023-12-11 02:20:57 EST; 50s ago
    Process: 81992 ExecStart=/usr/local/apache/bin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 81995 (httpd)
      Tasks: 6 (limit: 48510)
     Memory: 5.3M
        CPU: 23ms
     CGroup: /system.slice/httpd.service
             ├─81995 /usr/local/apache/bin/httpd -k start
             ├─81996 /usr/local/apache/bin/httpd -k start
             ├─81997 /usr/local/apache/bin/httpd -k start
             ├─81998 /usr/local/apache/bin/httpd -k start
             ├─81999 /usr/local/apache/bin/httpd -k start
             └─82000 /usr/local/apache/bin/httpd -k start

Dec 11 02:20:57 localhost.localdomain systemd[1]: Starting httpd server daemon...
Dec 11 02:20:57 localhost.localdomain systemd[1]: Started httpd server daemon.
[root@localhost ~]# 

mysql

创建用户

[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

安装依赖包

//安装第三方通用源
[root@localhost ~]# yum -y install epel-release
//安装包
[root@localhost ~]# yum -y install https://mirror.stream.centos.org/9-stream/CRB/x86_64/os/Packages/mariadb-devel-10.5.16-2.el9.x86_64.rpm

[root@localhost ~]#  yum -y install ncurses-devel openssl-devel openssl cmake

解压

[root@localhost ~]# ls
anaconda-ks.cfg    apr-util-1.6.3          Documents     httpd-2.4.58.tar.bz2                        Pictures   Videos
apr-1.7.4          apr-util-1.6.3.tar.bz2  Downloads     Music                                       Public
apr-1.7.4.tar.bz2  Desktop                 httpd-2.4.58  mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz  Templates
[root@localhost ~]# tar xf mysql-8.0.35-linux-glibc2.28-x86_64.tar.xz -C /usr/local/

修改目录/usr/local/mysql的属主属组

[root@localhost ~]# cd /usr/local
[root@localhost local]# mv mysql-8.0.35-linux-glibc2.28-x86_64/ mysql
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll
total 0
drwxr-xr-x. 14 root  root  164 Dec 11 01:48 apache
drwxr-xr-x.  6 root  root   58 Dec 11 01:29 apr
drwxr-xr-x.  5 root  root   43 Dec 11 01:35 apr-util
drwxr-xr-x.  2 root  root    6 May 16  2022 bin
drwxr-xr-x.  2 root  root    6 May 16  2022 etc
drwxr-xr-x.  2 root  root    6 May 16  2022 games
drwxr-xr-x.  2 root  root    6 May 16  2022 include
drwxr-xr-x.  2 root  root    6 May 16  2022 lib
drwxr-xr-x.  3 root  root   17 Nov 29 09:13 lib64
drwxr-xr-x.  2 root  root    6 May 16  2022 libexec
drwxr-xr-x.  9 mysql mysql 129 Dec 11 02:37 mysql
drwxr-xr-x.  2 root  root    6 May 16  2022 sbin
drwxr-xr-x.  5 root  root   49 Nov 29 09:13 share
drwxr-xr-x.  2 root  root    6 May 16  2022 src
[root@localhost local]# 

添加环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh 

建立数据存放目录

[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data

初始化数据库

[root@localhost ~]# mysqld  --initialize --user mysql --datadir=/opt/data/
2023-12-11T07:46:12.458282Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 88079
2023-12-11T07:46:12.464775Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-11T07:46:13.497324Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-11T07:46:15.281841Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: o6iN!&UXWwor
[root@localhost ~]# echo 'o6iN!&UXWwor' > pass
[root@localhost ~]# 

配置文件

[root@localhost ~]# 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@localhost ~]# ls /usr/local/mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost ~]# 

[root@localhost ~]# ln -s /usr/localmysql/include /usr/include/mysql
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d//mysql.conf 
/usr/local/mysql/lib
[root@localhost ~]# ldconfig -v
[root@localhost ~]# vim /etc/man_db.conf 

#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/apache/man
MANDATORY_MANPATH                       /usr/local/mysql/man

配置服务启动脚本

[root@localhost ~]# vim /usr/local/mysql/support-files/mysql.server 
basedir=/usr/local/mysql
datadir=/opt/data

启动mysql

//测试一下
[root@localhost ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL. SUCCESS! 
[root@localhost ~]# 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               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6010                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6010                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                 
[root@localhost ~]# /usr/local/mysql/support-files/mysql.server stop
Shutting down MySQL.. SUCCESS! 
[root@localhost ~]# 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               4096                         127.0.0.1:631                         0.0.0.0:*                            
LISTEN          0               128                          127.0.0.1:6010                        0.0.0.0:*                            
LISTEN          0               511                                  *:80                                *:*                            
LISTEN          0               128                               [::]:22                             [::]:*                            
LISTEN          0               128                              [::1]:6010                           [::]:*                            
LISTEN          0               4096                             [::1]:631                            [::]:*    

开机自启

[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service  /usr/lib/systemd/system/mysqld.service
[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service 

[Unit]
Description=mysqld 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
~                          
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status mysqld 
○ mysqld.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: disabled)
     Active: inactive (dead)
[root@localhost ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl status mysqld 
● mysqld.service - mysqld server daemon
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Mon 2023-12-11 03:11:05 EST; 2s ago
    Process: 89239 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
   Main PID: 89252 (mysqld_safe)
      Tasks: 39 (limit: 48510)
     Memory: 368.3M
        CPU: 640ms
     CGroup: /system.slice/mysqld.service
             ├─89252 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
             └─89442 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugi>

Dec 11 03:11:04 localhost.localdomain systemd[1]: Starting mysqld server daemon...
Dec 11 03:11:05 localhost.localdomain mysql.server[89239]: Starting MySQL. SUCCESS!
Dec 11 03:11:05 localhost.localdomain systemd[1]: Started mysqld server daemon.

[root@localhost ~]# 

修改密码

//使用临时密码登录


[root@localhost ~]# cat pass
o6iN!&UXWwor
[root@localhost ~]# mysql -uroot -p'o6iN!&UXWwor'
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 8
Server version: 8.0.35

Copyright (c) 2000, 2023, 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> alter user root@'localhost' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -proot
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 9
Server version: 8.0.35 MySQL Community Server - GPL

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

php

下载php

[root@localhost ~]# wget https://www.php.net/distributions/php-8.3.0.tar.xz.asc
[root@localhost ~]# tar xf php-8.3.0.tar.xz 

安装依赖包

[root@localhost ~]# 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 php-mysqlnd
//开启yum
[root@localhost ~]# vim /etc/yum.repos.d/rocky-devel.repo 
[devel]
name=Rocky Linux $releasever - Devel WARNING! FOR BUILDROOT ONLY DO NOT LEAVE ENABLED
mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=devel-$releasever$rltype
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/devel/$basearch/os/
gpgcheck=1
enabled=1 //改为1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9

[root@localhost ~]# yum -y install libsqlite3x-devel  oniguruma-devel  libzip-devel


三部曲

[root@localhost ~]# cd php-8.3.0/
[root@localhost php-8.3.0]# ls
appveyor   buildconf.bat        configure.ac     EXTENSIONS  pear                 README.REDIST.BINS  SECURITY.md  UPGRADING
benchmark  CODEOWNERS           CONTRIBUTING.md  LICENSE     php.ini-development  run-tests.php       tests        UPGRADING.INTERNALS
build      CODING_STANDARDS.md  docs             main        php.ini-production   sapi                travis       win32
buildconf  configure            ext              NEWS        README.md            scripts             TSRM         Zend
[root@localhost php-8.3.0]# 

[root@localhost php-8.3.0]#./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
[root@localhost php-8.3.0]# 
[root@localhost php-8.3.0]# make


[root@localhost php-8.3.0]# make install

安装后配置

[root@localhost php-8.3.0]# ls /usr/local/php8/
bin  etc  include  lib  php  sbin  var
[root@localhost php-8.3.0]# echo 'export PATH=/usr/local/php8/bin:/usr/local/php8/sbin:$PATH' > /etc/profile.d/php.sh
[root@localhost php-8.3.0]# source /etc/profile.d/php.sh 
[root@localhost php-8.3.0]# 

[root@localhost php-8.3.0]# ln -s /usr/local/php8/include/ /usr/include/php
[root@localhost php-8.3.0]# vim /etc/ld.so.conf.d/php.conf  
[root@localhost php-8.3.0]# cat /etc/ld.so.conf.d/php.conf 
/usr/localphp8/lib
[root@localhost php-8.3.0]# ldconfig -v

[root@localhost php-8.3.0]# which php
/usr/local/php8/bin/php
[root@localhost php-8.3.0]# php -v
PHP 8.3.0 (cli) (built: Dec 11 2023 04:11:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
[root@localhost php-8.3.0]# 


配置php-fpm

[root@localhost php-8.3.0]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-8.3.0]# 

[root@localhost php-8.3.0]# mkdir /etc/init.d
[root@localhost php-8.3.0]#  cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-8.3.0]# chmod +x /etc/init.d/php-fpm 
[root@localhost php-8.3.0]# cd /usr/local/php8/etc/
[root@localhost etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# 
[root@localhost etc]# cp php-fpm.conf.default  php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ls
www.conf  www.conf.default
[root@localhost php-fpm.d]# cd
[root@localhost ~]# 

启动php-fpm
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
[root@localhost ~]# 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               4096                         127.0.0.1:9000                         0.0.0.0:*                            
LISTEN         0               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6011                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6011                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                            
[root@localhost ~]# 

开机自启

[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service  /usr/lib/systemd/system/php-fpm.service
[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service 

[Unit]
Description=php server daemon
After=network.target 

[Service]
Type=forking
ExecStart=service php-fpm start
ExecStop=service php stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target


[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status php-fpm
○ php-fpm.service - php server daemon
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; preset: disabled)
     Active: inactive (dead)

Dec 11 05:00:12 localhost.localdomain systemd[1]: php-fpm.service: Service has more than one ExecStart= setting, which is only allowed >

[root@localhost ~]# systemctl enable --now php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# 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               4096                         127.0.0.1:9000                         0.0.0.0:*                            
LISTEN         0               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6011                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6011                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                            
[root@localhost ~]# systemctl status php-fpm
● php-fpm.service - php server daemon
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
     Active: active (running) since Mon 2023-12-11 05:01:43 EST; 18s ago
    Process: 237282 ExecStart=service php-fpm start (code=exited, status=0/SUCCESS)
   Main PID: 237288 (php-fpm)
      Tasks: 3 (limit: 48510)
     Memory: 7.2M
        CPU: 43ms
     CGroup: /system.slice/php-fpm.service
             ├─237288 "php-fpm: master process (/usr/local/php8/etc/php-fpm.conf)"
             ├─237289 "php-fpm: pool www"
             └─237290 "php-fpm: pool www"

Dec 11 05:01:43 localhost.localdomain systemd[1]: Starting php server daemon...
Dec 11 05:01:43 localhost.localdomain service[237286]: Starting php-fpm  done
Dec 11 05:01:43 localhost.localdomain systemd[1]: Started php server daemon.
[root@localhost ~]# 




取消注释

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
#LoadModule remoteip_module modules/mod_remoteip.so
LoadModule proxy_module modules/mod_proxy.so   //这个
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so   //这个
#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so

配置测试页面

[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 

[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# mkdir test
[root@localhost htdocs]# cd test
[root@localhost test]# vim index.php
<?php
   phpinfo();
?>


配置虚拟主机


[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf 
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Include conf/extra/vhosts.conf   //添加
# Local access to the Apache HTTP Server Manual


[root@localhost ~]# cd /usr/local/apache/conf/extra/
[root@localhost extra]# vim vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/test"
    ServerName www.ysy.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/test/$1
    <Directory "/usr/local/apache/htdocs/test">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost> 

AddType添加

[root@localhost extra]# cd ..
[root@localhost conf]# vim httpd.conf 
[root@localhost conf]# pwd
/usr/local/apache/conf
[root@localhost conf]# 

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php      //  添加
AddType application/x-httpd-php-source .phps  //添加
    
//添加index.php 
index.php放在index.html后面需要加php后缀才可以访问,反之
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

重启

[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl restart php-fpm
[root@localhost ~]# 

[root@localhost ~]# 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               4096                         127.0.0.1:9000                         0.0.0.0:*                            
LISTEN         0               4096                         127.0.0.1:631                          0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6011                         0.0.0.0:*                            
LISTEN         0               128                          127.0.0.1:6010                         0.0.0.0:*                            
LISTEN         0               151                                  *:3306                               *:*                            
LISTEN         0               511                                  *:80                                 *:*                            
LISTEN         0               128                               [::]:22                              [::]:*                            
LISTEN         0               70                                   *:33060                              *:*                            
LISTEN         0               128                              [::1]:6011                            [::]:*                            
LISTEN         0               128                              [::1]:6010                            [::]:*                            
LISTEN         0               4096                             [::1]:631                             [::]:*                            
[root@localhost ~]# 

验证

在这里插入图片描述

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值