Installing LAMP Stack on Ubuntu / Debian
By InterServer Staff on October 23rd, 2015
A LAMP (Linux, Apache, MySQL, PHP) stack is a common, free, and open-source web stack used for hosting web content in a Linux environment. It is the most common software stack that powers dynamic websites and web applications. Here Linux is an operating system, Apache is the popular web server developed by Apache Foundation, MySQL is relational database management system used for storing data and PHP is the widely used programming language. In this tutorial, we can discuss about how to install lamp stack on Ubuntu/ Debian
Minimal Ubuntu 18.04 server Installation.
SSH access to the server
Root user privileges or use the sudo command to run all commands
1) Update Software Packages
Before installing the LAMP stack, you need to update the repositories and software packages. To do this, please execute the following command:
$ sudo apt update
$ sudo apt upgrade
2) Install Apache Web Server
To install the Apache Web server, please enter the following command. The apache2-utils package will install some useful utilities like Apache HTTP server benchmarking tool.
$ sudo apt install -y apache2 apache2-utils
Once the installation process has been completed, apache should be automatically started. You can check the apache status using the following command:
$ sudo systemctl status apache2
If the apache service is not running, start it using the command:
$ sudo systemctl start apache2
You can also enable Apache to automatically start at system boot time by using the command:
$ sudo systemctl enable apache2
Apache version can be checked by using the command:
$ apache2 –v
3) PHP Installation
PHP is one of the most widely used server side scripting language used to generate dynamic content on websites and apps. Ubuntu 18.04 has default PHP 7.2 for installation. But we suggest adding additional PPA for PHP installation which includes multiple other versions of PHP. You can use the following commands to install PHP packages and update apt-cache 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
You may also need to install some additional PHP modules for supporting various tasks.
$ sudo apt install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-xml
4) Install MariaDB Database Server
MariaDB is a free, open-source database management system forked from MySQL and it is a community developed project being led by the original developers of MySQL. Enter the following command to install it on Ubuntu 18.04.
$ sudo apt install mariadb-server mariadb-client
Once the installation process has been completed, mariadb should be automatically started. You can check the mariadb status using the following command:
$ systemctl status mariadb
If the mariadb service is not running, start it using the command:
$ sudo systemctl start mariadb
You can also enable mariadb to automatically start at system boot time by using the command:
$ sudo systemctl enable mariadb
The MariaDB installation is not secure by default, you need to execute a security script that comes with the package. You will be asked to set a root password to ensure that nobody can login to the MariaDB.
$ sudo mysql_secure_installation
Once you execute the script, it will ask you to enter MariaDB root password, press Enter key as the root password isn’t set yet. Then enter ‘y’ to set the root password for MariaDB server.
Then enter yes/y to the following security questions:
Set root password? [Y/n]: y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
You can run the following command to login without providing MariaDB root password.
$sudo mariadb -u root
To exit, run
Check MariaDB server version information.
$ mariadb –version
Congrats! You have successfully installed LAMP stack (Apache, MariaDB, and PHP7.2you’re your Ubuntu 18.04 server.
If you need any further help, please do reach our support department.