How to Setup LAMP Stack ( Apache, Mysql, PHP) on Ubuntu 20.04 Server
Ubuntu 20.04 LTS version got released on April 23rd,2020. In this article we will learn how to configure LAMP stack ( Apache, Mysql/ Mariadb, PHP ) stable versions on the Server / Desktop. Now without wasting any time let’s begin with this tutorial.
Before we install any package on the server, Let’s update the default repository and packages on the server with the following steps.
Step 1: Update Packages on the Server
sudo apt update sudo apt upgrade
Step 2: Install Apache2 Server on Ubuntu
sudo apt install apache2 -y
After the installation, we need to verify if the Apache server is active and installed properly.
systemctl status apache2
If the Apache2 status appears to be active and running, we can move on to the next step, If not, then execute the following command to start the Apache Server.
sudo systemctl start apache2
After this, use the IP address of your server in the browser, you should be able to see the default Apache Server Page. If you are using “ufw”, then allow port 80 to accept incoming TCP connections using the following command.
sudo ufw allow http
Step 3: Installing Mysql on Ubuntu 20.04 Server
On the Ubuntu 20.04 default, APT package repository Mysql 8.0 is available. Execute the following command on the terminal.
sudo apt install mysql-server -y
After the fresh install of the Mysql Server, we should run the default Database Security script to disable the default less secure options on the server.
This script will ask you a series of questions. It will first ask you whether you want to configure the Validate Password Plugin, which will help us to determine the password strength.
If we select this option, then the plugin will ask you to select the strongest password by selecting the number 2. The output of this command is going to be the following.
Output Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
After completing this, you will get the option to add the root password. We will get the strength of the added password, as we have selected the Validate Password Plugin. It will ask you to continue with the provided password, if you are satisfied with the selected password and its strength then Select the value “Y” and hit the “Enter ” button.
Then select all the default options after that, which will remove the default test database and anonymous user from the Mysql Server. Even if we have added Root Password but, we cant use it for the authentication on MySQL shell. If you want then you can change this by executing the following command on the terminal.
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Though using the root user for the operations is not a good practice, hence we should add another user with privileges.
GRANT ALL PRIVILEGES ON *.* TO 'myserverfixusername'@'localhost' WITH GRANT OPTION;
You will be able to configure the Mysql Server 8.0 Successfully with these commands. If you don’t wish to use the Mysql Server and want to use MariaDB for better performance, then you can follow these instructions.
Step 4: Installing MariaDB on Ubuntu 20.04
sudo apt install mariadb-server mariadb-client -y
Check the status of MariaDB Server
systemctl status mariadb
● mariadb.service - MariaDB 10.3.22 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-04-10 14:19:16 UTC; 18s ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 9161 (mysqld) Status: "Taking your SQL requests now..." Tasks: 31 (limit: 9451) Memory: 64.7M CGroup: /system.slice/mariadb.service └─9161 /usr/sbin/mysqld
If it’s not active you can start the service with the following command.
sudo systemctl start mariadb
Enable the MariaDB to start automatically at the boot time, execute the following command.
sudo systemctl enable mariadb
Now we need to run the post-installation security script for MariaDB.
The Script will ask you for the root user password, as we haven’t added any root user password, just simply press “Enter” and select “Y” to set the password. After this just select all the default options according to the need, it will remove the anonymous user, test database, and disable the remote login option for the root user.
MariaDB package on the Ubuntu server uses Unix_socket to authenticate. Hence we can log in using the Operating system’s user name and password. Execute the following command on the terminal to access MariaDB Shell.
sudo mariadb -u root
You can exit using the following command.
Step 5: Install PHP on Ubuntu 20.04.
PHP7.4 is the latest stable version available on the default APT package Repository. Let’s install it using the following command.
sudo apt install php7.4 libapache2-mod-php7.4 php7.4-mysql php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline
By using the following command we can enable the Apache PHP7.4 Module
sudo a2enmod php7.4 sudo systemctl restart apache2
Check the installed PHP version.
The output of this command:
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
I hope this article helped you to Setup LAMP Stack ( Apache, Mysql, PHP) on Ubuntu 20.04 Server LAMP stack on the Ubuntu 20.04. If you are using Minecraft Server then follow the below-mentioned article to Allocate more RAM to the Minecraft Launcher.