- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Installing and Configuring PHP-FPM on Ubuntu Linux
Before we can start building our world-changing website or application on LEMP, we have to lay the foundation for the stack. In this hands-on lab, we will walk through installing and configuring PHP-FPM on Ubuntu Linux. When the lab is complete, we will have a configured PHP-FPM installation on Ubuntu Linux.

Lab Info
Table of Contents
-
Challenge
Validate That the NGINX Server Is Installed, Enabled and Running
Become
root
:sudo su -
Check the status of the
nginx
service:systemctl status nginx
The service should be
enabled
andrunning
.Verify that we can load the default NGINX web page using
curl
:By Public IP:
curl http://`cat /tmp/public_ip.txt`
By Public DNS:
curl http://`cat /tmp/public_dns.txt`
-
Challenge
Install PHP-FPM
Install PHP-FPM using
apt-get
:apt-get -y install php-fpm
Validate that the
php7.2-fpm
service is running, usingsystemctl
:systemctl status php7.2-fpm.service
The service should be
enabled
andrunning
. -
Challenge
Test Access PHP Pages Using NGINX
We have two pre-configured PHP pages in
/usr/share/nginx/html/
. Let's take a look at them:more /usr/share/nginx/html/*.php
Now, try accessing the PHP files via NGINX:
curl http://`cat /tmp/public_dns.txt`/info.php
curl http://`cat /tmp/public_dns.txt`/hello.php
We can see the contents, but the PHP code is not being executed. Try accessing the PHP files at http://PUBLIC_DNS/info.php and http://PUBLIC_DNS/hello.php with a web browser.
-
Challenge
Configure NGINX to use php-fpm to Process PHP Pages
We need to add a configuration block to the
/etc/nginx/conf.d/default.conf
file, so that NGINX usesphp-fpm
to process PHP pages:vi /etc/nginx/conf.d/default.conf
After the
location /
block, add the following:location ~ \.php$ { fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; }
-
Challenge
Validate and Activate PHP Configuration
Before we reload NGINX, we need to validate the configuration:
nginx -t
Once everything checks out, reload the configuration:
systemctl reload nginx
Make sure NGINX is running:
systemctl status nginx
-
Challenge
Test Access PHP Pages Using NGINX with PHP-FPM
Now, let's try accessing the PHP files via NGINX:
curl http://`cat /tmp/public_dns.txt`/info.php
curl http://`cat /tmp/public_dns.txt`/hello.php
Now the PHP code is not being executed. You can try accessing the PHP files at http://PUBLIC_DNS/info.php and http://PUBLIC_DNS/hello.php with your web browser.
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.