How to Create a LAMP Web Server Using Ubuntu

Ubuntu Web Server
Ubuntu Web Server.
01
of 08

What is a LAMP Web Server?

Apache Running On Ubuntu
Apache Running On Ubuntu.

This guide will show you the easiest way to install a LAMP web server using a desktop version of Ubuntu.

LAMP stands for Linux, Apache, MySQL and PHP.

The version of Linux used within this guide is of course Ubuntu.

Apache is one of many types of web server available for Linux. Others include Lighttpd and NGinx. 

MySQL is a database server which will help you make your web pages interactive by being able to store and display stored information.

Finally PHP (which stands for Hypertext Preprocessor) is a scripting language which can be used to create server side code and Web APIs which can then be consumed by client side languages such as HTML, javaScript and CSS.

I am showing you how to do install LAMP using the desktop version of Ubuntu so that budding web developers can set up a development or test environment for their creations.

The Ubuntu web server can also be used as an intranet for home web pages.

Whilst you could make the web server available for the whole world this is impractical using a home computer as broadband providers generally change the IP address for computers and so you would need to use a service such as DynDNS to get a static IP address. The bandwidth provided by your broadband provider would probably also not be suitable for serving web pages.

Setting up the web server for the whole world would also mean that you are responsible for securing the Apache server, setting up firewalls and make sure all the software is patched correctly.

If you want to create a web site for the whole world to view then you would be advised to choose a web host with CPanel hosting which takes away all of that effort.

 

02
of 08

How to Install a LAMP Web Server Using Tasksel

Tasksel
Tasksel.

Installing the whole LAMP stack is actually very straight forward and can be achieved using just 2 commands.

Other tutorials online show you how to install each component separately but you can actually install all of them at once.

To do so you will need to open a terminal window. To do this press CTRL, ALT and T at the same time.

In the terminal window type the following commands:

sudo apt-get install tasksel

sudo tasksel install lamp-server

The above commands install a tool called tasksel and then using tasksel it installs a meta-package called lamp-server.

So what is tasksel?

Tasksel lets you install a group of packages all at once. As described earlier LAMP stands for Linux, Apache, MySQL and PHP and it is common that if you install one then you tend to install them all.

You can run the tasksel command on its own as follows:

sudo tasksel

This will bring up a window with a list of packages or should I say group of packages that can be installed.

For instance you can install the KDE desktop, the Lubuntu desktop, a mailserver or an openSSH server.

When you install software using tasksel you aren't installing one package but a group of like-minded packages that all fit together to make one big thing. In our case the one big thing is a LAMP server.

03
of 08

Set the MySQL Password

Set MySQL Password
Set MySQL Password.

After running the commands in the previous step the packages required for Apache, MySQL and PHP will be downloaded and installed.

A window will appear as part of the installation requiring you to enter a root password for the MySQL server.

This password is not the same as your login password and you can set it to anything you wish. It is worth making the password as secure as possible as the owner of the password can administer the whole database server with the ability to create and remove users, permissions, schemas, tables and well pretty much everything.

After you have entered the password the rest of the installation continues without the requirement for further input.

Eventually you will return to the command prompt and you can test the server to see if it worked.

04
of 08

How to Test Apache

Apache Ubuntu
Apache Ubuntu.

 The easiest way to test whether Apache is working is as follows:

  • Open up Firefox by clicking the icon on the launcher (3rd from top)
  • In the address bar enter http://localhost

A web page should appear as shown in the image.

Basically if you see the words "It Works" on the web page as well as the Ubuntu logo and the word Apache then you know that the installation was successful.

The page you are seeing is a placeholder page and you can replace it with a web page of your own design.

To add your own web pages you need to store them in the folder /var/www/html.

The page you are seeing now is called index.html.

To edit this page you will need permissions to the /var/www/html folder. There are various ways to provide permissions. This is my preferred method:

Open a terminal window and enter these commands:

sudo adduser www-data

sudo chown -R www-data:www-data /var/www/html

sudo chmod -R g+rwx /var/www/html

You will need to log out and back in again for the permissions to take effect.

05
of 08

How to Check if PHP is Installed

PHPInfo
Is PHP Available.

The next step is to check that PHP is installed correctly. 

To do this open a terminal window and enter the following command:

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

Within the nano editor enter the following text:

Save the file by pressing CTRL and O and then exit the editor by pressing CTRL and X.

Open the Firefox web browser and enter the following into the address bar:

http://localhost/phpinfo

If PHP has installed correctly you will see a page similar to the one in the image above.

The PHPInfo page has all sorts of information including listing the PHP modules that are installed and the version of Apache that is running.

It is worth keeping this page available whilst developing pages so that you can see if modules you require in your projects are installed or not.

06
of 08

Introducing MySQL Workbench

MySQL Workbench
MySQL Workbench.

 Testing MySQL can be achieved using the following simple command in a terminal window:

mysqladmin -u root -p status

When you are prompted for a password you will need to enter the root password for the MySQL root user and not your Ubuntu password.

If MySQL is running you will see the following text:

Uptime: 6269  Threads: 3  Questions: 33  Slow queries: 0  Opens: 112  Flush tables: 1  Open tables: 31  Queries per second avg: 0.005

MySQL on its own is difficult to administer from the command line so I recommend installing 2 more tools:

  • MySQL Workbench
  • PHPMyAdmin

To install MySQL Workbench open a terminal and run the following command:

sudo apt-get install mysql-workbench

When the software has completed installing press the super key (windows key) on the keyboard and type "MySQL" into the search box.

An icon with a dolphin is used to denote MySQL Workbench. Click on this icon when it appears.

The MySQL workbench tool is fairly powerful albeit a little bit on the slow side.

A bar down the left lets you choose which aspect of your MySQL server you wish to manage such as:

  • Providing a server status
  • List client connections
  • Administer users and privileges
  • Manage system variables
  • Export data
  • Import data

The server status option tells you whether the server is running, how long it has been running, the server load, the number of connections and various other bits of information.

The client connections option lists the current connections to the MySQL server.

Within users and privileges you can add new users, change passwords and choose the privileges the users have against different database schemas.

In the bottom left corner of the MySQL Workbench tool is a list of database schemas. You can add your own by right clicking and choosing "Create Schema".

You can expand any schema by clicking on it to view a list of objects such as tables, views, stored procedures and functions.

Right clicking on one of the objects will allow you to create a new object such as a new table.

The right panel of MySQL Workbench is where you do the actual work. For instance when creating a table you can add columns along with their data types. You can also add procedures which provides the basic template for a new stored procedure within an editor for you to add the actual code. 

07
of 08

How to Install PHPMyAdmin

Install PHPMyAdmin
Install PHPMyAdmin.

A common tool used for administering MySQL databases is PHPMyAdmin and by installing this tool you can confirm once and for all that Apache, PHP and MySQL are working correctly.

Open a terminal window and enter the following command:

sudo apt-get install phpmyadmin

A window will appear asking which web server you have installed.

The default option is already set to Apache so use the tab key to highlight the OK button and press return.

Another window will pop up asking whether you want to create a default database to be used with PHPMyAdmin.

Press the tab key to select the "Yes" option and press return.

Finally you will be asked to provide a password for the PHPMyAdmin database. Enter something secure to use whenever you login to PHPMyAdmin.

The software will now be installed and you will be returned to the command prompt.

Before you can use PHPMyAdmin there are a few more commands to run as follows:

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf

sudo a2enconf phpmyadmin.conf

sudo systemctl reload apache2.service

The above commands create a symbolic link for the apache.conf file from the /etc/phpmyadmin folder into the /etc/apache2/conf-available folder.

The second line enables the phpmyadmin configuration file within Apache and finally the last line restarts the Apache web service.

What this all means is you should now be able to use PHPMyAdmin to manage databases as follows:

  • Open Firefox
  • Enter http://localhost/phpmyadmin into the address bar
  • Enter the PHPMyAdmin password into the password field and press the "Go" button.

PHPMyAdmin is a web based tool for managing MySQL databases.

The left panel provides a list of database schemas. Clicking on a schema expands the schema to show a list of database objects.

The top icon bar lets you manage various aspects of MySQL such as:

  • Databases
  • A SQL Editor
  • Server status
  • User accounts
  • Export data
  • Import data
  • Settings
  • Replication
  • Variables
  • Character sets
  • Engines 
  • Plugins

 

08
of 08

Further Reading

W3Schools
W3Schools.

Now that you have a database server up and running you can start to use it for developing full fledged web applications.

A good starting point for learning HTML, CSS, ASP, JavaScript and PHP is W3Schools.

This website has full yet easy to follow tutorials on client side and server side web development. 

Whilst you won't learn in depth knowledge you will grasp enough of the basics and concepts to get you on your way.

Was this page helpful?