Install Apache2, MySQL and PHP or Lamp On Ubuntu
In this article, We will learn how to install Apache2, MySql and PHP OR a LAMP stack on Ubuntu. The LAMP stack is a term of Linux, Apache, MySql, and PHP. If you want to host your website on a virtual private server then you need a LAMP server to run your website. So, first of all, You need a virtual private server to install Apache2, MySQL and PHP. Therefore you can easily buy a virtual private server from CloudCone or Digital Ocean. We will install Apache2, MySQL, and PHP on Ubuntu 16.04. So please select the Ubuntu server image when you are buying a virtual private server. After purchasing your server, So please login as root user in your server using Putty if you are running the window. You can also download putty from Putty’s official website.
Step 1: How To Install Apache2 On Ubuntu 16.04 LTS
Lets Start, When you are login as root user in your server through putty in window or terminal. So simply run a command which is given below to install the Apache2 HTTP server on Ubuntu.
sudo apt-get install apache2
After complete the Apache2 server installation then you need to run 2 more commands which are given below
sudo service apache2 stop
sudo service apache2 start
You can also check the Apache2 web server status by running this command.
sudo service apache2 status
sudo systemctl status service.apache2
After complete the Apache2 web server installation, please open your browser and putt your server IP address or http://localhost.Then you will see an Apache2 default page. Like this
Step 2: How To Install MySQL On Ubuntu 16.04
Now, We will install the MySQL Database Server on Ubuntu. So, please run the following commands to install the MySQL database server on a virtual private server. MariaDB is more secure and it is open-source.
sudo apt install mariadb-server mariadb-client
After installing the MySQL Database Server on Ubuntu, You need to run the following commands. Stop and Start again MySQL database.
sudo service mysql stop
sudo service mysql start
Now check your MySQL Database server status by running the following command. If your MySQL server status is not enabled then run enable command which is also given below.
sudo service mysql status
sudo systemctl enable mysql.service
After that, Run the following command to secure MariaDB by making root password and disallow remote root access.
When you will run this command on your Ubuntu server. You will see Prompted questions, So please give answers to our guidelines.
- Enter current password for root (enter for none): Just press the Enter
Set a root password? [Y/n]: Y
New password: Choose a password
Re-enter new password: confirm password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
Now, Restart your MySQL Database server or MariaDB by running the following command.
sudo service mysql restart
You can also check your database by running this command
sudo mysql -u root -p
Step 3: How To Install PHP and PHP Modules On Ubuntu 16.04
The final step is to install PHP and PHP Modules on Ubuntu 16.0.4 server. So, Please run the following commands to install PHP. The PHP 7.1 is not available on Ubuntu default repositories. So, we will run the following command to add the third party repository to upgrade.
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
Then we need to update and upgrade.
sudo apt-get update
Now run the following come to install PHP 7.1
sudo apt install php7.1 libapache2-mod-php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-zip php7.1-curl
After installing the PHP, Create a new file in the Apache2 default root directory to test the PHP on your virtual private server. So please run following command
sudo nano /var/www/html/test.php
after opening a file then add following command and save
<?php phpinfo( ); ?>
In the final, Please open your browser and browse your IP address 1.2.345.56.66/test.php or localhost/test.php. Then You will see a default PHP page. Like this
Now, You are virtual private server is ready to host your PHP website or WordPress website.