How Can We Help?
< All Docs
Print

How to install Lighttpd, MariaDB and PHP on Ubuntu 20.04

Table of Content
How to install lighttpd, php and mysql on ubuntu

Most Linux fans, if not all, have heard of web servers. This is especially true for those who want to work on web-based projects or careers. Because the Linux community has so many web servers to choose from, you might feel like you need to flip a coin or roll a dice to find the one that "might" meet your web-based needs.

Lighttpd is best known as a web server that is compatible, very flexible, fast, and safe. So, it is set up to work well in any operating system environment.

Also, this web server is very light, so it only needs a small amount of resources to run and do things like handle AJAX applications. This web server is open source and licenced by BSD. It works perfectly on UNIX-like systems.

Prerequesties:

  • Super user( root ) or any normal user with SUDO privileges.
  • Apt repository configured on your Ubuntu 20 server

1. Installing Lighttpd

Always make sure your operating system is up-to-date as the first step.

# apt update 

Now install the lighttpd by executing the below command

# apt install lighttpd 

Start the lighttpd services.

# systemctl start lighttpd 

you need to open the following ports to enable access to Lighttpd.

# ufw allow 80
# ufw allow 443

Use your machine's IP address or localhost in your web browser to make sure that Lighttpd can serve web pages on your Ubuntu system.

# server ip 

2. Install MySQL or Mariadb

MariaDB can be used in place of MySQL without any changes. It is being made by people who used to work on the MySQL team and are worried that Oracle will make MySQL a closed-source product. To install MariaDB on Ubuntu 20.04, type the following command.

#  apt install mariadb-server mariadb-client 

After successfully installing Mariadb or Mysql, we need to start the service and setup mysql server.

# systemctl start mariadb
# mysql_secure_instalation

3. Install PHP on Ubuntu

Lighttpd and PHP, which is a programming language, go well together. Since PHP is the core of most web applications, we need to set up support for it in Lighttpd.

So, you need to install the following PHP-related packages on your Ubuntu OS before you can use PHP.

# apt install php7.4, php7.4-fpm php7.4-mysql php7.4-cli php7.4-curl php7.4-xml 

For Lighttpd and PHP to talk to each other, we need to open some configuration files and make a few changes.

# vi /etc/php/7.4/fpm/pool.d/www.conf 

Comment out the initial listen = /run/php/php7.4-fpm.sock value and set it to listen = server-ip:9000 as shown.

Updated file content:

36 ;listen = /run/php/php7.4-fpm.sock

37 listen = 103.150.136.96:9000

Please note that, 36 and 37 are the line numbers, You have no need to mention them in file

And now make some changes in lighttpd configuration file

# vi /etc/lighttpd/conf-available/15-fastcgi-php.conf 

# -*- depends: fastcgi -*-
# /usr/share/doc/lighttpd/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
((
# "bin-path" => "/usr/bin/php-cgi", Comment out these two lines
# "socket" => "/var/run/lighttpd/php.socket",
"host" => "103.150.136.96", # here put your server ip or localhost ip
"port" => "9000", # enter here the port number
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
))
)

Now Enable the following modules responsible for the communication between Lighttpd and PHP

# lighty-enable-mod fastcgi
# lighty-enable-mod fastcgi-php

And now restart the php and lighttpd service

# systemctl restart php lighttpd 

And now, to test the installation of php, create a file in /var/www/html named as info.php and fill it with the below content.

# vi /var/www/html/info.php 

Content:

<?php phpinfo(); ?>

And now go to your browser, and hit the server-ip/info.php and you should be seeing the below page as a successfully php installed server.

Table of Contents