LAMP的部署
一. lamp架构的组成
1. lamp含义
- 由linux(操作系统)Apache(http服务器)MySQL(数据库,MariaDB)和PHP(Perl or Python)的一组动态网站或者服务器的开源软件组成Web架构
2. web服务器的工作流程
2.1 web服务器的资源分为静态和动态资源
-
静态资源:
- 客户端从服务器获得的资源与原文件相同,直接存放在文件系统的资源
-
动态资源:
- 程序文件,需要服务器执行之后,将结果给客户端
2.2 工作流程
- 1.客户端通过httpd协议请求web服务器资源
- 2.web服务器判断请求的资源是动态或者静态资源
- 如果是静态资源,直接从本地资源系统取回发送给客户端
- 若为动态资源则通过fastcgi协议与PHP服务器联系,通过CGI程序的master进程调度worker进程来执行程序以获得客户端请求的动态资源,并将执行的结果通过FastCGI协议返回给httpd服务器,httpd服务器收到php的执行结果后将其封装为http响应报文响应给客户端。
- 在执行程序获取动态资源时若需要获得数据库中的资源时,由Php服务器通过mysql协议与MySQL/MariaDB服务器交互,取之而后返回给httpd,httpd将从php服务器收到的执行结果封装成http响应报文响应给客户端。
2.3 httpd与PHP结合的方式
- modules:php将以httpd的扩展模块形式存在,需要加载动态资源时,httpd可以直接通过php模块来加工资源并返回给客户端
- httpd prefork:libphp5.so(多进程模型的php)
- httpd event or worker:libphp5-zts.so(线程模型的php)
- CGI:httpd需要加载动态资源时,通过CGI与php解释器(/bin/bash)联系,获得php执行的结果,此时httpd负责与php连接的建立和断开等
- FastCGI:利用php-fpm机制,启动为服务进程,php自行运行为一个服务,https通过socket与php通信
2.4cgi和fastcgi
- cgi:CGI是外部应用程序与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。
- fastcgi:是CGI的改良版,CGI是通过启用一个解释器进程来处理每个请求,耗时且耗资源,而FastCGI则是通过master-worker形式来处理每个请求,然后根据配置启动几个worker进程,当请求进来时,master会从worker(工作者)进程中选择一个去处理请求,这样就避免了重复的生成和杀死进程带来的频繁cpu上下文切换而导致耗时
2.5 status:响应状态码,用于标记请求处理过程中发生的情况
1.100-101纯信息提示
- 100:服务器仅接收到部分请求,但是一旦服务器并没有拒绝该请求
- 101:服务器转换协议,服务器将遵从客户的请求转换到另外一种协议
2.200-206,“成功”类的信息
- 200:请求资源正常
- 202:供处理的请求已被接受,但处理未完成
- 203:文档已经正常地返回,但一些应答头可能不正确
- 204:没有新文档。浏览器应该继续显示原来的文档
- 205:没有新文档。但浏览器应该重置它所显示的内容
- 206:客户发送了一个带有Range头的GET请求,服务器完成了它
3.300-305,“重定向”类的信息
- 301:永久重定向,响应状态码为“Moved Permanently”
- 请求的URL指向的资源已经被删除,但在响应报文中通过首部Location指明了资源现在所处的新位置,客户端需要请求新位置的资源
- 302:临时重定向,我这里正忙,你要的资源在另一个地方也有,你先去那里要
- 304:客户端发出了条件式请求,但服务器端发现客户端请求的资源已被客户端缓存过且未发生改变,让客户端直接到缓存里去取
4.400-415,“客户端错误”类的信息
- 400:由于客户端请求有语法错误,不能被服务器所理解
- 401:需要输入帐号和密码认证方能访问资源
- 403:请求被禁止
- 404:服务器无法找到客户端请求的资源
5.500-505,“服务端错误”类的信息
- 500:服务器内部错误,响应状态码为“Internal Server Error”
- 502:代理服务器从后端服务器收到了一条伪响应,响应状态码为“Bad Gateway”
- 503:服务器当前不能够处理客户端的请求,在一段时间之后,响应状态码为“Service”
二. 部署LAMP架构
1. 部署lamp架构的环境
系统平台 | ip | 安装的服务 |
---|---|---|
redhat 8.5 Centos8 | 192.168.232.1/128 | httpd-2.4 mysql-5.7 php php-mysql |
2. lamp的部署流程与准备
2.1 lamp安装顺序
- httpd — MySQL — PHP
2.2 准备httpd下载网址,并下载
[root@SYL3 ~]# ls
anaconda-ks.cfg
apr-1.7.0.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.53.tar.gz
[root@SYL3 ~]# tar -xf apr-1.7.0.tar.gz
[root@SYL3 ~]# tar -xf apr-util-1.6.1.tar.gz
[root@SYL3 ~]# tar -xf httpd-2.4.53.tar.gz
2.3 MySQL
-
下载MySQL
[root@SYL3 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
-
下载MySQL源
-
[root@SYL3 ~]# wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-devel-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.37-1.el7.x86_64.rpm https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.37-1.el7.x86_64.rpm [root@SYL3 ~]# ls anaconda-ks.cfg apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz httpd-2.4.53.tar.gz mysql-community-client-5.7.37-1.el7.x86_64.rpm mysql-community-common-5.7.37-1.el7.x86_64.rpm mysql-community-devel-5.7.37-1.el7.x86_64.rpm mysql-community-libs-5.7.37-1.el7.x86_64.rpm mysql-community-server-5.7.37-1.el7.x86_64.rpm mysql57-community-release-el7-10.noarch.rpm [root@SYL3 ~]#
2.4 PHP
[root@SYL3 ~]# wget https://www.php.net/distributions/php-7.4.29.tar.gz
[root@SYL3 ~]# ls
anaconda-ks.cfg
apr-1.7.0
apr-1.7.0.tar.gz
apr-util-1.6.1
apr-util-1.6.1.tar.gz
httpd-2.4.53
httpd-2.4.53.tar.gz
mysql-community-client-5.7.37-1.el7.x86_64.rpm
mysql-community-common-5.7.37-1.el7.x86_64.rpm
mysql-community-devel-5.7.37-1.el7.x86_64.rpm
mysql-community-libs-5.7.37-1.el7.x86_64.rpm
mysql-community-server-5.7.37-1.el7.x86_64.rpm
php-7.4.29.tar.gz
[root@SYL3 ~]#
三. 编译安装apache
1. 安装开发工具包
[root@SYL3 ~]# yum -y groups mark install 'Development Tools'
2. 创建Apache系统用户
[root@SYL3 ~]# useradd -r -M -s /sbin/nologin apache
-r 系统用户
-M 不要家目录
-s 不允许登录
3. 安装依赖包
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make
4. 编译安装apr,apr-util
- 先将configure文件中$cfgfile注释掉
[root@SYL3 apr-1.7.0]# vim configure
[root@SYL3 apr-1.7.0]# cat configure|grep cfgfile
cfgfile=${ofile}T
trap "$RM \"$cfgfile\"; exit 1" 1 2 15
# $RM "$cfgfile"
- 预编译apr
[root@SYL3 apr-1.7.0]# ./configure --prefix=/usr/local/apr
- 编译安装apr
[root@SYL3 apr-1.7.0]# make -j 4
[root@SYL3 apr-1.7.0]# make install
- 预编译apr-util
[root@SYL3 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
- 编译安装apr-util
[root@SYL3 apr-util-1.6.1]# make -j 4
[root@SYL3 apr-util-1.6.1]# make install
5. 编译安装httpd
- 预编译
[root@SYL3 httpd-2.4.53]# ./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@SYL3 httpd-2.4.53]# make -j 4
[root@SYL3 httpd-2.4.53]# make install
6. 安装完成后设置环境变量环境变量,头文件,和man文档
[root@SYL3 httpd-2.4.53]# cd
[root@SYL3 ~]# ls /usr/local/apache/
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@SYL3 ~]#
6.1 设置环境变量
[root@SYL3 ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@SYL3 ~]# source /etc/profile.d/httpd.sh
[root@SYL3 ~]# which httpd
/usr/local/apache/bin/httpd
[root@SYL3 ~]#
6.2 头文件和man文档
[root@SYL3 ~]# ln -s /usr/local/apache/include /usr/include/apache
[root@SYL3 ~]# vim /etc/man_db.conf
[root@SYL3 ~]# cat /etc/man_db.conf |grep apache
MANDATORY_MANPATH /usr/local/apache/man
[root@SYL3 ~]#
7. 配置server文件
[root@SYL3 ~]# cd /usr/lib/systemd/system
[root@SYL3 system]# cp sshd.service httpd.service
[root@SYL3 system]# vim httpd.service
[root@SYL3 system]# cat 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@SYL3 system]# systemctl daemon-reload
[root@SYL3 system]#
[root@SYL3 system]# cd
[root@SYL3 ~]# systemctl status httpd
● httpd.service - httpd server daemon
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabl>
Active: inactive (dead)
Apr 21 19:09:23 SYL3 systemd[1]: /usr/lib/systemd/system/httpd.s>
[root@SYL3 ~]# systemctl enable --now httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@SYL3 ~]# systemctl status httpd
● httpd.service - httpd server daemon
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enable>
Active: active (running) since Thu 2022-04-21 19:10:21 CST; 3>
Main PID: 706285 (apachectl)
Tasks: 2 (limit: 11216)
Memory: 1.5M
CGroup: /system.slice/httpd.service
├─706285 /bin/sh /usr/local/apache/bin/apachectl start
└─706301 /usr/local/apache/bin/httpd -k start
Apr 21 19:10:21 SYL3 systemd[1]: Started httpd server daemon.
[root@SYL3 ~]# apachectl stop
httpd (no pid file) not running
[root@SYL3 ~]# systemctl start httpd
[root@SYL3 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@SYL3 ~]#
7.1 关闭防火墙和selinux
[root@SYL3 ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@SYL3 ~]# vim /etc/selinux/config
[root@SYL3 ~]# cat /etc/selinux/config|grep SELINUX
# SELINUX= can take one of these three values:
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
SELINUXTYPE=targeted
[root@SYL3 ~]# setenforce 0
[root@SYL3 ~]#
- 出现开启时错误,修改配置文件将注释取消
[root@SYL3 ~]# apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::20c:29ff:fe88:169d%ens160. Set the 'ServerName' directive globally to suppress this message
[root@SYL3 ~]# cd /usr/local/apache/conf/
[root@SYL3 conf]# ls
extra httpd.conf magic mime.types original
[root@SYL3 conf]# vim httpd.conf
[root@SYL3 conf]# cat httpd.conf |grep ServerName
# ServerName gives the name and port that the server uses to identify itself.
ServerName www.example.com:80
[root@SYL3 conf]# cd
[root@SYL3 ~]# apachectl start
[root@SYL3 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@SYL3 ~]#
- 访问成功
四. MySQL的安装
1.安装MySQL
[root@SYL3 ~]# rpm -ivh mysql57-community-release-el7-10.noarch.rpm
warning: mysql57-community-release-el7-10.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql57-community-release-el7-10 ################################# [100%]
[root@SYL3 ~]#
2. 安装MySQL源
[root@SYL3 ~]# ls
anaconda-ks.cfg
apr-1.7.0
apr-1.7.0.tar.gz
apr-util-1.6.1
apr-util-1.6.1.tar.gz
httpd-2.4.53
httpd-2.4.53.tar.gz
mysql-community-client-5.7.37-1.el7.x86_64.rpm
mysql-community-common-5.7.37-1.el7.x86_64.rpm
mysql-community-devel-5.7.37-1.el7.x86_64.rpm
mysql-community-libs-5.7.37-1.el7.x86_64.rpm
mysql-community-server-5.7.37-1.el7.x86_64.rpm
[root@SYL3 ~]# yum -y install *.rpm
3. 配置MySQL
3.1 启动并设置开机自启
[root@SYL3 ~]# systemctl enable --now mysqld
[root@SYL3 ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabl>
Active: active (running) since Thu 2022-04-21 20:03:59 CST; 3>
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 927065 ExecStart=/usr/sbin/mysqld --daemonize --pid-f>
Process: 926461 ExecStartPre=/usr/bin/mysqld_pre_systemd (code>
Main PID: 927067 (mysqld)
Tasks: 27 (limit: 11216)
Memory: 287.3M
CGroup: /system.slice/mysqld.service
└─927067 /usr/sbin/mysqld --daemonize --pid-file=/var>
Apr 21 20:03:45 SYL3 systemd[1]: Starting MySQL Server...
Apr 21 20:03:59 SYL3 systemd[1]: Started MySQL Server.
[root@SYL3 ~]#
3.2 确定MySQL端口是否监听
[root@SYL3 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@SYL3 ~]#
4. 设置密码
4.1 找出临时密码
[root@SYL3 ~]# grep 'password' /var/log/mysqld.log
2022-04-21T12:03:49.424496Z 1 [Note] A temporary password is generated for root@localhost: Jw?eSqkBI8(3
[root@SYL3 ~]#
4.2 设置密码并登录
[root@SYL3 ~]# mysql -uroot -p'Jw?eSqkBI8(3'
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 2
Server version: 5.7.37
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> set password = password('Run123456!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
[root@SYL3 ~]# mysql -uroot -p'Run123456!'
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> quit
- 为避免mysql自动升级,这里需要卸载最开始安装的yum源
[root@SYL3 ~]# rpm -qa|grep mysql
mysql57-community-release-el7-10.noarch
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
[root@SYL3 ~]# rpm -e mysql57-community-release
[root@SYL3 ~]#
5. 设置权限
mysql> grant all on *.* to 'root'@'192.168.232.1' identified by 'Run123456!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
五. apache的配置
1. 启动代理模块
[root@SYL3 ~]# cd /usr/local/apache/conf/
[root@SYL3 conf]# ls
extra httpd.conf magic mime.types original
[root@SYL3 conf]# vim httpd.conf
[root@SYL3 conf]# cat httpd.conf |grep mod_proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
2. 配置虚拟主机
2.1 创建虚拟主机目录并生成php测试页面
[root@SYL3 ~]# cd /usr/local/apache/htdocs/
[root@SYL3 htdocs]# mkdir mushuang.com
[root@SYL3 htdocs]# chown -R apache.apache /usr/local/apache/
[root@SYL3 htdocs]# cd mushuang.com
[root@SYL3 mushuang.com]# vim index.php
[root@SYL3 mushuang.com]# cat index.php
<?php
phpinfo();
?>
[root@SYL3 mushuang.com]#
[root@SYL3 htdocs]# ll
total 4
-rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html
drwxr-xr-x. 2 apache apache 23 Apr 22 13:22 mushuang.com
[root@SYL3 htdocs]#
2.2 在配置文件的最后加入以下内容
[root@SYL3 apache]# ls
bin cgi-bin error icons logs manual
build conf htdocs include man modules
[root@SYL3 apache]# vim conf/httpd.conf
[root@SYL3 apache]#
[root@SYL3 conf]# cat httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/mushuang.com"//网站存放的位置
ServerName mushuang.example.com//域名,网站的名字
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/mushuang.com/$1
<Directory "/usr/local/apache/htdocs/mushuang.com">//允许写入
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
2.3 修改主配置文件,搜索AddType,添加以下内容
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php #添加此行
AddType application/x-httpd-php-source .phps #添加此行
- 配置
[root@SYL3 ~]# cd /usr/local/apache/conf/
[root@SYL3 conf]# vim httpd.conf
[root@SYL3 conf]# vim httpd.conf
[root@SYL3 conf]# cat httpd.conf |grep index.php
DirectoryIndex index.php index.html
[root@SYL3 conf]# cat httpd.conf |grep 'AddType application/x-httpd'
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
[root@SYL3 conf]#
[root@SYL3 apache]# vim conf/httpd.conf
[root@SYL3 apache]# cat conf/httpd.conf |grep index.php
DirectoryIndex index.php index.html
[root@SYL3 apache]#
六. PHP的安装
1. 解压
[root@SYL3 ~]# ls
anaconda-ks.cfg
apr-1.7.0
apr-1.7.0.tar.gz
apr-util-1.6.1
apr-util-1.6.1.tar.gz
httpd-2.4.53
httpd-2.4.53.tar.gz
mysql-community-client-5.7.37-1.el7.x86_64.rpm
mysql-community-common-5.7.37-1.el7.x86_64.rpm
mysql-community-devel-5.7.37-1.el7.x86_64.rpm
mysql-community-libs-5.7.37-1.el7.x86_64.rpm
mysql-community-server-5.7.37-1.el7.x86_64.rpm
php-7.4.29.tar.gz
[root@SYL3 ~]# tar xf php-7.4.29.tar.gz
2. 安装依赖包
[root@SYL3 ~]# 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 sqlite-devel libzip-devel
[root@SYL3 ~]# yum -y install yum -y install https://vault.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
3. 编译安装PHP
- 进行预编译
[root@SYL3 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
4. 安装PHP
[root@SYL3 php-7.4.29]# make -j 4
[root@SYL3 php-7.4.29]# make install
5. 设置环境变量,lib,头文件
[root@SYL3 ~]# echo 'export PATH=/usr/local/php7/bin:/usr/local/php7/:sbin:$PATH' > /etc/profile.d/php7.sh //设置环境变量
[root@SYL3 ~]# source /etc/profile.d/php7.sh//读取
[root@SYL3 ~]# which php
/usr/local/php7/bin/php
[root@SYL3 php7]# ln -s /usr/local/php7/include /usr/include/php
[root@SYL3 php7]# vim /etc/ld.so.conf.d/php.conf
[root@SYL3 php7]# cat /etc/ld.so.conf.d/php.conf
/usr/local/php7/lib
[root@SYL3 php7]# ldconfig
6. 配置php-fpm
[root@SYL3 ~]# cd php-7.4.29
[root@SYL3 php-7.4.29]# \cp php.ini-production /etc/php.ini //将PHP目录下的生产环境覆盖到/etc/ini
[root@SYL3 php-7.4.29]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp: overwrite '/etc/init.d/php-fpm'? y
[root@SYL3 php-7.4.29]# chmod +x /etc/rc.d/init.d/php-fpm //设置执行权限
[root@SYL3 php-7.4.29]# ll /etc/rc.d/init.d/php-fpm
-rwxr-xr-x. 1 root root 54696280 Apr 22 13:52 /etc/rc.d/init.d/php-fpm
[root@SYL3 php-7.4.29]#
[root@SYL3 php-7.4.29]# cd /usr/local/php7/etc/
[root@SYL3 etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@SYL3 etc]# cp php-fpm.conf.default php-fpm.conf//复制一份名为php-fpm.conf
[root@SYL3 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[root@SYL3 etc]# cd php-fpm.d
[root@SYL3 php-fpm.d]# ls
www.conf.default
[root@SYL3 php-fpm.d]# cp www.conf.default www.conf//复制一份www.conf
[root@SYL3 php-fpm.d]# ls
www.conf www.conf.default
[root@SYL3 php-fpm.d]#
7. 查看PHP的端口号
[root@SYL3 php-fpm.d]# vim www.conf
[root@SYL3 php-fpm.d]# cat www.conf|grep 9000
listen = 127.0.0.1:9000
[root@SYL3 php-fpm.d]#
8. 重启服务
[root@SYL3 ~]# 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 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@SYL3 ~]# /etc/init.d/php-fpm
[root@SYL3 ~]# 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 [::]:*
[root@SYL3 ~]# systemctl restart httpd
[root@SYL3 ~]# 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 [::]:*
[root@SYL3 ~]#
9. 访问成功
- 查看域名
C:\Windows\System32\drivers\etc
9.1 用ip访问
9.2 用域名访问
七. 安装PHP出现的问题
1. 编译安装PHP,用下面的安装出现的问题
[root@SYL3 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 \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-zlib-dir \
> --with-freetype-dir \
> --with-gettext \
> --enable-json \
> --enable-mbstring \
> --enable-pdo \
> --with-mysqli=mysqlnd \
> --with-pdo-mysql=mysqlnd \
> --with-readline \
> --enable-shmop \
> --enable-simplexml \
> --enable-sockets \
> --enable-zip \
> --enable-mysqlnd-compression-support \
> --with-pear \
> --enable-pcntl \
> --enable-posix
1. 问题1,缺少’sqlite3’包
Package 'sqlite3', required by 'virtual:world', not found
'sqlite3'包,'virtual:world'需要,未找到
[root@SYL3 php-7.4.29]# yum list all|grep sqlite
[root@SYL3 php-7.4.29]# yum -y install sqlite-devel
2.问题2,缺少包’oniguruma’
2.1 下载oniguruma包的网址
Package 'oniguruma', required by 'virtual:world', not found
包'oniguruma',需要'virtual:world',未找到
[root@SYL3 php-7.4.29]# yum list all|grep oniguruma
找到后安装进行预编译失败后在
[root@SYL3 php-7.4.29]# yum -y install https://vault.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
3. 问题3.
configure: WARNING: unrecognized options: --with-gd, --with-jpeg-dir, --with-png-dir, --with-freetype-dir, --enable-zip
- 解决
[root@SYL3 php-7.4.29]# ./configure --help|grep gd
--with-gdbm[=DIR] DBA: GDBM support
--enable-gd Include GD support
--with-external-gd Use external libgd
--with-webp GD: Enable WEBP support (only for bundled libgd)
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
--with-xpm GD: Enable XPM support (only for bundled libgd)
libgd)
--enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support (only
for bundled libgd)
[root@SYL3 php-7.4.29]# ./configure --help|grep jpeg
--with-jpeg GD: Enable JPEG support (only for bundled libgd)
[root@SYL3 php-7.4.29]# ./configure --help|grep png
[root@SYL3 php-7.4.29]# ./configure --help|grep freetype
--with-freetype GD: Enable FreeType 2 support (only for bundled
[root@SYL3 php-7.4.29]# ./configure --help|grep zip
--with-zip Include Zip read/write support
[root@SYL3 php-7.4.29]#
4. 问题4 缺少’libzip’包
Package 'libzip', required by 'virtual:world', not found
'libzip'包,需要'virtual:world',未找到
[root@SYL3 ~]# yum list all|grep libzip
Failed to set locale, defaulting to C.UTF-8
libzip.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
libzip-devel.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
libzip-tools.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
[root@SYL3 ~]#
[root@SYL3 php-7.4.29]# yum -y install libzip-devel
4. 问题4 缺少’libzip’包
FreeType 2 support (only for bundled
[root@SYL3 php-7.4.29]# ./configure --help|grep zip
--with-zip Include Zip read/write support
[root@SYL3 php-7.4.29]#
Package 'libzip', required by 'virtual:world', not found
'libzip'包,需要'virtual:world',未找到
[root@SYL3 ~]# yum list all|grep libzip
Failed to set locale, defaulting to C.UTF-8
libzip.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
libzip-devel.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
libzip-tools.x86_64 1.5.1-2.module_el8.2.0+313+b04d0a66 AppStream
[root@SYL3 ~]#
[root@SYL3 php-7.4.29]# yum -y install libzip-devel