• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Ubuntu Nginx PHP5-FPM UNIX Socket Configuration

By Abhishek Ghosh March 17, 2015 7:08 pm Updated on March 17, 2015

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.

 

Errors Related To Wrong Ubuntu Nginx PHP5-FPM UNIX Socket Configuration

 

Normally, UNIX Socket is preferred over TCP/IP for faster end result. Errors can be like :

connect() to unix:/var/run/php5-fpm.sock failed
upstream timed out (110: Connection timed out)
connect() to unix:/tmp/php5-fpm.sock failed ( : No such file or directory)

Advertisement

---

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 :

Vim
1
2
3
4
5
6
7
8
PHP 5.5.9-1ubuntu4.6 (cli) (built: Feb 13 2015 19:17:11)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with XCache v3.1.0, Copyright (c) 2005-2013, by mOo
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with XCache Optimizer v3.1.0, Copyright (c) 2005-2013, by mOo
    with XCache Cacher v3.1.0, Copyright (c) 2005-2013, by mOo
    with XCache Coverager v3.1.0, Copyright (c) 2005-2013, by mOo

This is PHP 5.5.9 from Ubuntu’s “natural” repo. Normally, we edit this PHP-FPM pool config file :

Vim
1
nano /etc/php5/fpm/pool.d/www.conf

and add / make this active socket active :

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

instead of TCP/IP port :

Vim
1
listen = 127.0.0.1:9000

In the Nginx configuration file, we pass in this way :

Vim
1
fastcgi_pass unix:/var/run/php5-fpm.sock;

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.

Ubuntu Nginx PHP5-FPM UNIX Socket Configuration

 

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
upstream php5-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/write this stuff
upstream php5-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 -g www-data nginx
usermod -a -G www-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
# if mysql 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
# if mysql 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
cat error.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
cat error.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.

Nginx public directory is usually here :

/usr/share/nginx/html/

wp-cron.php and wp-config.php will be here :

/usr/share/nginx/html/wp-cron.php

You’ll disable this PHP chron from wp-config.php file :

Vim
1
2
3
4
5
nano /usr/share/nginx/html/wp-config.php
# add this
define('DISABLE_WP_CRON', true);
# before
/* That's all, stop editing! Happy blogging. */

and add a real cron :

Vim
1
2
crontab -e
*/15 * * * * cd /usr/share/nginx/html/; php /usr/share/nginx/html/wp-cron.php > /dev/null 2>&1

This is PHP-CLI setup for running that wp-cron.php every 15 minutes. It possibly has to do something with W3 Total Cache. You can decrease the time to 1 or 2 minute depending on load average and top.

For OwnCloud, you will need another thing :

Vim
1
2
3
4
5
cd /etc/php5/fpm/conf.d/
nano 20-apcu.ini
# edit
;extension=apcu.so
apc.enabled=0

Obviously, restart the services – service php5-fpm restart && service nginx restart.

Tagged With php5-cgi unix socket , php5-fpm upstream error , ubuntu php fpm config

This Article Has Been Shared 370 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Ubuntu Nginx PHP5-FPM UNIX Socket Configuration

  • Cloud Computing 3D Rendering And Scope In Film Industry

    Cloud Computing 3D Rendering Has Definite Scope in Film Industry which might alarm the Stars of tomorrow and relieve the Producers investing in the Films.

  • SaaS : Everything You Wanted To Know

    SaaS or Software as a Service is designed by the architecture to be used by the consumer. SaaS is the model oCloud which the general users mostly know to exist.

  • Cloud Computing Grown as There Was Real Demand From The Customers

    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 […]

  • Cloud Database : Migrating From Relational Database Model to NoSQL

    Cloud Database is more and being in use now than before. The question of migrating from relational database model to NoSQL Database is becoming more important.

  • Mobile Phone Camera Photography : Get The Best Result

    Mobile Phone Camera Photography is becoming an important matter to seriously consider for Digital Photography. We always take a Mobile Phone with us.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (21K Followers)
  • Twitter (5.3k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is Standard Software February 28, 2021
  • WordPress Link to text Fragment February 27, 2021
  • How to Protect IP Cameras From Hackers February 25, 2021
  • 6 Sectors That Have Undergone Revamps in Digital Landscape February 24, 2021
  • What You Can Control with a Smartwatch and ESP32 February 23, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Ubuntu Nginx PHP5-FPM UNIX Socket Configuration," in The Customize Windows, March 17, 2015, March 1, 2021, https://thecustomizewindows.com/2015/03/ubuntu-nginx-php5-fpm-unix-socket-configuration/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy