Build a LAMP stack (Linux, Apache, MySQL, PHP) - Ubuntu 14
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. Ubuntu)|
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 your software is up to date:
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
index.phpto the first position directly after
DirectoryIndex, so the line looks like this:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
- Save and close the file:
- 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 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
- Install the package you want:
sudo apt-get install the name of the package you want to use
Test PHP processing on Apache
- Create a new PHP file under the
/var/www/htmldirectory:sudo vim /var/www/html/info.php
- After the file opens, type in the following code:
<?php phpinfo(); ?>
- Save and close the file:
- 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.
Now that you have a LAMP stack, we recommend setting up Apache Virtual Hosts for your websites.