If you wish to host websites on a VPS or an Unmanaged Dedicated Server, or if you have been assigned the task of installing all the required services for one, then a viable option would be to do it all in Linux. It has an advantage of hosting any dynamic website that uses PHP or WordPress with MySQL, Apache Server or any Relational Database. In this article you will get to learn and will know How to Install Linux, Apache, MySQL database, PHP (LAMP) Stack on Ubuntu 14.04 using our step-by-step guide.
First off- LAMP is an acronym for a group or set of open source software that we will use- the Linux OS, the web server Apache, the essential MySQL database and of course, PHP. All of them combined and installed will give a server the power to host web apps and dynamic websites.
Installing Apache Web Server
Apache is a renowned web server that is used all over the world with good reason- it is a great choice by default for hosting your website, and you can just as easily install Apache by utilizing Ubuntu’s versatile package manager,
apt. We will use the
sudo commands in this guide to ensure you have the proper permissions to execute the commands.
sudo apt- get update
sudo apt- get install apache2 -y
sudo command will prompt passwords for root privileges. Enter your password and proceed. Voila! the web server is already installed. Confirm that the Apache Server is configured right by checking your server ip in the web browser. Type in
A test page will pop-up, saying It Works! or the default page should come up. It will look similar to this:
Managing the web server
Should you ever need to restart or stop your Apache Web Server, type in these text as commands
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop to Stop
sudo /etc/init.d/apache2 restart to Restart
After the Apache configuration is completed, MySQL is the next logical step. MySQL pertains to a database management system that is open source, and will hold all your website’s data and arrange it in a relational table form. The ever-useful
apt can help us again here, as other packages come in the fray and assist in communication between our web components.
Type in the following command:
sudo apt-get install mysql-server php5-mysql -y
The server will prompt you to create and set a password to gain admin access as a MySQL root user. Provide a different password from your original Linux root password to protect yourself and your website. Wait a few minutes for MySQL to finish installation. There are still some more environments that are required to be installed for the MySQL to store web information securely. Point out the path for MySQL where it can create a directory structure by typing
Then increase protection and make your MySQL more secure by running an interactive script that will lock down database system access and remove dangerous defaults. Type in
As before, a password will be asked- this will be the password for your MySQL root account, and then it will next ask if you wish to change it. Enter Y for yes and N for no. Other questions can be answered by pressing the ‘Enter’ key, and the default values will then be set. Doing this removes all MySQL sample databases and users, loads the current settings and will disable the remote root log ins. Congratulations, MySQL is ready to use and the database system is complete. Moving on…
The next and last step will be installing PHP, which is responsible for processing your codes into dynamic content. It is able to run scripts, gather information from MySQL databases, and then transmit the content for display by the web server.
Run the command:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt -y
Some changes in the Apache configuration are needed to manage your dynamic website. By default, Apache looks for
index.html in a website directory, and we would like to command it to look for PHP files. We’ll then have it scan for the
Type in this text command to be able to open the file
dir.conf and modify it
sudo nano /etc/apache2/mods-enabled/dir.conf
The output would be like this:
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
which you would now modify into this, for the web server to process PHP file first
<IfModule mod_dir.c> DirectoryIndex (index.php is added here) index.html index.cgi index.pl (index.php is removed from here) index.xhtml index.htm </IfModule>
Once done, press “CTRL-X” to save and close it. Type Y to confirm, then hit ENTER for the file location. Afterwards, restart Apache for the changes to take effect, which you can perform by typing in
sudo service apache2 restart
How to Check if PHP is Working
To check and test the system if it has been configured properly, we need to create a very simple script which is the
info.php file in your public directory. Do this by entering
sudo nano /var/www/html/info.php
This will open a nano blank file wherein you will have to put the following PHP code in it:
<?php phpinfo(); ?>
Once done, save the file and then close it. You can then test whether it correctly displays content by visiting this page on the web browser and you need to enter your server IP address again:
Note: You may want to delete this file after performing the test since it could release information in regards to your server and made available even to unauthorized users.
Remove it by typing in
sudo rm /var/www/html/info.php
The page can be recreated anytime if you wish to access and see the information it holds in the future.
If this final step was a success… Congratulations! You have successfully configured LAMP stack on Ubuntu 14.04. Proceed in installing any CMS or host your dynamic website. This enables you to install various websites and a wide range of web software, with some of the more popular options being WordPress, PHPMyAdmin, and many more.
This work is licensed under a Creative Commons Attribution 4.0 International License.