Centos7下NGINXPHP的安装及配置

38次阅读

共计 2229 个字符,预计需要花费 6 分钟才能阅读完成。


首先编译安装 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
<?php
phpinfo();
?>

修改 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

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

正文完
 0