Install & Setup PHP and Nginx on Ubuntu Linux with FPM |Video upload date:  · Duration: PT11M16S  · Language: EN

Step by step guide to install PHP and Nginx on Ubuntu and configure PHP FPM for fastcgi processing and testing.

So you want a fast PHP site on Ubuntu without hand waving or pretending systemctl is a magic spell. This guide gets Nginx and PHP FPM installed and talking to each other so your app can do PHP things and not crash the server when traffic shows up. Expect commands to run and sanity checks to pass.

What you need before we start

Nothing mystical. Just a Ubuntu server with a non root user that can run sudo and a little patience.

  • Ubuntu server with SSH access
  • Sudo capable user
  • Basic familiarity with editing files under /etc

Update packages and avoid drama

Always start by updating the package list and applying upgrades. This saves you from the dependency circus later.

sudo apt update && sudo apt upgrade -y

Install Nginx and PHP FPM

Install the web server and the PHP FastCGI process manager in one go. Add the mysql extension if your app uses it.

sudo apt install nginx php-fpm php-mysql -y

PHP FPM runs PHP outside of the web server process. That means better performance and fewer mysterious crashes when someone runs a heavy script.

Configure Nginx to pass PHP to FPM

Edit your server block under /etc/nginx/sites-available. If you use the default file then modify /etc/nginx/sites-available/default. You want Nginx to hand off PHP files to PHP FPM.

Key points to change or verify in the server block

  • Root points to your web root like /var/www/html
  • Ensure index contains index.php so PHP files are served
  • Make Nginx pass PHP requests to PHP FPM using either the local unix socket path or a TCP address if using a remote process manager

Use the unix socket path under /run if PHP FPM is on the same machine for a slight speed gain. If you must run FPM remotely then use the FPM host and port, for example IP 127.0.0.1 and port 9000. After editing save the file and then check Nginx syntax and reload.

sudo nginx -t
sudo systemctl reload nginx

Quick test with a phpinfo page

Create a tiny PHP file in your web root to confirm the pipeline works. Remove the file after confirming so you are not broadcasting your PHP setup to random strangers.

sudo tee /var/www/html/info.php > /dev/null <<'PHP'
<?php phpinfo() ?>
PHP

Then open the page in a browser at your server IP or domain and look for the PHP info output. If you see it you win. Delete the file when done.

Restart services and verify

If you changed FPM pools or swapped versions restart the services. You can restart both Nginx and PHP FPM or target the specific version installed.

sudo systemctl restart php*-fpm nginx
sudo systemctl status nginx
sudo systemctl status php*-fpm

Check the status output for active running. If something failed check the journal or the error logs for clues.

Troubleshooting cheatsheet

  • 500 errors after configuration change Check Nginx error log at /var/log/nginx/error.log and the FPM pool log
  • Permission issues Make sure the web root is readable by the www data user or adjust the socket permissions
  • FPM not listening Confirm the socket file exists under /run or that FPM is bound to the correct IP and port

Final notes and sensible defaults

Prefer unix sockets for local performance and use TCP when you separate the process manager over the network. Keep the phpinfo page offline after testing. Now the server is ready for deployment and you can move on to things like SSL hardening and process supervision which are much more fun when the basics actually work.

If you enjoy reading man pages show yourself mercy and read the PHP FPM pool configuration for tuning values to match your app and server memory. Otherwise hope for the best and monitor your metrics like a responsible adult.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.