PHP FPM is one of the best ways to manage heavy traffic websites.
When using PHP-FPM, a dedicated service designed for processing PHP scripts handles the task.
Sometimes, PHP FPM may not work as we expect due to the bad configuration in web server settings.
At Bobcares, we often get requests from our customers to fix PHP FPM errors while installing it on centos server as part of our Server Management Services.
Today, we’ll see how our Support Engineers PHP FPM install on Centos and fix related errors.
How to install PHP-FPM on CentOS
PHP-FPM is easier to use and configure. Also, it is more efficient than FastCGI. Again, it needs fewer server resources than other PHP handlers like CGI, DSO.
Let’s see how our Support Engineers configure PHP-FPM on CentOS 7 with Nginx.
1. Initially, we log into the server as a root user.
2. Then, we turn on EPEL repo and Remi repo by following commands.
yum install epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
3. Also, we Install yum-utils packages too:
yum install yum-utils
4. Then, we enable Remi repo by using the following commands.
yum-config-manager --enable remi-php72
yum update
6. Again, we installed PHP7.2 on the server with the following commands.
yum install php72
7. After that, we installed php72-php-fpm along with commonly used modules:
yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
8. Next, we turn on PHP fpm for Nginx.
systemctl enable php72-php-fpm.service
9. At last, we start, stop and restart the service.
systemctl start php72-php-fpm.service
systemctl stop php72-php-fpm.service
systemctl restart php72-php-fpm.service
Moreover, the customers can customize PHP FPM parameters through a control panel like cPanel. Cpanel has a feature like MultiPHP manager that allows changing the PHP FPM parameters with few clicks. This interface looks like.
How we fixed errors after installing PHP fpm on CentOS
From our experience in managing server, we’ve seen that customers facing problems after installing PHP fpm on Centos. Let’s take a closer look at how our Support Engineers fixed the problems.
Wrong User and Group names
Recently one of our customers had a problem with his php-fpm. His php-fpm didn’t work after installing it on the server. He got an internal server error (500) Nginx.
Then our Support Engineers took the following steps to solve the issue.
1. We logged into the server as a root user.
2. Then, we used info,php file to check whether the php-fpm enabled or not on the server.
3. It was enabled but the settings in the Nginx configuration was wrong.
We used the following command to find out server user and group names. We found it was set to apache instead of nginx.
egrep '^(user|group)' /etc/nginx/nginx.conf
4. Then, we edited vi /etc/php-fpm.d/www.conf. And, set user and group to nginx:
user = nginx
group = nginx
5. Next, we saved the file. restarted php-fpm service.
systemctl restart php72-php-fpm.service
That fixed the issue.
Bad configuration settings
Often improper settings in the configuration file create problem after installing PHP FPM on the server. One of our customers got an Nginx 502 Bad Gateway Error on his website.
This is how our Support Engineers fixed it.
1. Initially, we checked the error log /var/log/nginx/error.log. And, we found the following entry.
"2019/01/30 23:57:31 [crit] 26911#0: *1 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.15, server: 192.168.0
2. We found that it was related to wrong settings in the Nginx configuration file. The customer tried upstreaming to unix:/var/run/php7.0-fpm.sock insted of unix:/var/run/php/php7.0-fpm.sock. This caused the error.
3. So, we updated the Nginx config file, /etc/nginx/conf.d/default.conf and edited the following lines too.
{
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4. Finally, we restarted the Nginx server.
systemctl restart nginx
This is how we fixed the issue.
[Having trouble while installing PHP FPM on centos? We’ll fix it for you.]
Conclusion
In short, While installing PHP FPM on centos, customers may face errors due to the bad configuration in web server settings. Today, we saw how our Support Engineers installed PHP FPM on CentOS fixed related errors.
Is that work on centos6?.
I have centos 6 server with PHP 5. I need to install php 7.2 with php-fpm on the same server without affecting php5. Is that possible?