How to Install LAMP Stack on Ubuntu 20.04 Server (Apache, MariaDB, PHP). In this tutorial we shall introduce what a LAMP Stack is and then navigate to installations steps. Let’s start!
What is LAMP Stack
LAMP is a set of open source software components that provides a complete environment to deploy web application. LAMP uses a Linux as the operating system, Apache as the webserver, MySQL/MariaDB as a database server and PHP/Perl/Python as the scripting language. Each component has its own capability to deploy a dynamic and high performance web applications. It is customizable and allows users to replace every component with another open-source solution as per application’s requirement.
LAMP stack server is chosen by many developers due to its ease of deployment, customization and large community support. Most widely used Content Management CMS like, Joomla, Drupal and WordPress run on the LAMP architecture. Compared to other commercial products, LAMP simplifies the software development process and provides flexibility.
Install LAMP Stack on Ubuntu 20.04 Server (Apache, MariaDB, PHP)
Install Apache Web Server
Apache web server is one of the most popular and used web servers around the world. More than half of the websites on the Internet used the Apache webserver to serve the web content. By default, the Apache webserver is included in the Ubuntu default repository. You can install it using the following command:
apt-get install apache2 -y
After installing the Apache webserver, start and enable the Apache service using the following command:
systemctl start apache2
systemctl enable apache2
To check the Apache service status, run the following command:
systemctl status apache2
You will get the Apache running status in the following output:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-01 12:01:25 UTC; 8s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 1347 (apache2)
Tasks: 55 (limit: 2348)
Memory: 5.3M
CGroup: /system.slice/apache2.service
├─1347 /usr/sbin/apache2 -k start
├─1349 /usr/sbin/apache2 -k start
└─1350 /usr/sbin/apache2 -k start
Apr 01 12:01:24 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...
To verify the Apache version, use the following command:
apache2 -v
You will get the Apache version in the following output:
Server version: Apache/2.4.41 (Ubuntu)
Server built: 2022-03-16T16:52:53
You can now open your web browser and access the Apache test page using the URL http://your-server-ip. You should see the Apache test page on the following screen:
PHP is an open source programming language that combines all the elements of the LAMP stack. It works with Apache to create dynamic web pages. It is also used to retrieve the data from the database. In a simple terms, it allows web applications to run efficiently.
You can install PHP along with other extensions using the following command:
Once PHP is installed with other extensions, you can verify the PHP version using the following command:
php -v
You will get the following output:
PHP 7.4.3 (cli) (built: Mar 2 2022 15:36:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Next, create a simple PHP page to test PHP processing on the Apache webserver.
nano /var/www/html/info.php
Add the following code:
PHP Test Page
Save and close the file then open your web browser and access the PHP test page using the URL http://your-server-ip/info.php. You should see the PHP test page on the following screen:
In this section, we will test whether the PHP can connect to the MariaDB database and run the database queries. First, connect to the MariaDB shell with the following command:
mysql -u root -p
Once you are connected, create a database and user with the following command:
CREATE DATABASE linuxdb;
CREATE USER 'linuxuser'@'%' BY 'password';
Next, grant all the privileges to the linuxdb database:
GRANT ALL ON linuxdb.* TO 'linuxuser'@'%';
Next, flush the privileges with the following command:
Now, open your web browser and access the PHP page using the URL http://your-server-ip/list.php. If everything is fine, you will get the content you’ve inserted in your table:
How to Install LAMP Stack on Ubuntu 20.04 Server (Apache, MariaDB, PHP) Conclusion
In this post, we explained how to install LAMP Stack on Ubuntu 20.04 server. We also explained how to connect to the MariaDB database using PHP and execute queries. I hope you can now easily deploy your PHP application using the LAMP stack.
You can consider other stacks like XAMPP, LEMP or MEAN.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.