Install Nginx with PHP 7.2.10 and PHP-FPM on Fedora 29 and RHEL/Centos 7.6
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
Select what you need: OPcache, APCu, CLI, PEAR, PDO, MySQL, PostgreSQL, MongoDB, Memcache, Memcached, GD, MBString, MCrypt, XML
Install PHP with all Included Modules
Fedora 29
dnf 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
dnf --enablerepo=remi --enablerepo=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
CentOS 7.5/6.10 and Red Hat (RHEL) 7.5/6.10
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
Check PHP version Installed :
[[email protected] ]# php --version PHP 7.2.11 (cli) (built: Oct 9 2018 15:09:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.11, Copyright (c) 1999-2018, by Zend Technologies [[email protected] ]#
A.5 Disable and remove httpd (Apache) server if installed , Start Nginx HTTP server and PHP-FPM (FastCGI Process Manager)
Stop httpd (Apache)
## Fedora 28/29 and CentOS/RHEL 7.6 ## systemctl stop httpd.service systemctl disable httpd.service ## CentOS/RHEL 6.10 ## service httpd stop chkconfig httpd off
Start Nginx
## Fedora 28/29 and CentOS/RHEL 7.6 ## systemctl start nginx.service ## CentOS/RHEL 6.10 ## service nginx start
Start PHP-FPM
## Fedora 28/29 and CentOS/RHEL 7.5 ##
systemctl start php-fpm.service
## CentOS/RHEL 6.10 ##
/etc/init.d/php-fpm start ## use restart after update
## OR ##
service php-fpm start ## use restart after update
1.6 Autostart Nginx and PHP-FPM on boot, also prevent httpd (Apache) autostarting on boot
Prevent httpd (Apache) autostarting on boot
Autostart Nginx on boot
## Fedora 28/29 and CentOS/RHEL 7.6 systemctl enable nginx.service ## CentOS/RHEL 6.10 ## chkconfig --add nginx chkconfig --levels 235 nginx on
Autostart PHP-FPM on boot
## Fedora 28/9 and CentOS/RHEL 7.6 systemctl enable php-fpm.service ## CentOS/RHEL 6.10 ## chkconfig --add php-fpm chkconfig --levels 235 php-fpm on
A.7 Configure Nginx and PHP-FPM
Latest Fedora Nginx + PHP-FPM builds use custom config, first restore default config
Restore nginx configs to default
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak vi /etc/nginx/nginx.conf
This is how my nginx conf file look like
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events < worker_connections 1024; >http < include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; >
Modify PHP-FPM to listen ip instead of socket ##
vi /etc/php-fpm.d/www.conf
## Change following Lines## ;listen = /run/php-fpm/www.sock listen = 127.0.0.1:9000
public_html directory for site Osradar.local
mkdir -p /var/www/osradar.local chown -R nginx:nginx /var/www/osradar.local
add logs under /var/log directory.
## public_html directory and logs directory ## mkdir -p /var/www/osradar.local/ chown -R nginx:nginx /var/www/osradar.local chown -R nginx:nginx /var/log/nginx
my Vhost Configuration File
cat /etc/nginx/conf.d/osradar.local.conf
Start Nginx
Fedora 28/29 and CentOS/RHEL 7.6 ## systemctl restart nginx.service ## CentOS/RHEL 6.10 ## service nginx restart
Add your testsite.local “domain” to /etc/hosts file
/etc/hosts file Nginx on same machine
127.0.0.1 localhost.localdomain localhost 192.168.2.98 osradar.local
A.8 Test your Nginx and PHP-FPM setup
Create /var/www/osradar.local/test.php file with following content:
Note:
If you get 403 forbidden error, then you probably have problem with SELinux, then run simply following command:
chcon -R -t httpd_sys_content_t /var/www/osradar.local/
## Or some apps might need httpd_sys_rw_content_t ##
chcon -R -t httpd_sys_rw_content_t /var/www/osradar.local/
B.0 (Open Port 80 on Iptables Firewall)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
B.1 Restart Iptables Firewall:
B.2. Fedora 28/29 and CentOS/Red Hat (RHEL) 7.6
B.2.1 Add New http Rule to Firewalld
firewall-cmd --permanent --zone=public --add-service=http
B.2.2 Restart firewalld.service
systemctl restart firewalld.service
Access following address, with your browser. http://osradar.local/
note: i have already crated index.html with the text showing bellow on /var/www/osradar.local/index.html
Test PHP conf file http://osradar.local/test.php
Please let us know if you still have any issues so that we can solve it together. Enjoy