Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Tutorials»How to Install Apache/PHP-FPM on Ubuntu 16.04 LTS

    How to Install Apache/PHP-FPM on Ubuntu 16.04 LTS

    RahulBy RahulFebruary 18, 20183 Mins ReadUpdated:November 20, 2019

    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 16.04 system. In this tutorial, we are using PHP 7.2 and configure with Apache using PHP-FPM and FastCGI.

    • 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

    Install Apache web server from the official repository. Launch terminal on your system or login with ssh to remote systems. Execute the following commands to install the latest available version of Apache web server and FastCGI module.

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

    PHP Installation

    For the installation of PHP versions, we use the PPA maintained here. Use the below couple of commands to add the PPA to your system.

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

    And install PHP 7.2 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.2 php7.2-fpm
    
    Note:- When you are using PHP-FPM. All the PHP modules configurations are residing under /etc/php/7.2/fpm directory. You can read more about enable/disable PHP modules.

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

    sudo systemctl status php7.2-fpm
    
    ● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
       Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabl
       Active: active (running) since Wed 2018-02-21 10:13:28 UTC; 17s ago
         Docs: man:php-fpm7.2(8)
     Main PID: 27506 (php-fpm7.2)
       Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
       CGroup: /system.slice/php7.2-fpm.service
               ├─27506 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
               ├─27509 php-fpm: pool www
               └─27510 php-fpm: pool www
    
    Feb 21 10:13:28 tecadmin systemd[1]: Starting The PHP 7.2 FastCGI Process Manager...
    Feb 21 10:13:28 tecadmin systemd[1]: Started The PHP 7.2 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.

    a2enmod actions fastcgi 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.

    Apache
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    <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.2-fpm.sock|fcgi://localhost/"
     
            # Else we can just use a tcp socket:
            #SetHandler "proxy:fcgi://127.0.0.1:9000"
        </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
    

    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
    

    Open a web browser access the info.php using server IP address (for default VirtualHost) for your configured domain in Apache VirtualHost.

    Apache FastCGI PHP php-fpm
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Multiple PHP Version with Apache on Ubuntu
    Next Article How to Setup Selenium with ChromeDriver on Ubuntu 20.04 & 18.04

    Related Posts

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:May 9, 20223 Mins Read

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How To Enable SSH Server on Ubuntu 22.04

    Updated:April 22, 20222 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    How To Disable HTTP Methods in Apache

    Updated:December 31, 20212 Mins Read

    5 Comments

    1. Herbert on July 23, 2018 2:39 pm

      Thks bro it works well for me

      Reply
    2. JKK on April 30, 2018 1:33 pm

      Smell something funny with this line:

      SetHandler “proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/”

      `php5.6-fpm.sock`???

      Is this copied from an old example or something?

      Reply
      • Rahul K. on May 1, 2018 5:11 am

        Thanks JKK, I have corrected the issue.

        Reply
    3. Kamal on February 26, 2018 4:35 pm

      How can I install php 5.4 on my Ubuntu 16.04 system with Apache?

      Reply
      • Anders on May 5, 2019 1:37 am

        apt install php

        Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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