Breaking News
Home / How To / How to install Lighttpd with PHP-FPM and MySQL on Ubuntu 20.04 LTS

How to install Lighttpd with PHP-FPM and MySQL on Ubuntu 20.04 LTS



Lighttpd is an open source web server that focuses on simplicity and high performance. It is a lightweight web server with small and low memory consumption but still retains standard requirements, security and flexibility. The Lighttpd web server is part of the LLMP Stack, which stands for Linux, Lighttpd, MySQL / MariaDB and PHP / PHP-FPM.

In this tutorial we will show you how to install and configure LLMP Stack on the Ubuntu 20.04 server. We will install the Lighttpd web server using the MariaDB database server and PHP-FPM on the latest version of the Ubuntu 20.04 server.

Prerequisites

  • Ubuntu 20.04 server
  • Root privileges
  • Understanding the basics of Ubuntu / Debian Server

What should we do?

  • Installing Lighttpd Web Server
  • Installing and Configuring MariaDB Database Server
  • Installing and Configuring PHP-FPM
  • Setup Lighttpd and PHP-FPM
  • Testing [19659013] Step 1 – Installing Lighttpd [196590toinstallLighttpdwebserveronourUbuntu2004serverTheLighttpdpackagesarebydefaultavailableontheUbunturepositoryupdatingallavailablerepositoriesandinstallingLighttpdusingtheaptcommandbelow

      sudo apt update 
    sudo apt install lighttpd

    When all installation is complete, start Lighttpd service and add it to the system boot.

      systemctl start lighttpd 
    systemctl enable lighttpd

    The lighttpd service is running, check it with the following command.

      systemctl status lighttpd 

    Below is the result you will get.

      Launch Lighttpd Webserver Service

    Then add the HTTP, HTTPS and SSH services to the ufw firewall.

      sudo ufw allow ssh 
    sudo ufw allow http
    sudo ufw allow https

    Activate the ufw firewall service with the command below.

      sudo ufw enable 

    Type & # 39; y & # 39; to enable the ufw firewall, and as a result, you have the firewall enabled on the Ubuntu system.

      ufw firewall open http and https ports

    Now open your browser and enter the server's IP address in the address bar.

    http://10.3.3.40/

    And you will get Lighttpd defaultindex.html page.

     Lighttpd default Index.hmtl

    As a result, Lighttpd web server has been installed on the Ubuntu 20.04 system.

    Step 2 – Install and configure MySQL Server

    In this step, we will install the MySQL database server and set the default root user for MySQL.

    Install MySQL Server using the apt command below.

      sudo apt install mysql server mysql-client 

    When all installation is complete, start the MySQL service and add the one in the system boot.

      systemctl start mysql 
    systemctl enable mysql

    Now check M ySQL service with the command below.

      systemctl status mysql 

    Below is the result you will get.

     Starting MySQL Service

    As a result, the MySQL database server is up and running on the Ubuntu system.

    Then run the "mysql_secure_installation" command below to set the MySQL root password.

      mysql_secure_installation 

    Press the " Enter " button to continue, enter your new MySQL root user password and type & # 39; Y "for all options.

      Press y | Y for Yes, another key for No: 
    Please enter the root password here

    New password:
    Enter new password:

    Delete anonymous users? (Press on y | Y for Yes, another button for No): Y
    Remove remote root login (Press y | Y for Yes, any other button for No): Y
    Delete the test database and get access to it? (Press y | Y for Yes, any other key for No): Y
    Reload authorization tables now? (Press y | Y for Yes, any other key for No): Y

    As a result, the MySQL root password has been configured.

    Then log in to the MySQL shell with the root user as below.

      mysql -u root -p 

    Check ollera now all available users on MySQL with the following question.

      select User, Host from mysql.user; 

    And you will get the list of default users on MySQL Server. Type now & # 39; exit & # 39; to log out of the MySQL shell.

     MySQL Check User

    As a result, the installation and configuration of MySQL Server for the LLMP stack has been completed. [19659058] Step 3 – Install and configure PHP-FPM

    In this step we will install PHP-FPM packages and configure them to work with Lighttpd web server.

    Install PHP-FPM packages to the Ubuntu system using the apt command below.

      sudo apt install php-fpm php-cgi php-mysql 

    The command automatically installs the latest PHP-FPM 7.4.

    When all installation is complete, go to the "/etc/php/7.4/fpm" directory and edit the "php.ini" configuration with the vim editor.

      cd /etc/php/7.4/fpm/ Tue 1919909021 vv php.ini 

    Deselect the following line to enable FastCGI support.

      cgi.fix_pathinfo = 1 

    Save and close.

    Then start the PHP-FPM service and add it to the system boot.

      sy stemctl start php7.4-fpm 
    systemctl enable php7.4-fpm

     Configure PHP-FPM

    Now check the PHP-FPM service with the following command.

      ss - pl | grip php 
    systemctl status php7.4-fpm

    Below is the result you will get.

     Check PHP-FPM Service

    As can be seen, the PHP-FPM service is running on the Ubuntu 20.04 system. And by default it runs under the sock file & # 39; /var/run/php/php7.4-fpm.sock' .ebrit19459045 ???? 19659029 ?? If the installation of PHP-FPM on ubuntu 20.04 has been completed.

    Step 4 – Configure Lighttpd and PHP-FPM

    For this step, we configure Lighttpd with PHP-FPM.

    Now go to the directory & # 39; / etc / lighttpd / conf-available & # 39 ;, you will get some configurations.

      cd / etc / lighttpd / conf-available / 

    Copy the default PHP FastCGI configuration & # 39; 15 -fastcgi-php.conf & # 39; and edit with the vim editor.

      cp 15-fastcgi-php. conf 15-fastcgi-php.conf.orig 
    vim 15-fastcgi-php.conf

    Now you get the default PHP FastCGI configuration as below.

      fastcgi.server + = (".php" => 
    ((
    "bin-path" => "/ usr / bin / php-cgi",
    "socket" => " /var/run/lighttpd/php.socket",ebrit19459021] "Max-procs" => 1,
    "bin-environment" => (
    "PHP_FCGI_CHILDREN" => "4",
    " PHP_FCGI_MAX_REQUESTS "=>" 10000 "
    ),
    " bin-copy-environment "=> (
    " PATH "," SHELL "," USER "
    ),
    " broken- scriptfilename "=>" enable "
    ))
    )

    The default configuration allows Lighttpd to spawn PHP-CGI on itself.

    For Lighttpd to work with PHP-FPM service, replace standard PHP-CGI configuration with the following configuration.

      fastcgi.server + = (".php" => 
    ((
    "socket" => "/ var / run / php / php7.4-fpm.sock",
    "broken -scriptfilename "=>" enable "
    ))
    )

    Save and close.

    Then activate the Lighttpd module fastcgi and fastcgi -php with the command below.

      lighttpd-enable-mod fastcgi 
    lighttpd-enable-mod fastcgi-php

    The command will make a module configuration symlink to & # 39; / etc / lighttpd / conf-enabled & # 39; catalog.

    You can check the directory & # 39; / etc / lighttpd / conf-enabled & # 39; with the following command.

      ls -lah / etc / lighttpd / conf-enabled / 

    And you get both fastcgi and fastcgi-php configurations in the "conf-enabled" directory.

     Enable FastCGI and FastCGI PHP Lighttpd

    Then apply the new installation and configuration, restart the Lighttpd service.

      systemctl restart lighttpd 

    Make sure there is no error.

    And as a result, the configuration of Lighttpd with PHP-FPM has been successfully completed.

    Step 5 – Testing [19659014] To test our LLMP Stack installation, we will create a new PHP information script file in the root directory of the standard document & # 39; / var / www / html & # 39 ;. Tu 1919909029 Go to the directory & # 39; / var / www / html & # 39; and create a new php file & # 39; info.php & # 39; with the vim editor.

      cd / var / www / html / 
    vim info.php

    Paste the following script.

      <? php 
    php info ();
    ?>

    Save and close.

    Then open your browser and enter the server's IP address using the path & # 39; /info.php&#39; as below.

    http: //10.10.10.30/info.php

    And you will get the result as below.

      phpinfo

    As can be seen, you can see all the information about your Lighttpd and PHP-FPM installation.

    And as a result, the installation of LLMP Stack on Ubuntu 20.04 has been successfully completed.


Source link