Cloud Servers Help

Build a LAMP stack (Linux, Apache, MySQL, PHP) - Debian 7

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. Debian)
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 you update the apt repository:
    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 the line index.php to the first position after the line Directory Index.
  3. 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 more information on a specific package, you can display the description:
    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. Under the /var/www/ directory, create a new PHP file:
    sudo vim /var/www/info.php
  2. When the file opens, type in the following code:
  3. Save and close the file:
  4. To verify that it works, type this URL into 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.

Was This Article Helpful?
Thanks for your feedback. To speak with a customer service representative, please use the support phone number or chat option above.
Glad we helped! Anything more we can do for you?
Sorry about that. Tell us what was confusing or why the solution didn’t solve your problem.