Installing LAMP Stack on Ubuntu 20.04

apache + MySQL+PHP

In this tutorial we going to learn how to install LAMP. LAMP (Linux, Apache, MySQL, PHP) is a set of software for web development. Includes Linux as Operation System, Apache – web server, MySQL – database system and PHP – programing language.

Prerequisites

Local or remote computer running Ubuntu server 20.04 or Ubuntu Desktop 20.04

Before install the LAMP Stack , first update the repositories:

sudo apt update
sudo apt upgrade

Apache Web Server installation

To install Apache web server type the following command:

sudo apt install -y apache2 apache2-utils

After run the above command Apache will be installed and ready. You may check the version with this command:

apache2 -v

To check the default Apache Web page open this address http://localhost/ for local computer, and for remote computer use the IP address.

Additional commands to start, stop, restart and check the status of Apache web server.

sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo systemctl status apache2

In some cases a firewall will prevent incoming requests to TCP port 80. To open TCP port 80 you will need to run a command.

For iptables firewall:

sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

For UFW firewall:

sudo ufw allow http

MySQL installation

For MySQL we will Install MariaDB Database Server. A drop-in replacement for MySQL. To install type the following command:

sudo apt install mariadb-server mariadb-client

To secure your MySQL server type the follow command:

sudo mysql_secure_installation

Additional commands to start, stop, restart and check the status of Mysql server.

sudo systemctl start mariadb
sudo systemctl stop mariadb
sudo systemctl restart mariadb
sudo systemctl status mariadb

Creating MySQL User Account and Grant All Privileges

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';

Replace newuser with a username and user_password with a password.

PHP installation

To install PHP and additional extensions type 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

If you want to install a new extension use the command:

sudo apt install php7.4-<new-extension>

Replace <new-extension> with the the name of the extension you want to install.

To check the version or list all installed modules use the following commands:

php -v
php -m

Next steps

Install WordPress website in your local computer of find professional services to create your new website. Or if you need professional help to setup a server you may find here.

Leave a Reply

Your email address will not be published. Required fields are marked *