My Computer Tips

Home | About | Categories | All Tips & Tutorials

Install a very basic LAMP server using Ubuntu 15.10

ID: 59

Category: Ubuntu

Added: 21st of December 2015

Views: 3,765

ⓘ This article is now out of date

This tutorial will show you how to set up a very basic LAMP server in Lubuntu, allowing you to create and test your websites locally.


Step 1 - Install Apache2


The first thing we need to do is install Apache2, so open your terminal and enter the following command
sudo apt-get install apache2

After installation open your webrowser and enter the following url http://localhost
You should see the Apache holding page.

Step 2 - Create www folder


Webpages are served from the /var/www directory, but I always find it better to serve the pages from my home directory, so the next thing we will do is create a new www folder on your desktop, then create a new file named index.html inside the www directory, copy and paste the HTML code below and then save the file.
<!DOCTYPE html>
<html>
<head>
<title>Apache Holding Page</title>
</head>
<body> Apache Holding Page </body>
</html>


Step 3 - Change Apache configuration files to serve files from the www directory


Now we need to edit two Apache configuration files to point Apache to the www directory you created earlier
We first need to edit /etc/apache2/sites-available/000-default.conf file
sudo gedit /etc/apache2/sites-available/000-default.conf

When the configuration file opens for editing, find the following:
DocumentRoot /var/www

and change to
DocumentRoot /home/username/Desktop/www


The next file we need to edit is /etc/apache2/apache2.conf
sudo gedit /etc/apache2/apache2.conf

When the configuration file opens for editing, find the following:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

and change to:
<Directory /home/username/Desktop/www>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>


Now we need to restart apache2 so the changes to the configuration files take effect, open your terminal and enter the following command
sudo service apache2 restart

After this open your browser and enter http://localhost, apache should now default to the index.html page you create earlier.

Step 4 - Install PHP5, MySQL Database


Now we can go on and install all the other packages, php5, mysql to complete the installation on of our basic LAMP server.

To install PHP5 open your terminal and enter the following command
sudo apt-get install php5

To install PHP5 GD Libarary open your terminal and enter the following command
sudo apt-get install php5-gd

To install MySQL database enter the following command. For the purpose of this tutorial when MySQL asks you for a root password when installing the package, leave this blank.
sudo apt-get install mysql-server

To install the PHP5, MySQL bind package enter the following command
sudo apt-get install php5-mysql

Now we need to restart apache2 so the changes take effect, open your terminal and enter the following command
sudo service apache2 restart


Step 5 - Create a phpinfo file


Next create a file in your www directory named info.php, open the file, copy and paste the code below and save it
<?php
phpinfo();
?>

Open your browser and enter the following URL, http://localhost/info.php to display information about your system
PHP Information file

Step 6 - Success


We have now set up a very basic LAMP server. This is enough to help you develop basic websites locally using PHP, MySQL. This tutorial will be expanded over time.