In computing, a solution stack includes a couple of components combined to offer a complete environment for software development. These components are developed independently but when combined, their benefits qualify them to form a stack. In this guide, we will go through the LAMP stack whose components include Linux, Apache, Mysql, and Php. Note that applications require a LAMP stack during development due to the need for an operating system, a web server, a database management tool, and an efficient programming language. Therefore, the LAMP stack is a well-known software development framework that uses open source components. Its main aim is to help developers to build and deliver web applications.
Components of LAMP Stack
LAMP has four components which we will cover in this section. These are the four layers in LAMP which include:
a) Linux: The Operating system
The backbone of the LAMP stack is Linux. It is a free and open source operating system that has dominated for many years. Due to its popularity and configuration flexibility, Linux is used for running the other LAMP components.
b) Apache: Web Server
This is the second layer that resides on top of the Linux layer. The Apache web server in this layer manages traffic received by a website or web applications. Apache processes clients’ requests and transmits data or information through HTTP(Hypertext Transfer Protocol).
c) MySQL: Database Server
MySQL is a popular database server that supports SQL and relational tables. Notably, being an open-source and cross-platform relational database management system, MySQL qualifies to be part of the LAMP stack. Developers and administrators can query data using SQL language.
PHP is an open source and general-purpose scripting language mainly used for web development. Hypertext Preprocessor(PHP) programming language has the capability of combining LAMP stack elements thus allowing web applications to run effectively.
Uses of Apache, MySQL/MariaDB, PHP
The four components in the LAMP stack provide optimal solutions to developers. They offer a platform for clients and users to access web-based tools, content, and software. Notably, LAMP works when a client makes requests. Then, the Apache web server uses PHP to execute the client’s request and fetches MySQL data. Once Apache has received the granted resources from PHP and MySQL, it presents HTML content to the client. With Linux being the base operating system, developers can create, manage and run web applications.
Installing LAMP Stack on Void Linux
Before installing the LAMP stack, updating the Void Linux repositories is recommended.
sudo xbps-install -Su
Step 1: Install Apache on Void Linux
To install the Apache web server, use the following command.
sudo xbps-install -S apache
Next, link the service file to start the Apache server.
sudo ln -s /etc/sv/apache /var/service/apache
Then start the Apache web server on Void Linux using the command below.
sudo sv start apache
Check the status to ensure that Apache is running.
sudo sv status apache
Apache status output:
$ sudo sv status apache run: apache: (pid 1500) 31s
If you want to make changes, access the Apache configuration file using a text editor such as Nano or Vim.
sudo vim /etc/apache/httpd.conf
For instance, uncomment the line below from the configuration file if you want to use the rewrite module.
LoadModule rewrite_module /usr/libexec/httpd/mod_rewrite.so
To uncomment, delete the # from the line above.
Testing Apache on Void Linux
Note that the default location of the apache folder is in /srv/www/apache. You can have the www directory on your home directory if you use the following command.
ln -s /srv/www/apache ~/www
Allow writes in the www directory so as save files successfully.
sudo usermod -a -G _apache `whoami` sudo chmod -R g+w /srv/www/apache
To ensure that Apache is working, we will create an HTML file.
sudo vim /srv/www/apache/index.html
Inside the HTML file, insert HTML texts. I will use the text below.
<h1>Apache for Technixleo void Linux is Working</h1>
Now, open your web browser and type http://localhost/ to run the HTML file. Expect the output as shown below.
Step 2: Installing MariaDB on Void Linux
MySQL and MariaDB work the same. In this section, we will use the following command to install MariaDB on Void Linux.
sudo xbps-install -S mariadb
Next, link the service file to start the mysqld.
sudo ln -s /etc/sv/mysqld /var/service/mysqld
In the next step, start the mysqld service to enable MariaDB to run on your system.
sudo sv start mysqld
Confirm that the mysqld is working.
sudo sv status mysqld
You should see the following output after checking on the mysqld status.
$ sudo sv status mysqld run: mysqld: (pid 1887) 40s; run: log: (pid 1886) 40s
Use the following command for a secure connection to MariaDB or MySQL.
Answer the questions after the command above is executed. Remember that you can press the Enter button to choose the default settings. Among the prompts, you are given a chance to change the password and set the one you prefer.
$ sudo mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] Enabled successfully! Reloading privilege tables.. ... Success! You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success!
To start creating and managing databases, log in to MariaDB by typing the following:
sudo mysql -u root -p
Confirm that MariaDB is working by creating a database.
CREATE DATABASE technixleodb;
MariaDB [(none)]> CREATE DATABASE technixleodb; Query OK, 1 row affected (0.000 sec)
Logout from MariaDB by typing the word exit.
MariaDB [(none)]> exit Bye
Step 3: Install PHP on Void Linux
To use PHP on Void Linux, install the PHP-apache. This package will pull PHP allowing you to use it on your system.
sudo xbps-install -S php-apache
When asked whether you want to install PHP-apache, type y for Yes.
$ sudo xbps-install -S php-apache [*] Updating repository `https://repo-default.voidlinux.org/current/x86_64-repodata' ... Name Action Version New version Download size libzip install - 1.9.2_1 86KB php install - 7.4.30_2 3692KB php-apache install - 7.4.30_2 2900KB Size to download: 6679KB Size required on disk: 31MB Space available on disk: 25GB Do you want to continue? [Y/n] y
Once PHP has been installed successfully, open the httpd configuration file. Note that Apache prints out PHP plain code; hence it is necessary to make changes in the configuration file.
sudo vim /etc/apache/httpd.conf
Once the above file has opened, comment on this line.
#LoadModule mpm_event_module modules/mod_mpm_event.so
Then uncomment the line below:
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
In the same file, at the end of the LoadModule List, add these two lines.
LoadModule php7_module /usr/libexec/httpd/modules/libphp7.so AddHandler php7-script .php
Still, on the same apache configuration file, scroll up to the end and add the below line.
Restart the Apache web server for the changes to be effective.
sudo sv restart apache
We will confirm whether PHP is well configured using the info.php file.
sudo vim /srv/www/apache/info.php
Then, inside the file, add this PHP code.
<?php phpinfo (); ?>
Save and exit from the file by pressing ESC followed by, :wq then hit the enter button.
Open your browser and type the http://localhost/info.php link to run the PHP file. The below image will be displayed.
Components of the LAMP stack are widely used around the world. Thus installing LAMP on your Void Linux is a good decision since you will leverage the benefits that Apache, MariaDB/MySQL, and PHP offer. Follow this guide for more information on installing and using LAMP on your Void Linux Operating System. In case you get stuck, feel free to leave a message in the comment section below.