How to install Apache, MySQL and PHP on Ubuntu 18.04

Ubuntu is one of the most popular Linux distributions. A lot of users use it to work with vps. To install LAMP (Apache, MySQL, PHP) you need a server with sudo access for commands.

Apache installation

First of all (as with any other installation of programs), you need to update the package manager

sudo apt-get update -y

Install and start Apache

sudo apt-get install apache2 -y
sudo systemctl start apache2.service

It is important to make sure that Apache was installed correctly and without errors. To do this, enter hostname -I in order to get your IP address and go to the link http:// SERVER_IP/

MySQL installation

sudo apt-get install mysql-server -y

This command will install the MariaBD database server and will then be prompted to enter the password for the root MySQL user. This step is required.

Install PHP

You can install PHP using the following command:

sudo apt-get install php -y

After installing PHP, you need to install common PHP extensions, such as GD, MySQL, and so on, using the following command:

sudo apt-get install -y php-{bcmath,bz2,intl,gd,mbstring,mcrypt,mysql,zip} && sudo apt-get install libapache2-mod-php  -y

Automatically Starting Apache and MySQL on Boot

These commands will allow you to start Apache and MySQL always when loading your web environment

sudo systemctl enable apache2.service
sudo systemctl enable mysql.service

Next, restart the Apache server for PHP to work

systemctl restart apache2.service

Was this article helpful?

Related Articles

1 Comment

  1. Thanks for ones marvelous posting! I definitely enjoyed reading it, you
    happen to be a great author.I will always bookmark your blog and
    will often come back down the road. I want to encourage that you continue your great work, have a nice morning!