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 Distributions»Debian»How to Install Apache with PHP-FPM on Debian 10

    How to Install Apache with PHP-FPM on Debian 10

    RahulBy RahulNovember 26, 20193 Mins ReadUpdated:December 4, 2019

    The FastCGI Process Manager (FPM) is an alternative to the FastCGI configuration with multiple enhancements. This is useful for high load websites. This tutorial will help you with the installation and configuration of PHP-FPM with Apache on your Debian 10 (Buster) Linux system.

    Prerequsities

    You must have SSH access to the Debian 10 system with Sudo privileges.

    Apache Installation

    Apache packages are available under default Apt repositories on all Debian systems. You can update the Apt cache and install Apache web server packages using the following command:

    sudo apt update 
    sudo apt install apache2 
    

    PHP Installation

    For the PHP installation we recommend to use Ondřej Surý‘s PPA, which provides latest PHP versions for Debian systems. Add this PPA to your Debian system using the following commands:

    wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
    sudo echo "deb https://packages.sury.org/php/ buster main" | tee /etc/apt/sources.list.d/php.list
    

    After that, install the required PHP version. You can simply execute the following commands for the default PHP version installation with PHP-FPM packages.

    apt update
    sudo apt install php php-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 the 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 Tue 2019-12-03 10:01:54 UTC; 24min ago
         Docs: man:php-fpm7.3(8)
     Main PID: 9883 (php-fpm7.3)
       Status: "Processes active: 0, idle: 2, Requests: 3, slow: 0, Traffic: 0req/sec"
        Tasks: 3 (limit: 3587)
       Memory: 14.2M
       CGroup: /system.slice/php7.3-fpm.service
               ├─9883 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
               ├─9884 php-fpm: pool www
               └─9885 php-fpm: pool www
    
    Dec 03 10:01:54 tecadmin-debian10 systemd[1]: Starting The PHP 7.3 FastCGI Process Manager...
    Dec 03 10:01:54 tecadmin-debian10 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 the Apache server.

    sudo a2enmod alias proxy 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 a 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
    <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:/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.

    http://localhost/info.php
    

    PHP FPM on Debian 10

    Conclusion

    You have successfully configured an Apache with PHP-FPM on your Debian 10 (Buster) Linux. You can now host a website from your server.

    Apache Debian 10 php-fpm
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To Install LAMP (Apache, MySQL, PHP) on Debian 10
    Next Article How to Install Nginx with PHP-FPM on Debian 10

    Related Posts

    How to Install Apache ActiveMQ on Ubuntu 22.04

    3 Mins Read

    How to Find Django Install Location in Linux

    Updated:April 27, 20221 Min Read

    (Resolved) – ReactJS 404 Error on Page Reload

    2 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    13 Best Linux Terminal Emulators and Bash Editors

    8 Mins Read

    3 Comments

    1. rh on August 29, 2021 8:09 pm

      worked perfecly for me on an arm64 graviton amazon server 🙂

      Reply
    2. bob on October 28, 2020 6:04 pm

      This procedure worked for me on a local 386 Debian-10 a2 server. I suggest that you add an example html-php file requiring it be saved with extension *.php. I was incorrectly using file index.html which returns only html code but doesn’t call internal php code.

      Reply
    3. Minh Tú on August 21, 2020 6:05 am

      Thank you so much. Best Regart

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • 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
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.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.