The LAMP server is one of the most commonly used sets of open-source apps for creating web apps. This stable and robust server structure is straightforward and simultaneously set up. LAMP is a combination of four components, namely: Linux, Apache, MySql, and Php. A similar counterpart for macOS and Windows is also there, namely MAMP and WAMP.
This free, open-source software app drives dynamic apps like Magento, WordPress, Joomla, and much more.
This guide will discuss how you can install Apache as the HTTP server, MariaDB or MySQL as a relation DBMS(database management system), and PHP as the server-side scripting language. For this article, we will be using Fedora version 37. In the end, your Apache web server will run a PHP script, connect to a DB and return a successful response.
LAMP components
Four program elements make up the Linux-based web servers. The elements are organized in layers to support each other and form the software stack. On top of this underlying stack, the elements also support mobile apps and websites. The four standard components are:
1. Linux
Linux, by itself, provides the basis of the model stack. On top of this layer, all other layers are run. The operating system is open-source and free. It is partially aided by its simplicity and is harder to customize most OSs.
2. Apache HTTP server
This second layer comprises apps from database servers, typically Apache Web Server. The layer is positioned just above Linux’s layer. Apache HTTP Server is an open-source licensing free software package first developed in 1995, formerly known as Apache Web Server.
3. MySQL
MySQL is a partnership database management system used in server data storage. This open-source format handles all data in an easy-to-use squamous format. Standard Query Language functions are suitable for organized business areas and impressive workshops that can conveniently accommodate all the biggest and most complex websites.
4. PHP
This and other related programming languages are used in the scripting layer. The PHP open-source scripting language is used to render interactive sites with Apache. We cannot use the Hypertext Markup Language (HTML) in complex procedures, including eliminating data from a database.
Let us now see some features of LAMP.
Features of LAMP
- It is open source. This means the software’s code is freely available and can be shared for people to make improvements and changes, boosting its general performance.
- It is a mature stack that is easy to configure.
- It is easily customizable. As such, users can replace every component with another open-source solution to suit the specific app’s needs.
- It is also easy to find support because of the vast size of the LAMP community.
Some of its cons include:
- It does not support other OS besides Linux.
- Switching between coding in PHP and Python on the server side and using JavaScipt on the client side can slow the development flow.
- The relational property of MySQL makes the whole LAMP stack less flexible and efficient than its competitors, who use non-relational solutions.
- Apache can run into performance problems when overloaded.
LAMP alternatives
Some of the open-source options include:
- XAMPP (Cross-platform, Apache, MariaDB, PHP, Perl)
- LLMP (Linux, Lighttpd, MySQL/MariaDB, PHP/Perl/Python)
- LAPP (Linux, Apache, PostgreSQL, PHP)
- MEAN (MongoDB, Express, Angular, Node.js)
- LEAP (Linux, Eucalyptus, AppScale, Python)
- LEMP (Linux, NGINX, MySQL/MariaDB, PHP/Perl/Python)
Some of the non-open sources include:
- MAMP (macOS, Apache, MySQL/MariaDB, PHP/Perl/Python)
- WAMP (Windows, Apache, MySQL/MariaDB, PHP/Perl/Python)
- WIMP (Windows, Internet Information Services, MySQL/MariaDB, PHP/Perl/Python)
Installing LAMP on Fedora
Requirements
Before proceeding further with the installation of the LAMP server in our Fedora system, ensure you meet the following requirements:
- Have a Fedora OS in your system. In this event, we will be using Fedora 37 OS.
- Good internet connectivity for downloading the packages.
- Root privileges to access the system you are working on.
In this guide, we will demonstrate how to set up the three components of the LAMP server. At later stages of the guide, we will also show you how to make a basic LAMP app to ascertain if the installation instance is working as intended.
Let us start!
How to install Apache
First, log in as root by running this command:
su -
To set up Apache, or httpd web server, open up your terminal and run this command:
dnf install httpd -y
Next, enable the Apache service to spontaneously start at the next system restart by issuing this command on your terminal:
systemctl enable httpd.service
Now, start the service, then check the status using the subsequent commands:
systemctl start httpd systemctl status httpd
Next, permit the HTTPS and HTTP services from the firewall. This is necessary if your firewall is blocking access to these services:
firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload
This should conclude the Apache installation process. Let us now continue with the installation of the MariaDB database.
How to install MariaDB
MariaDB is a fork of the original MySQL database.
Copy-paste the following command on your terminal to install the MariaDB in Fedora:
dnf install mariadb-server -y
Once the setup is over, we will now proceed to enable and start the MariaDB service, like we previously did with the Apache server:
systemctl enable mariadb systemctl start mariadb systemctl status mariadb
To conclude, in configuring and securing the MariaDB server, you have to configure some settings, which you don’t have to worry about, as this article will show you. Run the command below to start the secure setup of the MariaDB server:
mysql_secure_installation
After running the above command, a set of questions will open up on the screen like:
- Enter current password for root (Enter for none): Press the “Enter” button on your PC’s keyboard. The “Enter” key is used simply because there is no default password the first time you are configuring MariaDB.
- Switch to unit_socket authentication [Y/n]: type “n.” From MariaDB 10.4, a new authorization method has been appended based on the unix_socket. In this article, we will go with the conventional MariaDB password. Proceed by typing “N/n.”
- Change the root password? [Y/n] “n.” Remember that we have been using the root user from the moment we initiated the MariaDB installation. As such, we spontaneously have passwordless, root-like access. So continue by typing “N/n.”
- Remove anonymous users? [Y/n] “y.” Here, we recommend removing the anonymous users. The anonymous user allows anyone to log in to the database without an account. Removing the anonymous user is key for the production environment, as this account is meant for testing purposes. Proceed by typing “Y/y.”
- Disallow root login remotely? [Y/n] “y.” In the next section, deny access for root login from a remote address to boost security. Proceed by typing “Y/y.”
- Remove the test DB and access to it? [Y/n] “y.” The test DB is a default DB that anyone can access. Like the anonymous user, the test database is only meant for testing purposes and should be removed before proceeding to the production environment. Here, type “Y/y” as well.
- Reload privilege tables now? [Y/n] “y.” To apply the above changes, press “Y/y.”
Now we are done with the setup and configuration of MariaDB. Let us now move on to installing PHP.
How to install PHP
PHP is one of the most globally used scripting languages for app development. To install PHP in Fedora 37 OS, run the following command:
dnf install php php-common
Development with PHP will likely require the setup of several app-specific PHP modules, as shown below:
dnf install php-mysqlnd php-gd php-mbstrin
Some of these modules could already be set up with PHP; in our event, php-mbstring was set up alongside PHP.
A note about these modules:
- php0mysqlnd – MySQL Native Driver Plugin, or msqlnd, is needed by PHP for working with the MariaDB/MySQL DB.
- php-dg – Needed by PHP for working with and handling various image file (PNG, GIF, JPEG, and more) operations.
- php-mbstring – This module offers PHP with multibyte string handling capability.
With all that in place, let us test the LAMP server we just configured.
How to test the LAMP server configuration
After setting up everything, we are now ready to test our configuration. In this instance, we will create a test project to ascertain whether our LAMP setup’s components are working correctly.
Follow the steps below to do so.
Log in to the MariaDB database, as shown below:
mysql
For MariaDB version 10.4, you don’t need to specify the password to log in as a system-wide root user.
As we have denied the remote access for the root login in MariaDB while setting up, we need to generate a new user for remote access. In MariaDB, run the following command to create a new user:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY '123'; GRANT ALL ON *.* TO 'myuser'@'localhost'; flush privileges
Then return to the Apache root document directory and generate a file with a name of your preference; for instance, we will use “fosslinux.php”
After that, copy the following lines of codes inside the new file and save it:
LAMP Application My first PHP Application
Open a web browser and navigate to the following address:
http://localhost/fosslinux.php
or
http://”Apache_System_IP ”/fosslinux.php
If you correctly followed the afore-covered steps, you should be able to see the “Connection successful” message, as shown below:
Wrapping up
Finally! You have successfully created a LAMP environment and deployed a basic working LAMP app. This article covered how to set up a LAMP server in Fedora OS and the methods for testing a basic application using the LAMP server. Hopefully, this guide came in handy for you.