AMP AMP

How to Test The PHP Configuration on Apache and Nginx Web Servers In CentOS 7.6

Test the configuration of PHP On Apache And Nginx Web Servers In CentOS 7.6

PHP Configuration Test On Apache.

Check the version of Apache And nginx Web server

[root@linuxhelp ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Apr 24 2019 13:45:48
[root@linuxhelp ~]# nginx -v
nginx version: nginx/1.17.0

verify the port numbers of Apache And nginx Webservers.

[root@linuxhelp ~]# netstat -tulpn | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      1414/httpd      
 [root@linuxhelp ~]# netstat -tulpn | grep nginx
tcp        0      0 0.0.0.0:8989            0.0.0.0:*               LISTEN      32344/nginx: master 
tcp6       0      0 :::8989                 :::*                    LISTEN      32344/nginx: master 

Install the required php modules as follows:

[root@linuxhelp ~]# yum install php php-fpm php-mysql php-gd php-opcache php-apcu php-pecl-zip php-pecl-memcached php-pecl-memcache -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.horizon.vn
 * epel: mirror1.ku.ac.th
 * extras: mirror.horizon.vn
 * remi-php72: mirrors.neterra.net
 * remi-safe: mirrors.neterra.net
 * updates: centos-hcm.viettelidc.com.vn
Package php-mysql-5.4.16-46.el7.x86_64 is obsoleted by php-mysqlnd-7.2.17-1.el7.remi.x86_64 which is already installed
Package php-pecl-zip-1.15.4-1.el7.remi.7.2.x86_64 already installed and latest version
Resolving Dependencies
.
.
.
.

Dependency Updated:
  php-cli.x86_64 0:7.2.19-2.el7.remi               php-common.x86_64 0:7.2.19-2.el7.remi            
  php-json.x86_64 0:7.2.19-2.el7.remi              php-mbstring.x86_64 0:7.2.19-2.el7.remi          
  php-mysqlnd.x86_64 0:7.2.19-2.el7.remi           php-pdo.x86_64 0:7.2.19-2.el7.remi               
  php-xml.x86_64 0:7.2.19-2.el7.remi              

Complete!

Change the directory to Apache’s Document Root directory to create a file for viewing the php settings

[root@linuxhelp ~]# cd /var/www/html
[root@linuxhelp html]# vim info.php
 <?php
phpinfo();
?>

Restart the service of Apache

[root@linuxhelp html]# systemctl restart httpd

Open the Browser, Enter the url followed by the info.php

PHP Configuration Test On Nginx:

Enable the service of php-fpm.

[root@linuxhelp html]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

Start the service of php-fpm.

[root@linuxhelp html]# systemctl start php-fpm

Edit the configuration file of PHP

[root@linuxhelp html]# vim /etc/php.ini
cgi.fix_pathinfo=0

Modify the configuration of php-fpm as follows:

[root@linuxhelp html]# vim /etc/php-fpm.d/www.conf
user=nginx
group=nginx
listen.owner=nginx
listen.group=nginx

Change the directory to nginx customised Configuration file

[root@linuxhelp html]# cd /etc/nginx/conf.d/

Create a virtual host named php.conf

[root@linuxhelp conf.d]# vim php.conf
server {

listen 8989;
server_name 192.168.7.229;
root /usr/share/nginx/html;
index index.php;
 location ~* \.php$ {
      fastcgi_pass 127.0.0.1:9000;
      include         fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}

Change the directory to Nginx Document root directory to create a file to view the php settings

[root@linuxhelp conf.d]# cd /usr/share/nginx/html
[root@linuxhelp html]# vim info.php
<?php
Phpinfo();
?>

Restart the service of php-fpm

[root@linuxhelp html]# systemctl restart php-fpm

Test the Configuration of nginx

[root@linuxhelp html]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Restart the service of nginx

[root@linuxhelp html]# systemctl restart nginx.

Open the browser and enter the servername with its appropriate port number followed by info.php

With this,PHP Configuration Test on Apache And Nginx Web Servers in CentOS 7.6 comes to end.

Tag : Php-fpm CentOS
FAQ
Q
What is fastcgi_pass?
A
FastCGI is a programming interface that can speed up web applications.
Q
What is php cgi?
A
CGI stands for Common gateway interface which is a web technology and protocol that defines a way for a web server to interact with external applications.
Q
WHat does php-fpm allow?
A
php-fpm allows a website to handle high loads.
Q
What is the full form of php-fpm?
A
the full form of php-fpm is PHP-FastCGI Process Manager.
Q
What is the main configuration file of php?
A
/etc/php.ini is the configuration file of php