The LAMP Stack, which is short for the Linux, Apache, MySQL, and PHP web technology stack is currently the most popular web hosting environment for the PHP based application.
The LAMP stack powers over 70% of all web technologies according to W3Techs, the independent web technologies usages statistics engine. In the LAMP stack, Linux is an operating system, which in this case we will be using the Ubuntu flavor of Linux, Apache is the web server developed by Apache Foundation, the latest version is version 2.0, MySQL is relational database management system used for storing data which is currently replaceable with MariaDB and PHP is the programming language, the latest version is PHP 7.
All these version come with the latest version of Ubuntu 18.04. In this article we will be going over how to install and configure the LAMP stack on a new install on Ubuntu 18.04. if you don’t have a test box, head over to Digital Ocean or any of the Cloud services providers to get a new install of Ubuntu to follow along.
Firstly, we are required to have root access to the server you are installing on, login to your Ubuntu system using GUI for Desktop and SSH for the server edition and upgrade current packages to latest version.
ssh ubuntu@IP-address-of-host sudo apt update sudo apt upgrade
1. Installing PHP
Out of the box, Ubuntu 18.04 has PHP 7.2 as the default installation. However, you can add an additional PPA for PHP installation which includes multiple other versions of PHP. Use the apt command below to update apt cache and install PHP packages on your system.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt update sudo apt install -y php7.2
Now you install some additional PHP modules for supporting various tasks depending on what you need to do.
sudo apt install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-xml
2. Installing Apache2
After installing PHP on your system, let’s start the installation of Apache2 in your system. Your also required to install libapache2-mod-php module to work PHP with Apache2.
sudo apt install apache2 libapache2-mod-php7.2
This command will install the Apache web server and install the PHP module that allows Apache to become the PHP application server. This module automatically allows apache to process all files that end with the extension .php
.
3. Installing MySQL
Now we are at the final step of installing MySQL, In this last step we will install mysql-server packages for MySQL database. Also, install php-mysql package to use MySQL support using php. Use the following command to install it.
sudo apt install mysql-server php7.2-mysql
The installer will prompt for root password, This password will work for your MySQL root user. After installing MySQL execute the following command for initial settings of MySQL server. You will see that script will prompt for more settings than earlier MySQL versions like password validation policy etc.
sudo mysql_secure_installation
Additionally, you can also install phpMyAdmin for the administration of MySQL using web interface.
sudo apt install phpmyadmin
4. Restart MySQL and Apache Services
After installing all the services on your system. Restart MySQL and Apache service to reload any changes done manually.
sudo systemctl restart apache2.service sudo systemctl restart mysql.service
After completing all setup. Let’s create a phpinfo.php
file website document root with following content.
<?php phpinfo(); ?>
Now access this file in web browser. You will see the screen like below with all details of PHP on server.
At this point you have successfully configured web server on your Ubuntu 18.04 System. In our next article, we will be installing LAMP Stack on RHEL based systems, subscribe below to get updates on that article.