Site icon CentLinux

How to install LAMP on Ubuntu Server 18.04 LTS

Share on Social Media

Learn how to install LAMP on Ubuntu Server 18.04 LTS with this step-by-step guide. Set up Linux, Apache, MySQL, and PHP to create a powerful web server for your applications. Perfect for beginners and advanced users. #centlinux #ubuntu #apache

What is LAMP Stack?

A LAMP server is a web server environment that uses a combination of four open-source software components to deliver dynamic web content. LAMP is an acronym that stands for:

  1. Linux: The operating system, providing the foundation for the stack. Linux is known for its stability, security, and flexibility.
  2. Apache: The web server software that handles HTTP requests and serves web content to users. Apache is highly configurable and widely used for its reliability and performance.
  3. MySQL: The relational database management system (RDBMS) that stores and manages the data for your web applications. MySQL is known for its efficiency and robustness.
  4. PHP: The server-side scripting language that processes the business logic of web applications, interacts with the database, and generates dynamic web pages.

Key Features:

Use Cases:

Components Explained:

A LAMP server provides a powerful, flexible, and efficient platform for web development, capable of handling a wide variety of applications from small personal blogs to large-scale enterprise systems.

In this article, you will learn how to install LAMP on Ubuntu Server 18.04 LTS and deploy phpMyAdmin web application on it.

Recommended Online Training: Setup LAMP Stack on a Remote Cloud Server + PHP Foundations

Ubuntu Server Specification

We have installed a Ubuntu Server virtual machine with following specification.

Update your Ubuntu Server

Connect with lamp-stack-01.centlinux.com as a privileged user by using a ssh tool like PuTTY.

Download latest package list from repositories and update apt available package list.

$ sudo apt update
Hit:1 http://pk.archive.ubuntu.com/ubuntu bionic InRelease
...
Fetched 10.2 MB in 22s (459 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
115 packages can be upgraded. Run 'apt list --upgradable' to see them.

We have now an updated package list. Therefore, we can now upgrade our Ubuntu Server 18.04 LTS with latest version of packages.

Install all the new packages using apt command.

$ sudo apt upgrade -y

After upgrading Ubuntu software packages, you may also need to restart your Server.

$ sudo reboot

All package in our Ubuntu Server 18.04 LTS has been upgraded to latest versions.

Install Apache on Ubuntu Server

Apache HTTP Server can be installed on Ubuntu Server by using the apt command.

$ sudo apt install apache2 -y

During installation, a systemd service for Apache web server is automatically created and started.

Check status of Apache service.

$ systemctl status apache2
â apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
  Drop-In: /lib/systemd/system/apache2.service.d
           ââapache2-systemd.conf
   Active: active (running) since Fri 2020-02-21 14:50:33 UTC; 1min 27s ago
 Main PID: 2294 (apache2)
    Tasks: 55 (limit: 2290)
   CGroup: /system.slice/apache2.service
           ââ2294 /usr/sbin/apache2 -k start
           ââ2297 /usr/sbin/apache2 -k start
           ââ2298 /usr/sbin/apache2 -k start

Feb 21 14:50:33 lamp-stack-01.centlinux.com systemd[1]: Starting The Apache HTTP
Feb 21 14:50:33 lamp-stack-01.centlinux.com systemd[1]: Started The Apache HTTP

Apache installation also allows the defaults services and ports in Linux firewall.

$ sudo ufw app list
Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

Open URL http://lamp-stack-01.centlinux.com/ in a web browser.

Apache2 Default Homepage

The browser will serve the default page of Apache Web Server. It confirms that the Apache has been installed and configured on Ubuntu Server 18.04 LTS.

Install MySQL on Ubuntu Server

Install MySQL database available in apt repository. If you want to install a latest version of MySQL that was not available in apt repository, then you have to download it from MySQL website.

$ sudo apt install mysql-server -y

Configure MySQL database server and set root user password.

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

MySQL installation process automatically creates and starts a systemd service of MySQL database server.

Check status of MySQL service.

$ systemctl status mysql
â mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Fri 2020-02-21 16:02:28 UTC; 5min ago
 Main PID: 3396 (mysqld)
    Tasks: 29 (limit: 2290)
   CGroup: /system.slice/mysql.service
           ââ3396 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Feb 21 16:02:27 lamp-stack-01.centlinux.com systemd[1]: Starting MySQL Community
Feb 21 16:02:28 lamp-stack-01.centlinux.com systemd[1]: Started MySQL Community

MySQL database has been installed on Ubuntu Server 18.04 LTS.

Install PHP on Ubuntu Server

Install PHP and relevant packages using following command.

$ sudo apt-get install php libapache2-mod-php php-mysql -y

Restart Apache service.

$ sudo systemctl restart apache2

Create a php file in Apache document root.

$ sudo vi /var/www/html/phpinfo.php

Add following lines of code in this file.

<?php
phpinfo ();
?>

Open URL http://lamp-stack-01.centlinux.com/phpinfo.php in a web browser.

PHPInfo Page

Our PHP script has created a complete web page that displays the detailed information about PHP and related plugins.

Our LAMP Stack has been installed on Ubuntu Server 18.04 LTS.

Installing phpMyAdmin on Ubuntu Server

To install phpMyAdmin and related packages, we can use apt command.

$ sudo apt install phpmyadmin php-mbstring php-gettext -y

After successful installation, the installer will launch the TUI (Terminal User Interface) based configuration setup.

PHPMyAdmin – Configure Web Server

Choose the web server that we have installed on our LAMP Server.

We have chosen Apache web server. Click on Ok.

PHPMyAdmin – Configure Database Server

phpMyAdmin needs a MySQL database to use as its data repository. Since, we have already installed MySQL database on our LAMP Server. Therefore, click on Yes.

PHPMyAdmin – Configure Database Password

Enter the root user password and click on Ok.

PHPMyAdmin – Re-enter Database Password

Re-enter the root password and click on Ok.

...
Creating config file /etc/phpmyadmin/config-db.php with new version
checking privileges on database phpmyadmin for phpmyadmin@localhost: user creation needed.
granting access to database phpmyadmin for phpmyadmin@localhost: success.
verifying access for phpmyadmin@localhost: success.
creating database phpmyadmin: success.
verifying database phpmyadmin exists: success.
populating database via sql...  done.
dbconfig-common: flushing administrative password
apache2_invoke: Enable configuration phpmyadmin
Setting up php-gettext (1.0.12-0.1) ...
Setting up libfontconfig1:amd64 (2.12.6-0ubuntu2) ...
Setting up libgd3:amd64 (2.2.5-4ubuntu0.3) ...
Setting up php7.2-gd (7.2.24-0ubuntu0.18.04.3) ...

Creating config file /etc/php/7.2/mods-available/gd.ini with new version
Setting up php-gd (1:7.2+60ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for libapache2-mod-php7.2 (7.2.24-0ubuntu0.18.04.3) ...

Restart Apache service to load changes.

$ sudo systemctl restart apache2

Open URL http://lamp-stack-01.centlinux.com/phpmyadmin/ in a web browser.

PHPMyAdmin Login Page

If you want to customize the LAMP stack according to your requirements than you should read Learning PHP, MySQL & JavaScript (PAID LINK) by O’Reilly Media.

Final Thoughts

Setting up a LAMP server on Ubuntu Server 18.04 LTS is an excellent way to create a robust and scalable environment for your web applications. With the combination of Linux, Apache, MySQL, and PHP, you can efficiently manage dynamic websites and applications.

If you need help with installing the LAMP stack on Ubuntu Server 18.04 LTS, I offer a detailed service on Fiverr. This service includes:

Get your LAMP server up and running smoothly with professional assistance. Visit my Fiverr page for more details: Fiverr – How to Install LAMP on Ubuntu Server 18.04 LTS.

Let me help you build a powerful web server today!

Exit mobile version