How to solve this error "connect() to unix:/var/run/php5-fpm.sock failed"

July 6, 2017 24.4k views
Ubuntu PHP Nginx

i get this error continuously “connect() to unix:/var/run/php5-fpm.sock failed ”.
i tried many possibility but this is not solved.
Please help in urgently to solve this.

1 comment
  • Hi guys..
    I was getting same error on my server and the server was shutting down many many times along the day..

    I solved this upgrading the PHP version. PHP 5x to PHP 7.0.

    Server configuring:
    Ubuntu 14.04
    PHP 5x -> to PHP 7.0

    I followed this tutorial:

    Wish this help you too!

    by Brennen Bearnes
    PHP 7.0 was released on December 3, 2015. It promises substantial speed improvements over previous versions of the language, along with new features like scalar type hinting. This guide explains how to quickly upgrade a PHP 5.x installation on an Ubuntu 14.04 system with Apache or Nginx, using community-provided packages.
8 Answers

Hi @DhavalPadshala

That means PHP-FPM is not running. Start it by running sudo service php5-fpm restart

Thnx for reply @hansen
i do this many time but it is not work. please tell me there is another way to solve this problem

  • @DhavalPadshala

    Then we have to look at the configuration files.

    Your PHP configuration is located in /etc/php/5.6/fpm/pool.d/ - the listen parameter should be /var/run/php5-fpm.sock.

    Are you running Ubuntu 16.04 or 14.04?

Thnx again @hansen
My PHP configuration competed same as you suggest. and actually error will not occurred continuously on website.. it will some time in website . when there was an high traffic on server.

and i am running Ubuntu 14.04

  • @DhavalPadshala

    Okay, that’s a different problem then.

    What’s your definition of “high traffic”? And what are you running on the website?

    Can you post your PHP pool configuration?

I am running an image creating script using php gd.
and error only occurred when high traffic.

My Php pool Configuration file ==>

New link of Pool file ==>!

  • @DhavalPadshala

    You either need to make a queue system or increase the processes in the pool.

    Since I don’t know how much RAM you have available or how consuming the script is, it’s hard to know exactly what to put in, but you can play around with it.
    Remember to sudo service php5-fpm restart after changes.

    I’ve removed all comments besides two lines to make it easier to manage.

    user = www-data
    group = www-data
    listen = /var/run/php5-fpm.sock
    listen.owner = www-data = www-data
    listen.mode = 0660
    pm = dynamic
    ; pm.max_children = (total RAM - RAM used by other process) / (average amount of RAM used by a PHP process)
    pm.max_children = 15
    ; pm.start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 5
    pm.min_spare_servers = 5
    pm.max_spare_servers = 10
    chdir = /

    Another solution would be to generate multiple pools and have Nginx load balance between the pools. There’s upside/downside to both, so it really depends on your script and what the server is doing.

    Have you tested if your script would benefit from using PHP 7 instead of 5 ?
    Again, since I don’t know what your script is doing, I cannot say if it’ll benefit, but almost every script or app I’ve been using will use much less RAM and runs much-much faster with PHP 7.1, so I would highly recommend that you test that.

Thank’s help.
i make change as you say.
i tried Php 7 but it is not perfect for my script. Currenly i am using droplet of this configuration 16gb/8 cpu , 40 gb ssd, 6tb.

And sorry for my bad english @hansen

  • @DhavalPadshala No problem, most of us here are non-English speakers :-)

    With that amount of RAM and CPU, you can probably set the amount of processes to a fairly high level, but do some testing and slowly increase the numbers.

    And you should really look into upgrading your script, so it works with PHP 7, since 5.6 will only be support until the end of 2018:

Have another answer? Share your knowledge.