To install Apache web server, issue the command below:
$ sudo apt-get install apache2 apache2-utils
We need to enable Apache2 web server to start at system boot time, as well start the service as follows:
$ sudo systemctl enable apache2 $ sudo systemctl start apache2
To test whether the server is running, open your web browser and enter
http://server_address. The Apache2 default index page will be displayed in case the web server is up and running.
Note: The Apache default root directory is /var/www/html, all your web files will be stored in this directory.
Next, we need to install MySQL database server by running the command below:
$ sudo apt-get install mysql-client mysql-server
During the package installation, you will be prompted to set the root user password for mysql as seen in the image below. Choose a good and secure password, then hit the OK button twice to proceed further.
The database server deployment is not yet secure, for this reason, issue the following command to harden it’s security:
$ sudo mysql_secure_installation
Firstly, you will be asked to install the ‘validate_password’ plugin, so type in
Y/Yes and press Enter, and also choose the default password strength level. On my system, I already installed it.
Importantly, if you do not want to change the root password, then type
N/No when prompted to do so. Answer
Y/Yes for the rest of the subsequent questions.
Last but not least, we shall install PHP and a few modules for it to work with the web and database servers using the command below:
$ sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-cli php7.0-cgi php7.0-gd
Furthermore, to test if php is working in collaboration with the web server, we need to create a
info.php file inside /var/www/html.
$ sudo vi /var/www/html/info.php
And paste the code below into the file, save it and exit.
<?php phpinfo(); ?>
When that is done, open your web browser and type in the this address
http://server_address/info.php. You should be able to view the php info page below as a confirmation.