• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install LAMP Stack on Ubuntu 18.04

Written by Admin, Updated On May 7, 2019
apache, lamp, mysql, php, ubuntu

LAMP stack on Ubuntu 18.04 is a group of open-source software that is typically installed together to host dynamic websites. LAMP stands for Linux OS, with Apache web server, Data store in a MySQL database, and dynamic content is processed by PHP.

How To Install LAMP Stack on Ubuntu 18.04

Install LAMP Stack on Ubuntu 18.04#

This tutorial will shows one by one step how to install LAMP stack on Ubuntu 18.04 server.

Prerequisites#

First of all you need Ubuntu 18.04 server with a non-root sudo enabled user account.

Step 1 – Install Apache#

Apache web server is most popular web server in the world. It also has a great community support so it’s default choice for hosting a website. Execute following commands to install Apache :

sudo apt update
sudo apt install apache2

Here, we use sudo as command so these operations are executed with root privileges. It will prompt you to enter your regular user password to verify. After entering password, it will show details which packages will be install and how much disk space they will take. Press Y and hit Enter to continue and installation process will started.

Make sure that your firewall allows HTTP and HTTPS traffic. You can check “Apache Full” profile enables traffic or not :

sudo ufw app info "Apache Full"
Output
Profile: Apache Full
Title: Web Server (HTTP,HTTPS)
Description: Apache v2 is the next generation of the omnipresent Apache web
server.

Ports:
  80,443/tcp

It should show that it enables traffic to ports 80 and 443 or you can Allow incoming HTTP and HTTPS traffic for this profile:

sudo ufw allow in "Apache Full"

As an alternative, you can execute separate commands for port 80 and 433 to allow traffic as following :

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

You can test it quickly by visiting your server’s public IP address in your web browser.

http://YOUR_SERVER_IP

It should display a default Ubuntu 18.04 Apache web page as following screenshot :

Ubuntu 18.04 Apache default

If you are able to see this page then your Apache installation is correct.

Step 2 – Install MySQL #

As you know MySQL is a database management system. So, It will organize and provide access to databases where your site can store information. Execute following command to install mysql server.

sudo apt install mysql-server

This command will also show you details of packages which will be install and how much disk space will take. Press Y to continue. Also it will prompt you to set MySQL root user password and it will be your mysql root password.

After that, now run MySQL pre-installed simple security script. Which will remove defaults and lock down access to your database system. Execute given command :

sudo mysql_secure_installation

It will prompt you to configure password validation policy and more settings for MySQL. It will also ask to remove unnecessary users, disallow remote root login and test databases so go throughout it.

Finally, your MySQL server is installed and ready to use.

Step 3 – Install PHP#

PHP component will process code to display dynamic content. Execute below command with helper packages so it can communicate with Apache and can make connection with MySQL database.

sudo apt install php libapache2-mod-php php-mysql

I hope php installed without any issue and we will check it now. Now, restart Apache web server in order to get your changes by executing below command :

sudo systemctl restart apache2

Step 4 – Test Setup#

In order to test that your system is configured properly for PHP, create a very basic PHP script called info.php.

So create this file at web root of server. In Ubuntu 18.04 directory is located at /var/www/html/ so create file here by executing this command :

sudo nano /var/www/html/info.php

Add the following PHP code inside the file:

<?php
phpinfo();
?>

At last, Save and close file. Now visit this page in web browser using your server’s public IP address as following :

http://YOUR_SERVER_IP/info.php

It should show as following screenshot:

How to Install LAMP Stack on Ubuntu 18.04

Finally, you finished it.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Configure Static IP Addresses on Ubuntu 18.04 Server
Next Article   How to Install LEMP Stack on Ubuntu 18.04

Related Posts

  • How to Install WordPress with Nginx on Debian 11

    How to Install WordPress with Nginx on Debian 11

    March 22, 2023
  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook