Build a LAMP stack (Linux, Apache, MySQL, PHP) - Ubuntu 14

Difficulty: 3
Time: 20 minutes

To build a dynamic web application, you need what has been coined a “stack” - which is developer lingo for an integrated set of software that has all of the components your application needs.

Most stacks have the same types of components and differ mainly in which pieces of software they use for those components. For example, we’ll look at LAMP (which this article covers):

Component LAMP Software
Operating system Linux (e.g. Ubuntu)
Web server Apache
Database MySQL
Programming language PHP

If you're astute, maybe you noticed that LAMP is just an acronym for the software the stack uses.

In this guide, we'll walk you through installing all of these components (except for Linux, which is already installed as your OS when you create the server).

Install Apache

  1. Before you begin any installation, make sure that your software is up to date:
    sudo apt-get update
  2. Install Apache:
    sudo apt-get install apache2
  3. Set Apache to start on server boot:
    sudo update-rc.d apache2 defaults
  4. Verify that Apache is installed by going to:
    http://your server's IP address.
    If Apache is installed, the Apache Test Page displays.

    Note: GoDaddy Cloud Server customers can use Find your server's IP.

Install MySQL

  1. Install MySQL:
    sudo apt-get install mysql-server php5-mysql
  2. Enter a root password, and then press enter.
    Warning: It is possible to not enter a password here. However, we cannot urge you strongly enough to enter a strong password here. Without one your server becomes incredibly vulnerable.
  3. Activate MySQL:
    sudo mysql_install_db
  4. Set MySQL to start on server boot:
    sudo update-rc.d mysql defaults
  5. Secure your database server:
    sudo /usr/bin/mysql_secure_installation

    Answer the following questions when prompted:

    Question Suggested Answer Why/Why not?
    Enter current password for root (enter for none): Enter the password you created earlier. MySQL needs this password to have sufficient access to system resources, so that it can function as a database server.
    Do you want to change the root password? n Unless you want to change what you just did.
    Remove anonymous users? y The anonymous user allows anyone to login without requiring an account created by an admin. A hacker attempting to compromise your database server may try logging in as this user.
    Disallow root login remotely? y It is more secure to create a non-root user with admin permissions. Answer "no," if you need more flexibility to manage your database server.
    Remove test database and access to it? y If you have a reason to keep a test database, answer "no."
    Reload privilege tables now? y Why wait?

Install PHP

  • Install PHP
    sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Because you're going to use PHP for your site, you should also make sure Apache prioritizes index.php over other index files (that is: the file that displays when visitors come to your website).

  1. Open the dir.conf file:
    sudo vim /etc/apache2/mods-enabled/dir.conf
  2. Move index.php to the first position directly after DirectoryIndex, so the line looks like this:
    DirectoryIndex index.php index.html index.cgi index.xhtml index.htm
  3. Save and close the file:
  4. Restart Apache:
    sudo service apache2 restart

Install PHP modules

If your applications requires any PHP modules, you can install them now.

  1. View available PHP modules:
    apt-cache search php5-
  2. The list of available PHP modules displays. If you want to get more information on a particular package, you can display the description by typing:
    apt-cache show the name of the package you want to use
  3. Install the package you want:
    sudo apt-get install the name of the package you want to use

Test PHP processing on Apache

  1. Create a new PHP file under the /var/www/html directory:
    sudo vim /var/www/html/info.php
  2. After the file opens, type in the following code:
  3. Save and close the file:
  4. To verify it works, type this URL in your browser: http://your server's IP address/info.php

A page displays with the PHP version, extensions, build date, and other information.

Next steps

Now that you have a LAMP stack, we recommend setting up Apache Virtual Hosts for your websites.

Var den här artikeln till hjälp?
Tack för din feedback. Ring vårt supportnummer eller starta chattalternativet ovan om du vill prata med en medarbetare på kundtjänst.
Vi är glada att vi kunde hjälpa till! Finns det något mer vi kan göra för dig?
Det var tråkigt att höra. Berätta vad som var krångligt eller varför lösningen inte hjälpte dig med problemet.