代码语言:javascript复制1、查看是否安装过Nginx
rpm -qa|grep -E "nginx"
代码语言:javascript复制2、安装Nginx前需要提前安装以下这些依赖
2.1、查看gcc版本
gcc -v
若有内容输出说明已安装了gcc。否则,需使用以下命令进行安装。
代码语言:javascript复制 yum -y install gcc
代码语言:javascript复制2.2、pcre、pcre-devel安装
yum install -y pcre pcre-devel
代码语言:javascript复制2.3、zlib安装
yum install -y zlib zlib-devel
代码语言:javascript复制2.4、安装openssl
yum install -y openssl openssl-devel
代码语言:javascript复制3、 安装Nginx
3.1、下载Nginx源码并解压到 /home/nginx-php/
tar -zxvf nginx-1.10.3.tar.gz
代码语言:javascript复制3.2、切换到 /home/nginx-php/nginx-1.10.3
./configure
make
make install
代码语言:javascript复制3.3、切换到/usr/local/nginx/conf 配置目录,编辑nginx.conf
server {
listen 8001;
set $root /home/ecspadmin/public;
location ~ .*.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root $root;
}
location / {
root $root;
index index.html index.php;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
location ~ ^/(uploads|assets)/.*.(php|php5|jsp)$ {
deny all;
}
location ~ . .php($|/) {
#fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^((?U). .php)(/?. )$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
}
代码语言:javascript复制4、源码编译安装 PHP7.1.33
4.1、在安装PHP7.1.33前,需安装以下依赖
yum install -y openssl-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel recode-devel libicu-devel libzip-devel sqlite-devel oniguruma-devel
代码语言:javascript复制4.2、解压下载好的PHP7.1.33 并切换到
tar zxvf php-7.1.33.tar.gz
代码语言:javascript复制4.3、预编译
./configure --prefix=/usr/local/php7
--with-apxs2=/usr/bin/apxs
--with-config-file-path=/usr/local/php/etc
--with-curl
--with-freetype-dir
--with-gd
--with-gettext
--with-iconv-dir
--with-kerberos
--with-libdir=lib64
--with-libxml-dir
--with-mysqli
--with-openssl
--with-pcre-regex
--with-pdo-mysql
--with-pdo-sqlite
--with-pear
--with-png-dir
--with-xmlrpc
--with-xsl
--with-zlib
--enable-fpm
--enable-bcmath
--enable-libxml
--enable-inline-optimization
--enable-gd-native-ttf
--enable-mbregex
--enable-mbstring
--enable-opcache
--enable-pcntl
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvsem
--enable-xml
--enable-zip
make && make install
代码语言:javascript复制4.4、修改php.ini、php-fpm.conf
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod x /etc/rc.d/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
vim /usr/local/php7/etc/php-fpm.conf
最后 添加
pm.max_children =50
pm.start_servers=5
pm.min_spare_servers=2
pm.max_spare_servers=8
tail -4 /usr/local/php7/etc/php-fpm.conf
service php-fpm start
代码语言:javascript复制5、启动Nginx服务
5.1、切换目录到/usr/local/nginx/sbin下面
./nginx
代码语言:javascript复制5.2、启动、暂停服务
./nginx -s stop
./nginx -s quit
./nginx -s reload
最终效果如图: