How to install and configure PHP with Nginx on centos7
This blog will help you to install and configure PHP with Nginx on centos7
Prerequisite
Centos version 7, User with Sudo privileges
Procedure
Step 1: Install the EPEL repository
$ sudo yum install epel-release
Step 2: Install and start Nginx
Run the following command to install nginx,
$ sudo yum install nginx
To start and enable the service using the below command,
$ sudo systemctl enable –now nginx
Step 3: Install PHP
$ sudo yum install PHP
Step 4: Configure the php
Edit the php.ini file,
$ sudo vim /etc/php.ini
Find the line & uncomment it and change it to 0
cgi.fix_pathinfo=0
Then, edit the php-fpm configuration file,
$ sudo vim /etc/php-fpm.d/www.conf
Modify the following lines,
- listen = /var/run/php-fpm/php-fpm.sock
- listen.owner = nginx
- listen.group = nginx
- user = nginx
- group = nginx
Next, start and enable the PHP processor by running the command,
$ sudo systemctl enable –now php-fpm
Step 5: Nginx configuration to process PHP pages
$ sudo vim /etc/nginx/conf.d/default.conf
Change the file as seen as below,
Restart the Nginx service to reload the configuration file changes.
$ sudo systemctl restart nginx
Then you can test the PHP process on the web server by creating the info.php page on /usr/share/nginx/html.
And check whether the PHP is processing on the web browser by visiting the following page in a browser
http://your-server-IP-address/info.php