Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Install Apache with PHP-FPM on Ubuntu 18.04 LTS

    How to Install Apache with PHP-FPM on Ubuntu 18.04 LTS

    By RahulNovember 21, 20193 Mins Read

    PHP FPM (FastCGI Process Manager) is an alternative implementation of PHP FastCGI. It provides some additional features like Adaptive process spawning which is useful for sites. This tutorial will help you to install Apache with PHP-FPM/FastCGI on Ubuntu 18.04 (Bionic) LTS system. In this tutorial, we are using PHP 7.3 and configure with Apache using PHP-FPM and FastCGI.

    Advertisement
    • Install Apache with PHP & FastCGI on CentOS/RHEL

    You can also visit the previous tutorial to configure Apache with multiple PHP versions using PHP-FPM/FastCGI on Ubuntu systems.

    Apache Installation

    Apache packages are available under default repositories. SSH to your Ubuntu 18.04 LTS system with sudo privileges account and install Apache web server from the official repository.

    sudo apt update 
    sudo apt install apache2 libapache2-mod-fcgid
    

    PHP Installation

    For the PHP installation we recommend to use ppa:ondrej/php PPA, which provides latest PHP versions for Ubuntu systems. Use the below couple of commands to add the PPA to your system.

    sudo apt install software-properties-common
    sudo add-apt-repository ppa:ondrej/php
    

    Then install PHP 7.3 the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages.

    apt update
    sudo apt install php7.3 php7.3-fpm
    
    Note:- When you are using PHP-FPM. All the PHP modules configurations are residing under /etc/php/7.3/fpm directory. You can read more about enable/disable PHP modules.

    After installing above packages php7.3-fpm service will automatically be started. You can make sure by typing below command on terminal.

    sudo systemctl status php7.3-fpm
    
    ● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager
       Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2019-11-21 03:36:08 UTC; 36s ago
         Docs: man:php-fpm7.3(8)
     Main PID: 9054 (php-fpm7.3)
       Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
        Tasks: 3 (limit: 4704)
       CGroup: /system.slice/php7.3-fpm.service
               ├─9054 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
               ├─9069 php-fpm: pool www
               └─9070 php-fpm: pool www
    
    Nov 21 03:36:08 tecadmin systemd[1]: Starting The PHP 7.3 FastCGI Process Manager...
    Nov 21 03:36:08 tecadmin systemd[1]: Started The PHP 7.3 FastCGI Process Manager.
    

    Apache Configuration

    Now enable few modules required for the configuration of multiple PHP versions with Apache. These modules are necessary to integrate PHP FPM and FastCGI with Apache server.

    sudo a2enmod actions fcgid alias proxy_fcgi
    

    Let’s configure the Apache VirtualHost to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost.

    sudo vim /etc/apache2/sites-available/000-default.conf
    

    Update the configuration as followings.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/html
     
        <Directory /var/www/html>
            Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
        </Directory>
     
        <FilesMatch \.php$>
            # 2.4.10+ can proxy to unix socket
            SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost"
        </FilesMatch>
     
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    Save your changes to the configuration file and restart Apache to reload the changes.

    sudo systemctl restart apache2.service
    

    Test Setup

    Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it.

    echo "<?php phpinfo(); ?>" > /var/www/html/info.php
    

    Now access the info.php using server IP address (for default VirtualHost) for your configured domain in Apache VirtualHost.

    Apache PHP-FPM Ubuntu 18.04

    Conclusion

    You have successfully configured a Apache with PHP-FPM on your Ubuntu 18.04 (Bionic) LTS. You can now host a website from your server.

    Apache PHP php-fpm Ubuntu 18.04
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Setting Up Permissions in Home Directory on Linux

    How to Install Apache CouchDB on Ubuntu & Debian

    Configuring Apache Userdir on Ubuntu and Debian: A Simplified Guide

    View 5 Comments

    5 Comments

    1. Markus on December 3, 2020 5:47 pm

      Thanks for this. I used it for provisioning my Vagrant and it works without a problem.

      Reply
    2. Serg on October 9, 2020 9:04 am

      How to configure phpmyadmin correctly, I installed it but it doesn’t work.

      Reply
    3. Eugene on February 9, 2020 7:52 pm

      Working OK!
      But only after adding FilesMatch section directly to apache2.conf )))
      Ubuntu 16.04 LTS/PHP 7.4

      Reply
    4. hexacube on January 19, 2020 2:57 am

      Perfectly working

      Reply
    5. Andreas on December 29, 2019 6:03 pm

      This is a great guide, thanks a lot!

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • The Difference Between Git Reset –soft, –mixed, and –hard
    • Understanding the Staging Area in Git’s Workflow
    • Python Function with Parameters, Return and Data Types
    • free Command in Linux (Check Memory Uses)
    • Git Rebase: A Practical Guide
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.