LAMP is an acronym that stands for Linux, Apache, Mysql, and PHP. It is called a LAMP stack because these components together provide a set of software that deliver numerous web applications. Most developers choose LAMP since it offers a free and open-source back-end developing approach as well as ease of deployment and customization. With LAMP Stack you can build, host and manage web-based content. When used on Windows operating system, it is known as WAMP while on Macintosh it is called MAMP.In this guide, we will dig deep into the LAMP stack components, the installation process of LAMP, and how to use these elements altogether.

Layers of LAMP Stack

LAMP components are arranged into layers and support each other to make up the software stack. Below are the layers on LAMP Stack;

  • Linux

This is the operating system that is the first or base layer. Linux is mostly chosen since it is open-source, easy to configure, and has high flexibility. All the other components run on top of this layer.

  • Apache

This is the second layer of the LAMP Stack. It consists of the Apache Web server. Just like other web servers, Apache processes clients’ requests using HTTP and transmits data over the internet.

  • Mysql database

The third layer of the LAMP stack is the MySql database. It is an open-source database system that stores details of applications where this information can be queried using SQL language.

  • PHP

PHP is the fourth and final layer that sits on top of the other components. Hypertext Preprocessor(PHP) is a scripting language used for creating dynamic web pages. Alternatively, Perl and Python are programming languages that can be used instead of PHP in the LAMP Stack.

How do LAMP stack components Interoperate?

Linux, Apache, MySQL, and APHP interoperate in different ways. Everything starts when a client makes requests to the user’s browser. Apache webserver receives these requests and examines whether it is a PHP file then passes it to PHP. Then PHP loads the file and executes the code while communicating with MySQL to fetch any required data. With the code in the file and data from the MySQL database, PHP creates an HTML that the client needs to load a web page. Notably, all these operations are made possible since these components are running on Linux operating system.

Installation of LAMP Stack on Solus Linux

For this process to be successful, it is important to have Solus(a Linux distribution) operating system installed on your computer. Let’s proceed with installing LAMP on Solus.

Step 1: Upgrade Solus Repository

A key point to note is that you have to update your system’s repository before you install LAMP Stack.

sudo eopkg upgrade

If asked whether you want to continue with the process of updating the repository, type YES.

Step 2: Install Apache Web Server

Install Apache also known as httpd on Solus Linux

sudo eopkg install httpd


Keep in mind that it is important to change the default directory of httpd.

ls /usr/share/defaults/httpd/

Inside the /etc create an httpd directory.

sudo mkdir -p /etc/httpd/conf.d/

Let’s start the httpd service using this command.

sudo systemctl restart httpd

We can go ahead and create a HTML file using the below commands. Vim, a text editor will open. Press letter i on your keyboard to edit the file. Type a text you would want on the HTML file.

In this case, I will type ‘Welcome to Httpd‘. After you are done, press the ESC button followed by:wq then Enter button to save the file and exit from Vim.

sudo vim /var/www/index.html

To view the HTML File we have just created, open your browser and type the word localhost or your computer’s IP address then hit the enter button. A webpage will be displayed as shown below with the text we typed on Vim.

Once the installation and configurations are done, check whether Apache Web Server has been installed on Solus.

systemctl status httpd

Here is the output showing that Apache is up and running.

$ systemctl status httpd
● httpd.service - Apache Web Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2022-04-26 15:24:01 EAT; 32min ago
Main PID: 2879 (httpd)
Tasks: 109 (limit: 4647)
Memory: 7.4M
CPU: 98ms
CGroup: /system.slice/httpd.service
├─2879 /usr/sbin/httpd -k start -DFOREGROUND
├─2884 /usr/sbin/httpd -k start -DFOREGROUND
├─2885 /usr/sbin/httpd -k start -DFOREGROUND
├─2886 /usr/sbin/httpd -k start -DFOREGROUND
└─3238 /usr/sbin/httpd -k start -DFOREGROUND

Step 3: Install MySQL/MariaDB Database

Let’s install the third layer of LAMP on Solus. In this case, we will install MariaDB Server (which serves the same purpose as the MySql server) using the following code:

sudo eopkg install mariadb-server

Start MariaDB Service

sudo systemctl start mariadb.service

Enable MariaDB using these commands

sudo systemctl enable mariadb.service

Here is the output after enabling the MariaDB service

$ sudo systemctl enable mariadb.service
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

You can check the status of the MariaDB Service

systemctl status mariadb.service

Output showing MariaDB is active.

● mariadb.service - MariaDB 10.6.7 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-04-26 20:17:25 EAT; 3min 31s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 6225 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 4647)
     Memory: 61.0M
        CPU: 443ms
     CGroup: /system.slice/mariadb.service
             └─6225 /usr/sbin/mariadbd

In the last part of the installation, we will implement security in our MariaDB account

sudo mysql_secure_installation

You will be prompted with several questions after the command above is executed. Press Enter button to maintain the default settings. Note that you can change your current password by pressing Y and creating a new password.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..

Step 4: Install PHP and extensions

PHP which is our topmost layer in LAMP will be installed using the following command on Solus.

sudo eopkg install php -y

Configure PHP-FPM by changing username and group for www default pool

$ sudo vim /etc/php/php-fpm.d/www.conf
user = httpd
group = httpd

Start PHP-fpm service; which is an alternative in regards to webserver loading of data.

sudo systemctl start php-fpm

Create a configuration file to make PHP efficient.

sudo vim /etc/httpd/conf.d/php.conf

Vim text editor will open. Paste these commands.

LoadModule proxy_module lib64/httpd/mod_proxy.so
LoadModule proxy_fcgi_module lib64/httpd/mod_proxy_fcgi.so
< FilesMatch .php$> 
SetHandler " proxy:fcgi://127.0.0.1:9000" 
< /FilesMatch> 
< IfModule dir_module> 
DirectoryIndex index.php index.html
< /IfModule> 

Save the file and exit using ESC followed by:wq then hit the enter button.

Enable PHP-FPM

$ sudo systemctl enable --now php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

To check the status of the PHP-FMP, Type or copy-paste this:

systemctl status php-fpm

Output showing PHP-fpm is active.

● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-04-26 23:30:09 EAT; 13min ago
   Main PID: 5431 (php-fpm)
     Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 4647)
     Memory: 17.0M
        CPU: 123ms

Create a PHP sample file with this command:

sudo vim /var/www/phpinfo.php

On Vim, paste this code:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?>

Save the file by pressing ESC followed by:wq and hit the enter button.

Still, on the terminal, restart PHP-fpm then httpd services.

sudo systemctl restart php-fpm
sudo systemctl restart httpd

Go to your browser, and search for http://localhost/phpinfo.php or <serverip>/phpinfo.php.The results for the phpinfo.php file we have created will be displayed as shown below.

Step 5: Install phpMyAdmin

To manage your database, install phpMyAdmin. Its file is found on the phpMyAdmin website.

Download the phpMyAdmin file from Terminal.

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz

Extract the downloaded file.

tar -xvf phpMyAdmin-latest-all-languages.tar.gz

Move the file to the/var/www directory.

sudo mv phpMyAdmin-*/ /var/www/phpMyAdmin

Set user and group permissions.

sudo chown -R httpd:httpd /var/www/phpMyAdmin

Restart the httpd server.

systemctl restart httpd

Then go to http://<serverip_or_hostname>/phpMyAdmin on your browser. Your user name is root and MariaDB password or root user password in case you did not change it while installing MariaDB.

Conclusion

LAMP is an essential tool to install on your computer. It portrays outstanding benefits such as being open source and customizable. With LAMP installed, you can easily create and deploy applications. Follow the above steps to successfully install and use LAMP with its components. Additionally, install phpMyAdmin to assist you with creating and managing databases.

More resources;

LEAVE A REPLY

Please enter your comment!
Please enter your name here