Bobcares

How we install PHP FPM on CentOS – Related errors and fix

by | May 27, 2019

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.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

1 Comment

  1. Jayakrishnan P

    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?

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF