Current Location: Home> Latest Articles> Step-by-Step Guide to Configure PHP 5.5 with Nginx on CentOS

Step-by-Step Guide to Configure PHP 5.5 with Nginx on CentOS

gitbox 2025-07-26

Introduction

With increasing demands for performance and security in web development, combining PHP 5.5 with Nginx has become popular. This article offers a comprehensive solution for setting up PHP 5.5 and Nginx on a CentOS system, enabling you to build an efficient and stable web server.

Preparation

Before starting, it’s recommended to update your CentOS system to the latest version to ensure stability. Run the following command:

sudo yum update -y

Installing Nginx

Begin by installing Nginx using the commands below:

sudo yum install epel-release -y
sudo yum install nginx -y

Start and Enable Nginx on Boot

Once installed, start the Nginx service and enable it to start on boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Installing PHP 5.5

Since PHP 5.5 is not available in the default CentOS repositories, you need to add an external repository before installation:

sudo yum install php55 php55-fpm -y

Configuring PHP-FPM

After installation, edit the PHP-FPM configuration file to set the running user and group:

sudo vi /etc/php-fpm.d/www.conf

Locate and modify the following lines:

user = nginx
group = nginx

Start and Enable PHP-FPM on Boot

Start PHP-FPM and enable it to launch at startup:

sudo systemctl start php-fpm
sudo systemctl enable php-fpm

Configure Nginx to Support PHP 5.5

Create a new configuration file in Nginx’s configuration directory to enable PHP processing:

sudo vi /etc/nginx/conf.d/php55.conf

Add the following content:

listen 80;
server_name your_domain.com;
root /usr/share/nginx/html;
index index.php index.html index.htm;

location / {
    try_files $uri $uri/ =404;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Test Nginx Configuration and Restart Service

Check the Nginx configuration for syntax errors:

sudo nginx -t

If everything is correct, restart Nginx:

sudo systemctl restart nginx

Testing the PHP Environment

Create a PHP test page to verify your setup:

echo '<?php phpinfo(); ?>' | sudo tee /usr/share/nginx/html/info.php

Visit http://your_domain.com/info.php in your browser. If the PHP info page displays, your setup is successful.

Conclusion

Following these steps, you have successfully installed and configured PHP 5.5 with Nginx on a CentOS server. This setup delivers improved performance and reliability suitable for projects requiring PHP 5.5 support.