The installation and configuration of NGINX+PHP under Centos7

Keywords: Web Server PHP Nginx zlib OpenSSL

First compile and install NGINX:

1. Install dependency package

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

2. Run configure configuration

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

4. Compile and install

make && make install

5. Start NGINX

/usr/local/nginx/sbin/nginx //start-up
/usr/local/nginx/sbin/nginx -s stop //Close
/usr/local/nginx/sbin/nginx -s reload //restart
ps -ef | grep nginx  //View startup status

Compile and install PHP+PHP-FPM

1. Installation dependency

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. Run configure configuration

./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. Compile and install

make && make install

Copy PHP configuration file php.ini-development and rename it 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. Start PHP FPM

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

View service status

ps -A|grep php

If there is a PHP FPM process and no error is reported, then we write a PHP test page.

vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

Modify NGINX configuration file

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

Add root configuration

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

Remove the comments for the PHP configuration and add the ducument? Root variable

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;
}

Check profile

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

Make sure there is no problem and reload nginx

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

Browser access http://192.168.3.211/index.php

The test page is displayed normally and the configuration is successful.

Posted by coupe-r on Mon, 21 Oct 2019 10:48:16 -0700