This works for Ubuntu 16.04 and Ubuntu 18.04. I would highly recommend that you install a Nginx server over Apache since it is overall much better and faster.
Before we start, please proceed following this tutorial’s first step if you do not already have a different account than root.
Before anything we need to make sure that our system is up to date.
apt-get update -y
apt-get upgrade -y
Installing Apache And PHP 7.2
To install the Apache server, run the following command:
sudo apt-get install apache2 -y
sudo apt-get install php7.2-curl php7.2-gd php7.2-json php7.2-mbstring php7.2-intl php7.2-mysql php7.2-xml php7.2-zip
You can access your website by the url
If you want to use a domain name instead, then simply point it to your server IP.
There are many different settings for security here too you may want to configure. One of the most common ones is to hide directories. You can follow this tutorial here.
To install the MySQL server, run the following command:
sudo apt-get install mysql-server
After the installation is finished you want to enable it by running the following commands:
systemctl start mysql
systemctl enable mysql
To configure the MySQL server please click here to jump down a bit.
If you followed our previous tutorial and set up a firewall, then you need to allow MySQL and Apache.
sudo ufw allow mysql
sudo ufw allow in "Apache Full"
sudo ufw restart
So you have gotten this far, good job! But now comes the hard part.
If you want to allow remote access from outside of your server to the MySQL database:
sudo ufw allow mysql
To open up MySQL shell:
/usr/bin/mysql -u root -p
If you have set any password to root, then type it after -p
To update/set the root password: (Change ‘password’ with your specified password. Example of this ‘MyPasswordwow!’.)
UPDATE mysql.user SET authentication_string = PASSWORD('password') WHERE User = 'root';
To create a database in MySQL:
Simply replace ‘name’ with the database name you want.
CREATE DATABASE Name;
After each change, do not forget to reload the MySQL server by running: