Ubuntu Nginx PHP5-FPM UNIX Socket Configuration

Advertisement

Some Extra Steps Needed to Perform in Ubuntu for the Right Nginx PHP5-FPM UNIX Socket Configuration. Else You’ll Face Random 502, 504 Error. There are important parts of many Free Software has been patched, PHP5-FPM is one of them. We described how to fix the PHP5-FPM restart issue, in a separate GitHub project, but honestly; Ubuntu Nginx PHP5-FPM UNIX socket configuration is more difficult to fix by a new user. It will unfortunately give Nginx related error, WP-Cron related errors etc. We have a small list of HTTP Error Codes.

It is basically not even possible to list the number of different type of errors. You have the everything right, these errors are relatively newer and related to modified materials for increasing security after fix of those shell shock, Heartbleed etc. deb Linux unfortunately throws more errors.

Ubuntu Nginx PHP5-FPM UNIX Socket Configuration : Does Socket Exits?

There are reasons to upgrade PHP 5.5.9 to 5.6. Although, our method will solve your issue with 95% warranty. Run php -v and you will get this kind of output :

Errors starts to throw on the fronted and in log file. This happens due to two reasons in combination – improper permission, wrong user-group of nginx and non-existing UNIX socket file. WordPress like software will give you another gift – wp-cron related error. OwnCloud will give APC related error. 95% will be covered if we fix 5 stuffs.

UNIX socket, unfortunately needs to be created. Editing the /etc/php5/fpm/pool.d/www.conf file to make php5-fpm.sock active, in practical never works. Various complex errors become apparent with PHP-MySQL fronted Apps and their Plugins/Modules.

Advertisement

---

Checking the UNIX Socket Configuration

Your /etc/php5/fpm/php-fpm.conf should look like this :

Vim

1

2

3

4

5

6

7

[global]

pid=/var/run/php5-fpm.pid

error_log=/var/log/php5-fpm.log

emergency_restart_threshold=5

emergency_restart_interval=2

events.mechanism=epoll

include=/etc/php5/fpm/pool.d/*.conf

Secondly, you should have a file named php5-fpm.conf at /etc/nginx/conf.d containing this :

Vim

1

2

3

upstreamphp5-fpm-sock{

server unix:/var/run/php5-fpm.sock;

}

Usually it never exists. In that case, do these :

Vim

1

2

3

4

5

6

cd/etc/nginx/conf.d

nano php5-fpm.conf

#copy-paste/writethisstuff

upstreamphp5-fpm-sock{

server unix:/var/run/php5-fpm.sock;

}

Save it and chown the directory :

Vim

1

sudo chown root:www-data/etc/nginx/conf.d/-R

But, nginx is not of www-data user group. We should add :

Vim

1

2

sudo useradd-gwww-data nginx

usermod-a-Gwww-data nginx

These solves many things, but wait.

Editing /etc/php5/fpm/pool.d/www.conf

It is a challenge to edit /etc/php5/fpm/pool.d/www.conf due to hundreds of commented out lines. This is what we are giving you is a fail safe set for chronic patient server :

Vim

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

[www]

user=www-data

group=www-data

listen=/var/run/php5-fpm.sock

listen.owner=www-data

listen.group=www-data

listen.mode=0660

listen.allowed_clients=127.0.0.1

pm=dynamic

pm.max_children=5

pm.start_servers=2

pm.min_spare_servers=1

pm.max_spare_servers=3

pm.max_requests=500

request_terminate_timeout=30

chdir=/

security.limit_extensions=.php.php3.php4.php5

php_flag[display_errors]=off

php_admin_value[error_log]=/var/log/fpm-php.www.log

php_admin_flag[log_errors]=on

php_admin_value[memory_limit]=128M

These settings will never make your 4GB instance blazing fast, but it will be stable.

Restart and Reboot the Services

Vim

1

2

3

4

5

#ifmysql is on the same server

service mysql stop

service php5-fpm stop

service nginx stop

reboot

After the reboot, reload the configurations and start them :

Vim

1

2

3

4

#ifmysql is on the same server

service mysql start

service php5-fpm start

service nginx start

Check /var/log/nginx for Errors

cd to :

cd /var/log/nginx

Vim

1

2

cd/var/log/nginx&&ls-al

caterror.log

Copy & Paste the error to your computer and then empty the error.log file :

cd /var/log/nginx

Vim

1

2

3

4

echo" ">error.log

caterror.log

#nothing

Now, you’ll wait like a real cat and run cat error.log every 5-6 mins for few times. With a normal website with visitors, if error has to arrive, it should show up. For WordPress, errors are due to wp-cron and for OwnCloud it is related to APC.

Cloud Computing grown as there was a clear cut demand from the consumer. Most users who cares for quality, actually went mad with the traditional web hosts. The crap graphics of cPanel, increasing bill for Virtual Private Server and Dedicated server, “your problem you will solve” type of mentality, usage of worst possible hardwares, all […]