Software⏱️ 4 min read📅 2026-06-19

How to Fix: 502 Bad Gateway error: How to install php8.1-fpm.sock on ubuntu 18.04

Fixing the 502 Bad Gateway error on Ubuntu 18.04 with php8.1-fpm.sock installation.

Quick Answer: Run the command "sudo systemctl enable php8.1-fpm" to start and enable the php8.1-fpm service, then restart nginx for the changes to take effect.

The Bad Gateway error is caused by an issue with PHP-FPM (FastCGI Process Manager) and its configuration. This error affects users who are trying to run PHP scripts on their server, particularly those using Nginx as their web server.

This error can be frustrating for developers and system administrators because it prevents them from accessing their web applications or running PHP scripts. In this guide, we will walk you through the steps to fix this issue and install php8.1-fpm.sock on Ubuntu 18.04.

💡 Why You Are Getting This Error

  • The root cause of this error is that the php8.1-fpm.sock file is not installed or configured correctly. This file is required for PHP-FPM to communicate with Nginx. When the php8.1-fpm.sock file is missing, Nginx cannot connect to it, resulting in a Bad Gateway error.
  • Another possible cause is that the php-fpm configuration is incorrect. The configuration file may not be pointing to the correct location of the php8.1-fpm.sock file.

🚀 How to Resolve This Issue

Installing and Configuring php8.1-fpm.sock

  1. Step 1: Step 1: Install the php-fpm package using apt-get or aptitude. This will install all the necessary packages, including php8.1-fpm.sock.
  2. Step 2: sudo apt-get install php-fpm
  3. Step 3: Step 2: Create a new file in the /etc/php/7.4/fpm/pool.d/ directory called 'www.conf'. This file will contain the configuration for the php-fpm pool that we want to use.
  4. Step 4: sudo nano /etc/php/7.4/fpm/pool.d/www.conf
  5. Step 5: Step 3: In the www.conf file, add the following lines to configure the php-fpm socket to point to the correct location of the php8.1-fpm.sock file:
  6. Step 6: ; pool name ('www' here) # www.conf

Alternative Fix Method

  1. Step 1: Step 1: Create a symbolic link to the php8.1-fpm.sock file using the ln command.
  2. Step 2: sudo ln -s /var/run/php/php8.1-fpm.sock /etc/php/7.4/fpm/pool.d/
  3. Step 3: Step 2: Restart the php-fpm service to apply the changes.
  4. Step 4: sudo service php-fpm restart

🎯 Final Words

To fix the Bad Gateway error, you need to install and configure php8.1-fpm.sock on your Ubuntu 18.04 system. You can do this by installing the php-fpm package, creating a new configuration file for the php-fpm pool, and configuring the socket to point to the correct location of the php8.1-fpm.sock file. Alternatively, you can create a symbolic link to the php8.1-fpm.sock file and restart the php-fpm service to apply the changes.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions