Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 30m
Published
Clock icon Jan 10, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. 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 and running.

    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`
    
  2. 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, using systemctl:

    systemctl status php7.2-fpm.service
    

    The service should be enabled and running.

  3. 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.

  4. 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 uses php-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;
     }
    
  5. 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
    
  6. 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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans