LAMP 部署

编译安装apache


[root@localhost ~]# wget https://downloads.apache.org/apr/apr-1.7.0.tar.gz
[root@localhost ~]# wget https://downloads.apache.org/apr/apr-util-1.6.1.tar.gz
[root@localhost ~]# 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@localhost ~]# wget https://www.php.net/distributions/php-7.4.29.tar.xz
[root@localhost ~]# 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


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



//全部解压缩
[root@localhost ~]# tar -xf apr-1.7.0.tar.gz 
[root@localhost ~]# tar -xf apr-util-1.6.1.tar.gz 
[root@localhost ~]# 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@localhost ~]# cd apr-1.7.0/
[root@localhost apr-1.7.0]# vim configure
 # $RM "$cfgfile"        //将此行加上注释,或者删除此行
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install



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

//编译安装httpd 
[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.54
[root@localhost 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@localhost httpd-2.4.54]# make && make install

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

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

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


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


启动apache
//设置开机自启 写一个server文件 可以直接复制其他的文件更改 
[root@localhost conf]# cd /usr/lib/systemd/system
[root@localhost system]# ls sshd.service 
sshd.service
[root@localhost system]# cp sshd.service httpd.service
[root@localhost 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@localhost ~]# vim /etc/selinux/config
SELINUX=disabled                



//启动服务
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# 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@localhost ~]# systemctl status httpd 
[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          128                      [::]:22                     [::]:*                    
LISTEN     0          128                         *:80                        *:*
[root@localhost ~]# apachectl stop
[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          128                      [::]:22                     [::]:*                    
[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          128                      [::]:22                     [::]:*                    
LISTEN     0          128                         *:80                        *:*  


 安装mysql

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

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

//解压软件至/usr/local/
[root@localhost src]# ls /usr/local/
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost src]# cd /usr/local 
[root@localhost local]# tar xf /usr/src/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C ./
[root@localhost 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@ local]# ln -s mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
[root@ 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@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll -d mysql
lrwxrwxrwx. 1 mysql mysql 36 Jul  5 22:48 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/

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

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

配置mysql

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

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

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


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

2022-07-05T19:54:52.558957Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-05T19:54:52.641610Z 1 [Note] A temporary password is generated for root@localhost: iQBGfK)Hh0Ny

[root@node1 mysql]# echo 'yhspkt[gfp' > /root/mysql.passwd
[root@node1 mysql]# cd
[root@node1 ~]# ls |grep  passwd
mysql.passwd

//生成配置文件
[root@nlocalhost ~]# 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 ~]# cd /usr/local/mysql 
[root@localhost mysql]# ls
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost mysql]# ls support-files/
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@localhost mysql]# cp -a support-files/mysql.server  support-files/mysqld 
[root@localhost mysql]# chown -R mysql.mysql support-files/mysqld
[root@localhost 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@localhost mysql]# cd support-files/
[root@localhost support-files]# vim mysqld 
basedir=/usr/local/mysql
datadir=/opt/data    


启动mysql

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



[root@localhost~]# cat mysql.passwd 
yhspkt[gfp
[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('runti123!');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -pruntime123!
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> 

 
 
[root@localhost ~]# /usr/local/mysql/support-files/mysqld stop
Shutting down MySQL.. SUCCESS! 
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service  mysqld.service 
[root@localhost ~]# ls |grep mysql
mysqld.service
mysql.passwd
[root@localhost ~]# vim mysqld.service 
[root@localhost ~]# echo > mysqld.service 
[root@localhost ~]# 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@localhost ~]# mv mysqld.service  /usr/lib/systemd/system/


//systemctl启动验证
[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl status mysqld
● mysqld.service - mysqld server daemon
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor 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; vendor preset: disabled)
   Active: active (running) since Wed 2022-07-05 23: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 05 23:06:21 node1.lab.example.com systemd[1]: Starting mysqld server daemon...
Jul 05 23:06:22 node1.lab.example.com mysqld[40947]: Starting MySQL. SUCCESS!
Jul 05 23:06:22 node1.lab.example.com systemd[1]: Started mysqld server daemon.
lines 1-14/14 (END)

[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          128                      [::]:22                     [::]:*                    
LISTEN     0          80                          *:3306                      *:*                    
LISTEN     0          128                         *:80                        *:*

安装 php

//安装依赖包
[root@localhost ~]# 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@localhost ~]# tar xf php-7.4.29.tar.xz 
[root@localhost ~]# 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@localhost ~]# cd php-7.4.29/
[root@localhost php-7.4.29]#

[root@localhost 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@localhost php-7.4.29]# dnf list all |grep sqlite
[root@localhost 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@localhost php-7.4.29]# dnf list all |grep oniguruma
[root@localhost 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@localhost php-7.4.29]# dnf list all |grep libzip
[root@localhost 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@localhost php-7.4.29]# make && make install

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


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



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

//验证
[root@localhost ~]# 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@localhost ~]# cd php-7.4.29
[root@localhost php-7.4.29]# cp php.ini-production /etc/php.ini 
[root@localhost php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.4.29]# chmod +x /etc/init.d/php-fpm
[root@localhost php-7.4.29]# cd /usr/local/php7/etc
[root@localhost etc]# cp php-fpm.conf.default  php-fpm.conf
[root@localhost etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@localhost etc]# cd php-fpm.d
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ls
www.conf  www.conf.default


启动php
//直接启动
[root@localhost php-fpm.d]# service  php-fpm start 
Starting php-fpm  done
[root@localhost 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@localhost 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@localhost php-fpm.d]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# vim index.php
<?php
    phpinfo();
?>
[root@localhost htdocs]# ls
index.html  index.php

//更改虚拟主机配置文件
[root@localhost htdocs]# cd ../conf 
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@localhost conf]# cd extra/
[root@localhost 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@localhost extra]# cd ..
[root@localhost 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@localhost conf]# chown -R apache.apache /usr/local/apache
 

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

[root@localhost 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@localhost conf]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Dec  2  2020 /etc/rc.local -> rc.d/rc.local
[root@localhost conf]# ll /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 474 Dec  2  2020 /etc/rc.d/rc.local
[root@localhost conf]# chmod +x /etc/rc.d/rc.local 
[root@localhost conf]# vim /etc/rc.d/rc.local

/usr/local/apache/bin/apachectl start 
service mysqld start 
service php-fpm start 
        //添加以上三行 
        
//重启验证
[root@localhost conf]# apachectl stop 
[root@localhost conf]# service mysqld stop  
Redirecting to /bin/systemctl stop mysqld.service
[root@localhost conf]# service  php-fpm stop 
Gracefully shutting down php-fpm . done
[root@localhost 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@localhost ~]# reboot 
[root@localhost ~]# 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                 [::]:* 



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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值