环境 | ip | 服务 |
---|---|---|
RHEL7 | 192.168.118.100 | nginx |
RHRL7 | 192.168.118.128 | mysql |
RHEL7 | 192.168.118.112 | php |
三台服务器都关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
安装nginx
nginx
安装mysql
msql安装
##只看安装就可以
安装php
[root@haha local]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-develreadline readline-devel libxslt libxslt-devel mhash mhash-deve
[root@haha local]# cd /usr/src/
[root@haha src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
[root@haha src]# tar xf php-7.2.8.tar.xz
[root@haha src]# cd php-7.2.8/
[root@haha php-7.2.8]# ./configure --prefix=/usr/local/php7 \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir=/usr \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-jpeg-dir \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
[root@haha php-7.2.8]# make && make install
[root@haha bin]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@haha bin]# source /etc/profile.d/php7.sh
[root@haha bin]# which php
/usr/local/php7/bin/php
[root@haha bin]# php -v
PHP 7.2.8 (cli) (built: Sep 26 2018 09:17:49) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
[root@haha php-7.2.8]# cp php.ini-production /etc/php.ini
[root@haha php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@haha php-7.2.8]# chmod +x /etc/init.d/php-fpm
[root@haha php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@haha php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@haha php-7.2.8]# 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 //最大空闲进程数
[root@haha php-7.2.8]# tail /usr/local/php7/etc/php-fpm.conf
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p argument)
; - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
[root@haha php-7.2.8]# service php-fpm start
Starting php-fpm done
\\默认情况下,fpm监听在127.0.0.1的9000端口
[root@haha php-7.2.8]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@haha php-7.2.8]# ps -ef | grep php
root 67777 1 0 09:32 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 67778 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67779 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67780 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67781 67777 0 09:32 ? 00:00:00 php-fpm: pool www
nobody 67782 67777 0 09:32 ? 00:00:00 php-fpm: pool www
root 67785 2020 0 09:32 pts/2 00:00:00 grep --color=auto php
修改nginx配置文件
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
error_log logs/error.log; #取消错误日志的注释
#启用这几行
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
server {
listen 80; #监听80端口
# server_name 192.168.118.128;
charset koi8-r;
access_log logs/host.access.log main;
location / {
root /www; #存放网页路径
index index.html index.htm;
}
#取消下面的注释
location ~ \.php$ {
root /www;
fastcgi_pass 192.168.118.112:9000; #php服务器的ip
fastcgi_index index.php ; #和访问文件名相同
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
创建存放网站名称,写入php网页信息
[root@php-fpm ~]# mkdir /www
[root@php-fpm ~]# chown -R nginx.nginx /www
[root@php-fpm ~]# cd /www/
[root@php-fpm www]# cat test.php
重启php 和nginx
[root@nginx-server ~]# service nginx restart
[root@php-fpm www]# service php-fpm restart
Gracefully shutting down php-fpm . done