Nginx和php-fpm部署到不同的服务器
Nginx安装滤过,基本上nginx上的配置很少,只要添加个server就可以了,主要安装php-fpm服务
php7.1.3安装
1、安装依赖的软件包
yum -y install gcc gcc-c++ autoconf automake libtool re2c flex bison php-mcrypt libmcrypt libmcrypt-devel openssl-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel zlib-devel mcrypt bzip2-devel libicu-devel systemd-devel mhash postgresql-devel glibc-devel glib2-devel ncurses-devel curl-devel gettext-devel lrzsz net-tools make vim
2、添加php用户
groupadd php
useradd -M -s /sbin/nologin -g php php
3、解压源码文件:
tar php-7.1.3.tar.gz
4、编译安装php
cd php-7.1.3
./buildconf --force
./configure --prefix=/usr/local/php-7.1.3 --with-config-file-path=/usr/local/php-7.1.3/etc/ --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mcrypt --with-mhash --with-openssl --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --with-xmlrpc --with-libdir=/usr/lib64 --with-png-dir=/usr/lib64 --with-gettext=/usr/lib64 --with-curl --with-jpeg-dir --with-freetype-dir=/usr/lib64 --with-fpm-user=php --with-fpm-group=php --with-pgsql --with-libxml-dir --with-bz2 --with-pcre-dir --without-gdbm --without-pear --enable-zip --enable-inline-optimization --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-intl --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --enable-soap --enable-session --enable-opcache --enable-fpm --enable-fileinfo --enable-calendar --enable-cli --enable-static --enable-wddx --disable-debug --enable-mysqlnd --enable-pdo --disable-rpath
make install
5、copy配置文件
cp php.ini-development /usr/local/php-7.1.3/etc/php.ini
cp /usr/local/php-7.1.3/etc/php-fpm.conf.default /usr/local/php-7.1.3/etc/php-fpm.conf
cp /usr/local/php-7.1.3/etc/php-fpm.d/www.conf.default /usr/local/php-7.1.3/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
6、编辑配置文件
vim /usr/local/php-7.1.3/etc/php-fpm.d/www.conf
[global]
pid = /usr/local/php-7.1.3/var/run/php-fpm.pid
error_log = /usr/local/php-7.1.3/var/log/php-fpm.log
[php]
listen = 0.0.0.0:9002
listen.allowed_clients = 192.168.1.251 #Nginx服务器的ip地址
user = php
group = php
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
slowlog = /tmp/phpslow.log
request_slowlog_timeout = 1
7、编辑Nginx的配置文件
server {
listen 80;
server_tokens off;
server_name ServerName;
location ~ \.php$ {
root /opt/html; #这是php-fpm服务器上的地址,并不是Nginx的本地地址哦。
fastcgi_pass 192.168.1.250:9002;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
8、启动php-fpm和Nginx的服务即可访问了,不过要在ServerName后面加上index.php