In this tutorial, we want to learn how to install LAMP stack on ubuntu 20.04 LTS. In the previous article, we talk about install lamp stack with tasksel on ubuntu 18.04 LTS. But in this tutorial we manually everything on a LAMP stack.
LAMP Stack is an open-source Web development platform that uses Linux as the operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language.
Install LAMP on Ubuntu 20.04
Point: in this post we connected to Ubuntu 20.04 via SSH as the root user, If you don’t access with root user or use sudo usernames, please add the sudu command before every command we write below.
Install Apache on Ubuntu 20.04 LTS
For installing the Apache webserver on Ubuntu, you have to use an apt command like the following command:
apt install apache2
Once the installation is finished, you’ll need to adjust your firewall settings to allow HTTP and HTTPS traffic. UFW has different application profiles that you can leverage for accomplishing that.
For opening Web server port on UFW, following command:
ufw allow in "Apache"
After that, you can use the below command to check the status and enable rule.
If you see output like below, the configuration on UFW is OK for service on port 80 and 443.
Output Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Apache ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Apache (v6) ALLOW Anywhere (v6)
Now, you can open the browser and use the static IP of your server to check everything is OK or not.
You may also be interested in :
Install MySQL Ubuntu 20.04 LTS
Now the Ubuntu server has a web server up and running, you need to install a database system to be able to store and manage data for your sites.
For installing MySQL on ubuntu 20.04, run the following command.
sudo apt install mysql-server
When prompted, confirm installation by typing Y, and press Enter key.
When the installation is done, you need to run a security script that comes pre-installed with MySQL.
So run the following command, for preinstalled MySQL and Secure it.
this will ask if you want to configure the validate password plugin.
Answer Y for yes or anything else to continue without enabling.
If you answer yes, You will be asked to select a level of password validation, we are recommended answer 2 and press Enter, but you can choose any option you want.
After that you need to input your favorite password for MySQL’s root username twice.
And after that press Y and Enter key for every prompt until the end.
When the script is done, you can verify MySQL with log in to the MySQL console with the following command.
You will see output like below if your MySQL service installed OK.
Output Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 8.0.19-0ubuntu5 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
To exit the console, you need type exit and press Enter.
Install PHP on Ubuntu 20.04
You have Apache installed to serve your content and MySQL installed to store and manage your data. PHP is the component of our setup that will process code to display dynamic content to the final user. In addition to the PHP package, you’ll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. You’ll also need libapache2-mod-php to enable Apache to handle PHP files. Core PHP packages will automatically be installed as dependencies.
To install these packages, please the following command:
apt install php libapache2-mod-php php-mysql
After the installation is finished, you can run the following command to confirm your PHP version:
IF PHP successfully installed, you see output like below:
Output PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
remember: With the above command, Ubuntu installed the latest version of PHP, so if you need any version on PHP, you should type version of PHP.
Testing PHP Processing on your web server
Now that you have a custom location to host your website’s files and folders, we’ll create a PHP test script to confirm that Apache is able to handle and process requests for PHP files.
Create a new file named info.php inside your custom webroot folder:
add below PHP command on it and save the file
To test this, go to your web browser and access your server’s domain name or IP address, followed by the script name, which in this case is info.php:
You’ll see a page similar to this:
We prepare a video from all steps, you can see the video below.