Title: Step-by-Step Guide to Configuring Nginx and PHP-FPM on Ubuntu
Author: Immanuel Raj
Published: January 17, 2024
Last modified: February 15, 2025

---

![step by step guide to configuring nginx and php fpm on ubuntu](https://immanuelraj.
dev/wp-content/uploads/2024/01/step-by-step-guide-to-configuring-nginx-and-php-fpm-
on-ubuntu.avif)

# Step-by-Step Guide to Configuring Nginx and PHP-FPM on Ubuntu

[January 17, 2024](https://immanuelraj.dev/nginx-and-php-fpm-setup/)

—

by

[Immanuel Raj](https://immanuelraj.dev/author/iamimmanuelraj/)

in [Uncategorized](https://immanuelraj.dev/category/uncategorized/)

Read Time

1–2 minutes

In this blog we will see how to properly configure Nginx and php-fpm in a linux (
ubuntu) machine or server.

---

**Pre-Requisites:**

    ```wp-block-code
    Linux (Ubuntu) Server.

    Php.

    Nginx.
    ```

Considering that the linux server is already setup and running with ubuntu, lets
get started with the Nginx and php fpm setup.

---

## Installing Nginx.

You can follow [**_THIS_**](https://nginx.org/en/docs/install.html) link and install
Nginx

## Installing PHP

You can follow [**_THIS_**](https://www.php.net/manual/en/install.unix.debian.php)
link and install PHP.

---

### Basic Nginx (V 1.24) Setup for PHP-FPM (8.4)

    ```wp-block-code
    server {  ...  # Add index.php nginx config  index ... index.php ...;  # Pass PHP scripts on Nginx to FastCGI (PHP-FPM) server  location ~ \.php$ {    include fastcgi_params;    # Nginx php-fpm sock config:    fastcgi_pass unix:/run/php/php8.1-fpm.sock;    fastcgi_index  index.php;    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;  }  # deny access to Apache .htaccess on Nginx with PHP,   # if Apache and Nginx document roots concur  location ~ /\.ht {    deny all;  }...} # End of PHP FPM Nginx config example
    ```

_This is just a example config snippet and not the whole/actual configuration._

Depending on your system’s default configuration you may need to change `fastcgi_pass`
parameter.

It can be of the following variation

    ```wp-block-code
    fastcgi_pass 127.0.0.1:9000; # For locally passing the php files

    fastcgi_pass unix:/run/php/php8.1-fpm.sock; # For using unix socket to pass the file
    ```

_unix socket location may vary per system (can be /run/php/php8.1-fpm.sock /var/
run/php/php8.1-fpm.sock). This doesnt make a difference if the locations are symlinked
or mounted. If incase it is not done then this needed to be noted carefully._

_Another way is to change the phpfpm pool.d/www.conf file to use local host instead
of unix socket_.

Finally restart the php and nginx services.

#### **Here are some articles and blogs and links that will help you to learn and know more about these.**

    ```wp-block-code
    https://nginx.org/en/docs/beginners_guide.html

    https://nginx.org/en/docs/switches.html

    https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

    https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/

    https://easyengine.io/wordpress-nginx/why-nginx/

    https://serverguy.com/comparison/apache-vs-nginx/

    http://nginx.org/en/docs/http/ngx_http_core_module.html

    https://www.journaldev.com/26342/nginx-location-directive

    https://nginx.org/en/docs/beginners_guide.html

    https://nginx.org/en/docs/switches.html

    https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

    https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/

    https://easyengine.io/wordpress-nginx/why-nginx/

    https://serverguy.com/comparison/apache-vs-nginx/

    http://nginx.org/en/docs/http/ngx_http_core_module.html

    https://www.journaldev.com/26342/nginx-location-directive
    ```

[linux](https://immanuelraj.dev/tags/linux/) [nginx](https://immanuelraj.dev/tags/nginx/)
[php](https://immanuelraj.dev/tags/php/) [php-fpm](https://immanuelraj.dev/tags/php-fpm/)
[selfhosting](https://immanuelraj.dev/tags/selfhosting/) [server](https://immanuelraj.dev/tags/server/)
[ubuntu](https://immanuelraj.dev/tags/ubuntu/) [web](https://immanuelraj.dev/tags/web/)
[web-server](https://immanuelraj.dev/tags/web-server/)

[Previous:  Oh-My-ZSH](https://immanuelraj.dev/oh-my-zsh/)

[Next:  OpenResty SSL Setup: Install and Secure Site withNginx with Let’s Encrypt on Ubuntu](https://immanuelraj.dev/nginx-openresty-ssl-setup-ubuntu/)

![Immanuel Raj Avatar](https://secure.gravatar.com/avatar/88db6e1fa27cf854075acbaa156189ace30cf3701b2d8640cd774280ead1d4d3?
s=80&d=mm&r=g)

## About the author

Software Developer & Technology Consultant

---

## Popular Categories

 * [Bible](https://immanuelraj.dev/category/bible/) (1)
 * [Cloudflare](https://immanuelraj.dev/category/cloudflare/) (1)
 * [Databases](https://immanuelraj.dev/category/databases/) (1)
 * [Docker](https://immanuelraj.dev/category/docker/) (1)
 * [Email](https://immanuelraj.dev/category/email/) (1)
 * [ERPNext](https://immanuelraj.dev/category/erpnext/) (3)
 * [Frappe](https://immanuelraj.dev/category/frappe/) (2)
 * [Github Actins](https://immanuelraj.dev/category/github-actins/) (1)
 * [God](https://immanuelraj.dev/category/god/) (1)
 * [Google Cloud](https://immanuelraj.dev/category/gcp/) (1)
 * [Hosting](https://immanuelraj.dev/category/hosting/) (2)
 * [Life](https://immanuelraj.dev/category/life/) (1)
 * [Linux](https://immanuelraj.dev/category/linux/) (13)
 * [ML](https://immanuelraj.dev/category/ml/) (1)
 * [Networking](https://immanuelraj.dev/category/networking/) (2)
 * [Security](https://immanuelraj.dev/category/security/) (2)
 * [Self Hosting](https://immanuelraj.dev/category/self-hosting/) (7)
 * [SSL](https://immanuelraj.dev/category/ssl/) (3)
 * [Terminal](https://immanuelraj.dev/category/terminal/) (1)
 * [Tools](https://immanuelraj.dev/category/tools/) (2)
 * [Uncategorized](https://immanuelraj.dev/category/uncategorized/) (8)
 * [Web](https://immanuelraj.dev/category/web/) (2)
 * [WordPress](https://immanuelraj.dev/category/wordpress/) (1)

---

## Useful Links

Links I found useful and wanted to share.

 * [Sponsor Me](https://github.com/sponsors/iamimmanuelraj)

---

## Search the website

Search