03_C74部署_LNP

环境:两台 Centos7.4 最小化安装

软件:PHP 7.1.26 Nginx 1.15.9
IP:192.168.189.73 主机名:web01
192.168.189.74 主机名:web02
一、安装PHP 7.1.26 (web01 web02都要安装PHP Nginx)
1.1、安装依赖包:
yum install -y gcc gcc-c++ libtomcrypt* curl-devel libjpeg-devel libpng-devel freetype-devel libxslt libxslt-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-* m4 autoconf openssl openssl-devel pcre pcre-devel zlib* net-tools lrzsz autoconf automake libxml* ncurses-devel libtool-ltdl-devel* php-devel php-mysql libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl gdbm-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

安装libmcrypet-2.5.7
cd /opt
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure #编译(默认安装到/usr/local/lib/)
make && make install
1.2、下载PHP 7.1.26 解压、安装
cd /opt
wget http://cn2.php.net/distributions/php-7.1.26.tar.gz
tar zxvf php-7.1.26.tar.gz
cd php-7.1.26/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/conf.d --with-mcrypt=/usr/include --with-mysqli --with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-soap --with-openssl --with-openssl-dir --with-pcre-regex --with-zlib --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --with-pcre-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-gettext --with-gmp --with-mhash --enable-mbstring --with-libmbfl --with-onig --enable-pdo --with-zlib-dir --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd --without-pear -enable-tokenizer --enable-opcache

make && make install
1.3、配置PHP
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
cp /opt/php-7.1.26/php.ini-development /usr/local/php/etc/php.ini
cp -r /opt/php-7.1.26/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#修改配置文件
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /usr/local/php/etc/php-fpm.conf
sed -i 's#short_open_tag = Off#short_open_tag = On#g' /usr/local/php/etc/php.ini
sed -i 's#pdo_mysql.default_socket=#pdo_mysql.default_socket= /usr/local/mysql-5.7.25/run/mysql.sock#g' /usr/local/php/etc/php.ini
chmod +x /etc/init.d/php-fpm
#配置开机启动
chkconfig --add /etc/init.d/php-fpm
chkconfig php-fpm on
systemctl start php-fpm

二、安装Nginx 1.15.9
2.1、安装依赖包:
yum install gcc gcc-c++ pcre pcre-devel openssl openssl-devel -y
useradd -s /sbin/nologin nginx
2.2、下载Nginx 解压、安装
cd /opt
wget http://nginx.org/download/nginx-1.15.9.tar.gz
tar zxf nginx-1.15.9.tar.gz
cd nginx-1.15.9/
./configure --with-http_ssl_module --with-http_stub_status_module --prefix=/usr/local/nginx/
make
make install
2.3、配置nginx服务
cd /usr/lib/systemd/system
touch nginx.service
chmod 754 nginx.service

cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=True
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
2.4、修改Nginx 配置文件,整合PHP

cd /usr/local/nginx/conf/
cp nginx.conf nginx.conf.$(date +%F%H%M%S)
cat >/usr/local/nginx/conf/nginx.conf << EOF
worker_processes 4;
worker_rlimit_nofile 100000; #更改worker进程的最大打开文件数限制.
events {
worker_connections 409600;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
server_tokens off; #隐藏版本号。
keepalive_timeout 60;
gzip on;
gzip_disable "msie6"; #设置成IE6或者更低版本禁用gzip功能。
gzip_proxied any;
gzip_min_length 1000; #设置对数据启用压缩的最少字节数。
gzip_comp_level 6;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
try_files \$uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF

2.5、启动
systemctl enable nginx
systemctl start nginx



三、安装NFS (web01 web02都要安装)
yum install rpcbind nfs-utils -y
启动NFS:
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs
四、验证PHP,测试连接Mysql (web01 web02都要操作)
vim /usr/local/nginx/conf/nginx.conf



保存退出。 重启nginx
cd /usr/local/nginx/html
vim test.php





数据库连接测试:

在mysql01 192.168.189.77 上操作
grant all privilege on *.* to root@'192.168.189.%' identified by 'windows@123';
flush privileges

web01 web02 创建连接mysql 的php文件
cd /usr/local/nginx/html && vim sql_con.php

<?php
$mysqli = new mysqli("192.168.189.156", "root", "abc.com123");
if (!$mysqli) {
echo"database error";
}
else{
echo"connect mysql is successful";
}
$mysqli->close();
?>