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.
Nothing mystical. Just a Ubuntu server with a non root user that can run sudo and a little patience.
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 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.
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
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
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.
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.
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.