1. Install Nginx, PHP 7.2.12 and PHP-FPM
1.1 Change to root user.
sudo -i
## OR ##
su -
1.2 Install needed repositories
## Remi Dependency on CentOS 7 and Red Hat (RHEL) 7 ##
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
## CentOS 7 and Red Hat (RHEL) 7 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
1.3 Install Nginx, PHP 7.2.12 and PHP-FPM
yum --enablerepo=remi,remi-php72 install nginx php-fpm php-common
1.4 Install PHP 7.2.12 modules
- OPcache (php-opcache) – The Zend OPcache provides faster PHP execution through opcode caching and optimization.
- APCu (php-pecl-apcu) – APCu userland caching
- CLI (php-cli) – Command-line interface for PHP
- PEAR (php-pear) – PHP Extension and Application Repository framework
- PDO (php-pdo) – A database access abstraction module for PHP applications
- MySQL (php-mysqlnd) – A module for PHP applications that use MySQL databases
- PostgreSQL (php-pgsql) – A PostgreSQL database module for PHP
- MongoDB (php-pecl-mongodb) – PHP MongoDB database driver
- Redis (php-pecl-redis) – Extension for communicating with the Redis key-value store
- Memcache (php-pecl-memcache) – Extension to work with the Memcached caching daemon
- Memcached (php-pecl-memcached) – Extension to work with the Memcached caching daemon
- GD (php-gd) – A module for PHP applications for using the gd graphics library
- XML (php-xml) – A module for PHP applications which use XML
- MBString (php-mbstring) – A module for PHP applications which need multi-byte string handling
- MCrypt (php-mcrypt) – Standard PHP module provides mcrypt library support
yum --enablerepo=remi,remi-php72 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml
1.5 Start Nginx HTTP server and PHP-FPM (FastCGI Process Manager)
Start Nginx
## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl start nginx.service
Start PHP-FPM
## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl start php-fpm.service
1.6 Autostart Nginx and PHP-FPM on boot
Autostart Nginx on boot
## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl enable nginx.service
Autostart PHP-FPM on boot
## Fedora 29/28/27 and CentOS/RHEL 7.5 ##
systemctl enable php-fpm.service
1.7 Configure Nginx and PHP-FPM
配置nginx支持php
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak#备份原有配置文件
vi /etc/nginx/nginx.conf #编辑
user nginx nginx; #修改nginx运行账号为:nginx组的nginx用户
:wq #保存退出
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak #备份原有配置文件
vi /etc/nginx/conf.d/default.conf #编辑
index index.php index.html index.htm; #增加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
systemctl restart nginx.service #重启nginx
把 test.php 上传/usr/share/nginx/html.
或
cd /usr/share/nginx/html
vi test.php #添加以下代码
<?php
phpinfo();
?>
:wq! #保存退出