This tutorial will help you to install Apache, MariaDB and PHP 7.1 (LAMP) on Ubuntu 17.10. You can follow this tutorial on a VPS (Virtual Private Server) or on a local Ubuntu computer.
Installing LAMP on Ubuntu has four basic steps:
Before you install the LAMP stack, it is a good to update repository and software packages. Run the following commands:
sudo apt update
sudo apt upgrade
Enter the following command to install Apache Web server.
sudo apt install apache2 apache2-utils
Enter y when terminal will ask "Do you want to continue?".
After it is installed, Apache should be automatically started. You can check its status with systemctl.
systemctl status apache2
If it is not running, use systemctl to start it.
sudo systemctl start apache2
To enable Apache to automatically start at boot time.
sudo systemctl enable apache2
To check Apache version:
Now, type the public IP address of your server (or localhost) in the browser address bar. You should see "It works!" Web page, which means Apache Web server is running properly. If you are installing LAMP on your localcomputer, then type 127.0.0.1 or localhost in the browser address bar.
Now we need to set www-data (Apache user) as the owner of document root. By default it’s owned by the root user.
sudo chown www-data:www-data /var/www/html/ -R
MariaDB is a drop-in replacement for MySQL. Enter the following command to install it.
sudo apt install mariadb-server mariadb-client
After it is installed, MariaDB server should be automatically stared. Use systemctl to check its status.
systemctl status mariadb
If it is not running, start it with this command.
sudo systemctl start mariadb
To enable MariaDB to automatically start at boot time, run
sudo systemctl enable mariadb
Now, run the post installation security script.
When it asks you to enter MariaDB root password, press Enter key as the root password isn’t set yet. Then enter y to set the root password for MariaDB server.
Next, you can press Enter to answer all remaining questions, which will remove anonymous user, disable remote root login and remove test database. This step is a basic requirement for MariaDB database security.
To check MariaDB server version information.
Enter the following command to install PHP 7.1.
sudo apt install php7.1 libapache2-mod-php7.1 php7.1-mysql php-common php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-readline
Enable the Apache php7.1 module and then restart Apache Web server.
sudo a2enmod php7.1
sudo systemctl restart apache2
To check PHP version information.
To test PHP scripts with Apache server, you need to create a info.php file in the document root directory.
sudo nano /var/www/html/info.php
Paste the following PHP code into the file.
<?php phpinfo(); ?>
Save and close the file.
Now, in the browser address bar, enter server-ip-address/info.php. If you follow this tutorial on your local computer, then type 127.0.0.1/info.php or localhost/info.php. You should see your server’s PHP information. This means PHP scripts can run properly with Apache web server.
For your server’s security, you should delete info.php file now.
sudo rm /var/www/html/info.php