WebHostingPeople Blog

  • Domains
    • Shared Hosting

  • Cloud VPS
  • Servers
    • Client Area Login

How Can We Help?

How to Install LAMP Stack on Ubuntu / Debian

You are here:

A LAMP (Linux, Apache, MySQL, PHP) stack is a widely used and open-source web stack for hosting web content in a Linux environment. It is the most prevalent software stack that empowers dynamic websites and web applications. Here Linux serves as the operating system, Apache functions as the popular web server developed by Apache Foundation, MySQL acts as the relational database management system used for data storage, and PHP serves as the extensively utilized programming language. In this tutorial, we’ll discuss how to set up the lamp stack on Ubuntu/ Debian

Prerequisites

Minimal Ubuntu 18.04 server installation.

SSH access to the server

Root user privileges or use the sudo command to execute all commands

1) Updating Software Packages

Before installing the LAMP stack, it’s necessary to update the repositories and software packages. To accomplish this, please execute the following command:

$ sudo apt update

$ sudo apt upgrade

2) Installing Apache Web Server

To install the Apache Web server, please enter the following command. The apache2-utils package will install some useful utilities such as Apache HTTP server benchmarking tool.

$ sudo apt install -y apache2 apache2-utils

Once the installation process is complete, 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 start automatically at system boot time by using the command:

$ sudo systemctl enable apache2

To check the Apache version, use the following command:

$ apache2 –v

3) PHP Installation

PHP is one of the most widely used server-side scripting languages, utilized for generating dynamic content on websites and apps. Ubuntu 18.04 comes with default PHP 7.2 for installation. However, we recommend adding an additional PPA for PHP installation, which includes multiple other PHP versions. 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 to support various tasks.

$ sudo apt install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-xml

4) Installing MariaDB Database Server

MariaDB is a free and open-source database management system derived from MySQL. It is a community-developed project led by the original developers of MySQL. Use the following command to install MariaDB on Ubuntu 18.04.

$ sudo apt install mariadb-server mariadb-client

Once the installation process is complete, 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 start automatically at system boot time by using the command:

$ sudo systemctl enable mariadb

The MariaDB installation is not secure by default, so you need to execute a security script that comes with the package. You will be prompted to set a root password to ensure that nobody can log in to the MariaDB.

$ sudo mysql_secure_installation

When prompted, press Enter as the root password isn’t set yet. Then enter ‘y’ to set the root password for the MariaDB server.

Respond with 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 log in without providing the MariaDB root password.

$sudo mariadb -u root

To exit, run

exit;

Check the MariaDB server version information.

$ mariadb –version

Congratulations! You have successfully set up the LAMP stack (Apache, MariaDB, and PHP7.2) on your Ubuntu 18.04 server.

Post Your Comment