Build a LAMP stack (Linux, Apache, MySQL, PHP) - Debian 7
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):
|Operating system||Linux (e.g. Debian)|
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).
- Before you begin any installation, make sure that you update the
aptrepository:sudo apt-get update
- Install Apache:
sudo apt-get install apache2
- Set Apache to start on server boot:
sudo update-rc.d apache2 defaults
- 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:
sudo apt-get install mysql-server php5-mysql
- 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.
- Activate MySQL:
- Set MySQL to start on server boot:
sudo update-rc.d mysql defaults
- Secure your database server:
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:
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).
- Open the
dir.conffile:sudo vim /etc/apache2/mods-enabled/dir.conf
- Move the line
index.phpto the first position after the line
- Restart Apache:
sudo service apache2 restart
Install PHP modules
If your applications requires any PHP modules, you can install them now.
- View available PHP modules:
apt-cache search php5-
- 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
- Install the package you want:
sudo apt-get install the name of the package you want to use
Test PHP processing on Apache
- Under the
/var/www/directory, create a new PHP file:sudo vim /var/www/info.php
- When the file opens, type in the following code:
<?php phpinfo(); ?>
- Save and close the file:
- 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.
Now that you have a LAMP stack, we recommend setting up Apache Virtual Hosts for your websites.