Install Apache

To install Apache open the terminal and type these commands:

sudo apt-get update
sudo apt-get install apache2

Make sure that your firewall allows HTTP and HTTPS traffic:

sudo ufw allow in "Apache Full"

Type your pubblic IP or localhost in your browser:

http://localhost

http://your_ip

Your web server is now ready! with default configuration.

To restart Apache:

sudo service apache2 restart

To stop Apache:

sudo service apache2 stop

To start Apache:

sudo service apache2 start

Install MySQL

To install MySQL open the terminal and type this command:

sudo apt-get install mysql-server

During the installation, your server will ask you to select and confirm a password for the MySQL "root" user. This is an administrative account in MySQL.

Securing MySQL (Optional)

sudo mysql_secure_installation

Enter "y" for "yes" or any other letter for "no". In the first step enter the password of the root user, then you will be asked if you want to test the password security and if you want to change it.

For the following steps it is recommended to press "y" then "yes".

  • Remove anonymous users
  • Disable root login remotely
  • Remove test database
  • Update new rules

Install PHP

To install PHP open the terminal and type this command:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

Restart Apache:

sudo service apache2 restart

Test PHP processing on your web server, create a PHP file at root location by typing:

sudo nano /var/www/html/info.php

Put the following text, inside the file:

<?php phpinfo(); ?>

Close and save.

Now we can test our web server. We just have to visit this page in our web browser.

http://localhost/info.php

http://your_ip/info.php

If this was successful, then your PHP is working as expected.
The installation is now complete with basic configurations.