Hostwinds Tutorials

Search results for:


Table of Contents


Installing Apache
Installing MySQL
Installing PHP
PHP 5.6
PHP 7.0
Test PHP

How to install LAMP on Ubuntu 16.04

Tags: Ubuntu 

Installing Apache
Installing MySQL
Installing PHP
PHP 5.6
PHP 7.0
Test PHP

LAMP stack is a popular open-source web platform commonly used to run dynamic websites and servers. It includes Linux, Apache, MySQL, and PHP.

You'll need to ensure you have a user set up that is not root that has been granted Sudo privileges. If you need assistance in doing this, you can do the following:

adduser desired-username

You'll want to set a strong password for the user.

The set password prompts:

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

You'll then use usermod to add the user to the sudo group. Make sure to replace [desiredusername]  below with the actual username you desire to create

sudo usermod -a -G Sudo [desiredusername]

Use the su command to switch to the new user account to which you have granted the privileges.

su [desiredusername]

Installing Apache

Apache is one of the most popular web servers available and widely used due to its stability. It's generally the default choice for Clients when setting up a web server due to its long history, stability, and support over many years.

You will install Apache using the Ubuntu package manager, apt.

You will run the following commands to start the update for your system and start the installation process.

sudo apt-get update && Sudo apt-get install apache2

It will then prompt you for the password of the user. Once you enter the password, it will start the installation process by showing its packages. You will press Y  and then hit Enter on your keyboard to continue with the installation.

You can verify that Apache installed correctly by going to http://your_server_IP_address (Replace your_server_IP_address with your server's IP address).

You can find your server IP address by navigating to the Cloud Control section in your Client Area. It can also be found in the welcome email we sent out to you. That email can be found in your email history, which is accessible through the Client Area by clicking the drop-down menu on the right-hand side that says "Hello Client."

If installed correctly, this should bring up a default Apache Default Page when you visit your server's IP address in your browser.

Installing MySQL

MySQL is a database management system. Hostwinds clients use this to organize and provide access to databases where your site will store information.

Run the following commands to get started.

sudo apt-get install mysql-server

As it did before, when installing Apache, it will bring up a prompt showing the packages it will install and the disk space that will be used. Press Y  and then Enter on your keyboard to continue with the installation.

During this, you will be asked to select a password for the MySQL "root" user. Make sure NOT to leave this blank and to create a strong password.

Installing PHP

PHP is the component that will process the code to display the content on your site. It can run scripts, connect to MySQL, and hand over the content.

PHP 5.6

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

PHP 7.0

apt-get -y install php7.0 libapache2-mod-php7.0

Apache will first look for the index.html file, but since you are using PHP, you will want to tell the webserver to look for index.php instead. You'll change this by editing the dir. conf file with root privileges.

sudo nano /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

The index.php file is then be moved into the first position. It should look like this.

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.CGI index.pl index.XHTML index.htm

When you are finished, press CTRL+X to save and then Y and Enter to confirm.

Apache is then restarted to save the changes.

sudo systemctl restart apache2 && sudo systemctl status apache2

Test PHP

Create the file by typing the command below:

touch /var/www/html/info.php && echo "" >>info.php

You'll then access the following link. (insert your IP for your hosting)

http://your_server_IP_address/info.php (Again, replacing your_server_IP_address with your server's IP address).

Once you have verified it is working, remove the file. You can do this by typing:

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

From here, you can install PHP Modules, WordPress, set up PHPMyAdmin, etc.

Written by Hostwinds Team  /  April 7, 2018