当前位置:   article > 正文

lamp分离部署_php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x

php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64


环境说明:三台主机全部防火墙和selinux关闭状态

IP需要安装的服务
192.168.50.131httpd-2.4
192.168.50.135mysql-5.7
192.168.50.136php
php-mysql

1. 在192.168.50.131上安装httpd

安装yum源
[root@apache131 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
[root@apache131 ~]#  sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@apache131 ~]# yum clean all
[root@apache131 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@apache131 ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@apache131 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@apache131 yum.repos.d]# ls
CentOS-Base.repo      epel-testing-modular.repo
epel-modular.repo     epel-testing.repo
epel-playground.repo  redhat.repo
epel.repo
[root@apache131 yum.repos.d]# vim CentOS-Base.repo         将里面的$releasever改成8
[root@apache131 yum.repos.d]# vim epel.repo           将里面的$releasever改成8
[root@apache131 yum.repos.d]# cd
[root@apache131 ~]# yum clean all
[root@apache131 ~]# yum makecache

安装开发工具包
[root@apache131 ~]# yum groups mark install "Development Tools"


创建apache服务的用户和组
[root@apache131 ~]# useradd -r -M -s /sbin/nologin apache
[root@apache131 ~]# id apache
uid=994(apache) gid=991(apache) groups=991(apache)


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


下载和安装apr以及apr-util
[root@apache131 src]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.gz
[root@apache131 src]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
[root@apache131 src]# wget https://downloads.apache.org/httpd/httpd-2.4.46.tar.bz2
[root@apache131 src]# ls
apr-1.6.5.tar.gz  apr-util-1.6.1.tar.gz  debug  httpd-2.4.46.tar.bz2  kernels
[root@apache131 src]# tar xf apr-1.6.5.tar.gz 
[root@apache131 src]# tar xf apr-util-1.6.1.tar.gz 
[root@apache131 src]# yum -y install lbzip2
[root@apache131 src]# tar xf httpd-2.4.46.tar.bz2 
[root@apache131 src]# ls
apr-1.6.5  apr-1.6.5.tar.gz  apr-util-1.6.1  apr-util-1.6.1.tar.gz  debug  httpd-2.4.46  httpd-2.4.46.tar.bz2  kernels
[root@apache131 src]# cd apr-1.6.5
[root@apache131 apr-1.6.5]# vim configure
 cfgfile="${ofile}T"
    trap "$RM \"$cfgfile\"; exit 1" 1 2 15
    # $RM "$cfgfile"        //将此行加上注释,或者删除此行



配置,编译安装
[root@apache131 apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@apache131 apr-1.6.5]# make
[root@apache131 apr-1.6.5]# make install
[root@apache131 apr-1.6.5]# cd ../apr-util-1.6.1
[root@apache131 apr-util-1.6.1]#  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@apache131 apr-util-1.6.1]# make
[root@apache131 apr-util-1.6.1]# make install
[root@apache131 apr-util-1.6.1]# cd ../httpd-2.4.46
[root@apache131 httpd-2.4.46]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--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@apache131 httpd-2.4.46]# make 
[root@apache131 httpd-2.4.46]# make install



写环境变量
[root@apache131 httpd-2.4.46]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@apache131 httpd-2.4.46]# source /etc/profile.d/httpd.sh
[root@apache131 httpd-2.4.46]# cd
[root@apache131 ~]# which httpd
/usr/local/apache/bin/httpd


做一个软连接
[root@apache131 ~]# ln -s /usr/local/apache/include /usr/include/apache
[root@apache131 ~]# ll -d /usr/include/apache
lrwxrwxrwx. 1 root root 25 Oct 31 16:07 /usr/include/apache -> /usr/local/apache/include



取消ServerName前面的注释
[root@apache131 ~]# vim /etc/httpd24/httpd.conf 
ServerName www.example.com:80


启动apache
[root@apache131 ~]# apachectl start
[root@apache131 ~]# ss -antl
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
LISTEN            0                 128                                      *:80                                    *:*              
LISTEN            0                 128                                   [::]:22                                 [::]:*            
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106

在这里插入图片描述

2. 在192.168.50.135上安装mysql

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


创建用户和组
[root@mysql135 ~]# useradd -r -M -s /sbin/nologin mysql
[root@mysql135 ~]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)


下载二进制格式的mysql软件包
[root@mysql135 ~]# ls
anaconda-ks.cfg  mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz


解压软件至/usr/local/
[root@mysql135 ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mysql135 ~]# ls /usr/local
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.31-linux-glibc2.12-x86_64  sbin  share  src


做软连接并修改属主
[root@mysql135 ~]# cd /usr/local
[root@mysql135 local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql
[root@mysql135 local]# chown -R mysql.mysql mysql
[root@mysql135 local]# ll
total 0
drwxr-xr-x. 2 root  root    6 Aug 12  2018 bin
drwxr-xr-x. 2 root  root    6 Aug 12  2018 etc
drwxr-xr-x. 2 root  root    6 Aug 12  2018 games
drwxr-xr-x. 2 root  root    6 Aug 12  2018 include
drwxr-xr-x. 2 root  root    6 Aug 12  2018 lib
drwxr-xr-x. 2 root  root    6 Aug 12  2018 lib64
drwxr-xr-x. 2 root  root    6 Aug 12  2018 libexec
lrwxrwxrwx. 1 mysql mysql  35 Oct 31 16:19 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 9  7161 31415 129 Jun  2 21:11 mysql-5.7.31-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root  root    6 Aug 12  2018 sbin
drwxr-xr-x. 5 root  root   49 Aug 30 14:12 share
drwxr-xr-x. 2 root  root    6 Aug 12  2018 src


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


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


初始化数据库
[root@mysql135 ~]# mysqld --initialize-insecure --datadir=/opt/data --user=mysql         -insecure是不设密码


配置mysql头文件和lib库
[root@mysql135 ~]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@mysql135 ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@mysql135 ~]# ldconfig            重新读取配置文件


生成配置文件
此时打开配置文件已有内容,所以我们先把这内容备份,以防后面会用到
[root@mysql135 ~]# vim /etc/my.cnf

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@mysql135 ~]# mv /etc/my.cnf{,-bak}
[root@mysql135 ~]# ls /etc/my.cnf*
/etc/my.cnf-bak

/etc/my.cnf.d:
client.cnf

此时再写配置文件
[root@mysql135 ~]# 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@mysql135 ~]#  cd /usr/local/mysql
[root@mysql135 mysql]#  cd support-files
[root@mysql135 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@mysql135 support-files]# cp mysql.server /etc/init.d/mysqld
[root@mysql135 support-files]# cd
[root@mysql135 ~]# ll /etc/init.d/mysqld
-rwxr-xr-x. 1 root root 10576 Oct 31 16:37 /etc/init.d/mysqld
[root@mysql135 ~]# vim /etc/init.d/mysqld 
basedir=/usr/local/mysql                     安装路径和数据路径添加上去
datadir=/opt/data


设置开机自启
[root@mysql135 ~]#  chkconfig --add mysqld
[root@mysql135 ~]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

启动
[root@mysql135 ~]#  service mysqld start
Starting MySQL.Logging to '/opt/data/mysql135.err'.
 SUCCESS! 
[root@mysql135 ~]#  ps -ef |grep mysql
root       14446       1  0 16:40 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/datamysql.pid
mysql      14634   14446  4 16:40 pts/1    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql135.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root       14664    1589  0 16:40 pts/1    00:00:00 grep --color=auto mysql
[root@mysql135 ~]# ss -antl
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
LISTEN            0                 80                                       *:3306                                  *:*              
LISTEN            0                 128                                   [::]:22                                 [::]:*          



登录会报错缺少一个文件,使用whatprovides来查看依赖包
[root@mysql135 ~]# mysql
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@mysql135 ~]#  yum whatprovides libncurses.so.5
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:35:42 ago on Sat 31 Oct 2020 04:06:24 PM CST.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo        : BaseOS
Matched from:
Provide    : libncurses.so.5
[root@mysql135 ~]# yum -y install ncurses-compat-libs



登陆修改密码
[root@mysql135 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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('maqiang123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye


使用新密码登陆
[root@mysql135 ~]# mysql -uroot -pmaqiang123
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.31 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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
Bye

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199

3. 在192.168.50.136上安装php

配置yum源(8.0版本以上可以忽略此步骤)
[root@php136 ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@php136 ~]#  rpm -Uvh remi-release-7.rpm
[root@php136 ~]# yum makecache --enablerepo=remi-php74


8.0版本默认就有php,所以不需要安装源
[root@php136 ~]#  yum list all|grep php
Repository AppStream is listed more than once in the configuration
php.x86_64                                           7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-bcmath.x86_64                                    7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-cli.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-common.x86_64                                    7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-dba.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-dbg.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-devel.x86_64                                     7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-embedded.x86_64                                  7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-enchant.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-fpm.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-gd.x86_64                                        7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-gmp.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-intl.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-json.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-ldap.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-mbstring.x86_64                                  7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-mysqlnd.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-odbc.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-opcache.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-pdo.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-pear.noarch                                      1:1.10.5-9.module_el8.2.0+313+b04d0a66           AppStream 
php-pecl-apcu.x86_64                                 5.1.12-2.module_el8.2.0+313+b04d0a66             AppStream 
php-pecl-apcu-devel.x86_64                           5.1.12-2.module_el8.2.0+313+b04d0a66             AppStream 
php-pecl-zip.x86_64                                  1.15.3-1.module_el8.2.0+313+b04d0a66             AppStream 
php-pgsql.x86_64                                     7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-process.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-recode.x86_64                                    7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-snmp.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-soap.x86_64                                      7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-xml.x86_64                                       7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 
php-xmlrpc.x86_64                                    7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream 


安装依赖包之前先安装epel源
[root@php136 ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@php136 ~]#  sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@php136 ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@php136 ~]# cd /etc/yum.repos.d/
[root@php136 yum.repos.d]# vim epel.repo     将里面的$releasever改成8
[root@php136 yum.repos.d]# cd
[root@php136 ~]# yum clean all
[root@php136 ~]# 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
[root@php136 ~]#  yum list all|grep php|grep mysql
php-mysqlnd.x86_64                                   7.2.24-1.module_el8.2.0+313+b04d0a66             AppStream    
[root@php136 ~]# yum -y install php-mysqlnd



下载php
[root@php136 ~]# cd /usr/src/
[root@php136 src]#  wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@php136 src]# ls
debug  kernels  php-7.2.8.tar.xz


安装编译软件
[root@php136 ~]# yum -y install gcc gcc-c++ make



编译安装php
[root@php136 ~]# cd /usr/src/
[root@php136 src]# ls
debug  kernels  php-7.2.8.tar.xz
[root@php136 src]# tar xf php-7.2.8.tar.xz 
[root@php136 src]#  cd php-7.2.8
[root@php136 php-7.2.8]# ./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
[root@php136 php-7.2.8]# make
[root@php136 php-7.2.8]# make install


设置环境变量
[root@php136 php-7.2.8]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php.sh
[root@php136 php-7.2.8]# source /etc/profile.d/php.sh 
[root@php136 php-7.2.8]# which php
/usr/local/php7/bin/php



配置php-fpm
[root@php136 php-7.2.8]#  cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@php136 php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php136 php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@php136 php-7.2.8]# cd /usr/local/php7/etc/
[root@php136 etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d
[root@php136 etc]# cp php-fpm.conf.default php-fpm.conf
[root@php136 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@php136 etc]# cd php-fpm.d/
[root@php136 php-fpm.d]# ls
www.conf.default
[root@php136 php-fpm.d]# cp www.conf.default www.conf
[root@php136 php-fpm.d]# ls
www.conf  www.conf.default



编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
配置fpm的相关选项为你所需要的值:配置文件最后添加以下四行
[root@php136 php-fpm.d]# vim /usr/local/php7/etc/php-fpm.conf
.....
.....
pm.max_children = 50    ;最多同时提供50个进程提供50个并发服务
pm.start_servers = 5    ;启动时启动5个进程
pm.min_spare_servers = 2    ;最小空闲进程数
pm.max_spare_servers = 8    ;最大空闲进程数


启动php-fpm
[root@php136 ~]# service php-fpm start
Starting php-fpm  done
[root@php136 ~]# ss -antl
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
LISTEN            0                 128                              127.0.0.1:9000                            0.0.0.0:*              
LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
LISTEN            0                 128                                   [::]:22                                 [::]:*         


提供网站
[root@php136 ~]#  mkdir -p   /usr/local/php7/htdocs/
[root@php136 ~]# cd /usr/local/php7/htdocs/
[root@php136 htdocs]# ls
[root@php136 htdocs]# vim index.php

<?php
    phpinfo();
?>
[root@php136 htdocs]# pwd
/usr/local/php7/htdocs
[root@php136 htdocs]# useradd -r -M -s /sbin/nologin apache
useradd: user 'apache' already exists
[root@php136 htdocs]# chown -R apache.apache /usr/local/php7/htdocs/
[root@php136 htdocs]# ll
total 4
-rw-r--r--. 1 apache apache 24 Oct 31 18:55 index.php



更改监听端口,让httpd服务器能找到
[root@php136 htdocs]#  vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 0.0.0.0:9000    #改为全IP,使所有的客户端都可以访问

再次重启
[root@php136 htdocs]# service  php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done
[root@php136 htdocs]# ss -antl
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
LISTEN            0                 128                                0.0.0.0:9000                            0.0.0.0:*              
LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
LISTEN            0                 128                                   [::]:22                                 [::]:*              
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198

4. 配置apache

4.1 启用代理模块

进入配置文件,将这两个注释取消掉
[root@apache131 ~]# vim /etc/httpd24/httpd.conf 
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
  • 1
  • 2
  • 3
  • 4

4.2 配置虚拟主机

[root@apache131 ~]# vim /etc/httpd24/httpd.conf 
# Virtual hosts
Include /etc/httpd24/extra/httpd-vhosts.conf     #取消注释,启动虚拟主机文件
[root@apache131 ~]# vim /etc/httpd24/extra/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://192.168.50.136:9000/usr/local/php7/htdocs/$1            此处填php服务器ip
    #开启反向代理
    <Directory "/usr/local/apache/htdocs">
        Require all granted
    </Directory>
</VirtualHost>
以上设置表示把以.php结尾的文件请求发送到php-fpm进程,php-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://127.0.0.1:9000后指明了这两个参数,其它参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定



[root@apache131 ~]#  vim /etc/httpd24/httpd.conf 
#搜索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        #添加此行

 #找到index.html 添加index.php
 <IfModule dir_module>
    DirectoryIndex  index.php index.html
</IfModule>



重启服务
[root@apache131 ~]# apachectl restart
[root@apache131 ~]# ss -antl
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           
LISTEN            0                 128                                0.0.0.0:22                              0.0.0.0:*              
LISTEN            0                 128                                      *:80                                    *:*              
LISTEN            0                 128                                   [::]:22                                 [::]:*             
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

5. 验证

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/307869
推荐阅读
相关标签
  

闽ICP备14008679号