Sep 13, 2025

How to Setup Nginx with PHP on Linux

To install Nginx and PHP on your server, follow the instructions based on your operating system:

On Ubuntu/Debian:

Step 1: Install Nginx

  1. Update package index:
  1. Install Nginx:
  1. Start Nginx service:
  1. Enable Nginx to start on boot:
  1. Check Nginx status:

Step 2: Install PHP

  1. Install PHP:
  1. Check PHP version:

On CentOS/RHEL:

Step 1: Install Nginx

  1. Install Nginx:
  1. Start Nginx service:

Step 2: Install PHP

  1. Install PHP:
  1. Start PHP-FPM service:

Configure Nginx to Use PHP

  1. Edit Nginx configuration for your site (e.g., /etc/nginx/sites-available/default):
  1. Update the location:
    Update the location ~ \.php$ block with the correct PHP-FPM socket (or port):
  1. Test the Nginx configuration:
  1. Reload Nginx to apply the changes:

Verify PHP is Working

  • Create a phpinfo() test file to verify PHP is working:
  • Add the following PHP code:
  • Visit the test file in your browser:
Avatar photo
Md. Azaj Ikbal

Red Hat | CentOS | Ubuntu | Shell Scripting | Server Hardening | Server Clustering | Virtualization | VMware | vSphere | vCenter | ESXi | vMotion | SAN Storage | vSAN | VMware Data Center | Windows Server Domain Controller | DNS & DNS Sec | RADIUS | Cacti | Observium | GrayLog | Veeam Backup | Huawei Networking | Cisco Networking | IP Telephony | Server Admin | Network Engineer