Centos7下NGINX+PHP的安装及配置


首先编译安装NGINX:

1.安装依赖包

yum install -y gcc-c++  pcre pcre-devel  zlib zlib-devel openssl openssl-devel

2.运行configure配置

cd /usr/local/src/nginx-1.14.0 && ./configure --prefix=/usr/local/nginx

4.编译安装

make && make install

5.启动NGINX

/usr/local/nginx/sbin/nginx //启动
/usr/local/nginx/sbin/nginx -s stop //关闭
/usr/local/nginx/sbin/nginx -s reload //重启
ps -ef | grep nginx  //查看启动状态

编译安装PHP+PHP-FPM

1.安装依赖

yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.运行configure配置

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm

3.编译安装

make && make install

拷贝PHP配置文件php.ini-development并重命名为php.ini

cp /usr/local/src/php-7.2.0/php.ini-development /usr/local/php-7.2.0/php.ini-development /usr/local/php/etc/

mv php.ini-development php.ini

4.启动php-fpm

/usr/local/php/sbin/php-fpm

查看服务状态

ps -A|grep php

如果有php-fpm的进程且没有报错,然后我们写一个PHP测试页

vim /usr/local/nginx/html/index.php

修改NGINX配置文件

vim /usr/local/nginx/conf/nginx.conf

添加root配置

server {
listen 80;
server_name index.php.com;
root /usr/local/nginx/html/index.php;

删除PHP配置的注释,并添加ducument_root变量

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ducument_root$fastcgi_script_name;
include fastcgi_params;
}

检查配置文件

/usr/local/nginx/sbin/nginx -t

确保没问题后重载nginx

/usr/local/nginx/sbin/nginx -s reload

浏览器进入http://192.168.3.211/index.php

测试页面正常显示,配置成功。

你可能感兴趣的:(centos,nginx,linux)