LAMP Stack is a set of free and open source software that can be used to create web applications. LAMP is a acronym and named after the original stack components i.e. Linux operating system, Apache web server, MySQL relational database management system and PHP programming language.
In this article, you will learn how to install LAMP stack on Ubuntu Server 18.04 LTS and deploy phpMyAdmin web application on it.
Table of Contents:
- Environment Specification
- Upgrading Ubuntu Server Packages
- Installing Apache on Ubuntu Server
- Installing MySQL Database on Ubuntu Server
- Installing PHP on Ubuntu Server
- Installing phpMyAdmin on Ubuntu Server
Environment Specification:
We have installed a Ubuntu Server virtual machine with following specification.
- CPU - 3.4 Ghz (2 cores)
- Memory - 2 GB
- Storage - 20 GB
- Operating System - Ubuntu Server 18.04 LTS
- Hostname – lamp-stack-01.centlinux.com
- IP Address - 192.168.116.218 /24
Upgrading Ubuntu Server Packages:
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.
Installing 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.
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.
Installing MySQL Database 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.
Installing 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.
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.
Choose the web server that we have installed on our LAMP Server.
We have chosen Apache web server. Click on Ok.
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.
Enter the root user password and click on Ok.
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.
We have successfully installed LAMP Stack on Ubuntu Server 18.04 LTS and deploy phpMyAdmin web application on it. If you want to customize the LAMP stack according to your requirements than you should read Learning PHP, MySQL & JavaScript by O'Reilly Media.
No comments:
Post a Comment