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.
Before starting, it’s recommended to update your CentOS system to the latest version to ensure stability. Run the following command:
sudo yum update -yBegin by installing Nginx using the commands below:
sudo yum install epel-release -y
sudo yum install nginx -yOnce installed, start the Nginx service and enable it to start on boot:
sudo systemctl start nginx
sudo systemctl enable nginxSince 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 -yAfter installation, edit the PHP-FPM configuration file to set the running user and group:
sudo vi /etc/php-fpm.d/www.confLocate and modify the following lines:
user = nginx
group = nginxStart PHP-FPM and enable it to launch at startup:
sudo systemctl start php-fpm
sudo systemctl enable php-fpmCreate a new configuration file in Nginx’s configuration directory to enable PHP processing:
sudo vi /etc/nginx/conf.d/php55.confAdd 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;
}Check the Nginx configuration for syntax errors:
sudo nginx -tIf everything is correct, restart Nginx:
sudo systemctl restart nginxCreate a PHP test page to verify your setup:
echo '<?php phpinfo(); ?>' | sudo tee /usr/share/nginx/html/info.phpVisit http://your_domain.com/info.php in your browser. If the PHP info page displays, your setup is successful.
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.