Install LAMP on Ubuntu 20.04

The first step, make sure you have updated to the latest version of the kernel and library.


# apt update -y; apt upgrade -y; resize2fs /dev/vda1; reboot


Install Web Server


# apt install apache2 -y
# systemctl enable apache2


Install PHP74 and supporting PHP74 libraries


# apt install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4 -y

Cek php sudah terpasang dan menggunakan versi PHP74

# php -v
PHP 7.4.3 (cli) (built: Jun 13 2022 13:43:30) ( 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

Restart apache2 agar ter-integrasi dengan PHP74

# systemctl restart apache2

By default public html is located in /var/www/html. You can add your web files there directly.


Install MariaDB 10.5


MariaDB version 10.5 itself was launched in June 2020 and is currently in stable version status. And technical support from MariaDB developers will continue until June 2025. In general, the engine in MariaDB 10.5 has been refined and supports almost all database applications.

# apt install gnupg -y; apt install apt-transport-https curl -y
# apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
# sh -c "echo 'deb https://download.nus.edu.sg/mirror/mariadb/repo/10.5/ubuntu focal main' >>/etc/apt/sources.list"
# apt update; apt install install mariadb-server -y


Setup secure installation MariaDB 10.5

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!


Make sure MariaDB auto starts after rebooting.
# systemctl enable mariadb


Download phpmyadmin for easy database configuration


# cd /var/www/html/; mkdir phpmy9x; cd phpmy9x
# wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-english.tar.gz
# tar -zxvf phpMyAdmin-5.2.0-english.tar.gz ; cd phpMyAdmin-5.2.0-english
# mv * ..

Then try opening the phpmyadmin that was created earlier.

Go to http://ip-address/phpmy9x/ then use the root username and password that has been setup to log in to phpmyadmin and start creating a database.


Congratulations! Now your webserver and database have been successfully created and can be used.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.