Step-By-Step LAMP Server Set-Up (Optimized For Ubuntu / Drupal)

(Linux Apache MySQL PHP) Set-Up

Part 1 – Login to Server

After setting up your server on Rackspace you can login to it in the terminal via ssh root@your-ip-address and the passcode that popped-up during set-up.

Make sure your new ip address is not blacklisted (meaning the previous owner abused it.) Go to to see.

Part 2 – Up-Date Server

Once in your server you need to update and upgrade by using code below. Since we are logged in as root we do not need to use sudo in our commands.

sudo apt-get update

Part 3 – Install Apache

Next, we need to install Apache2 and it's dependencies.

Depending on your version of ubuntu either apache2 version 2.2 or 2.4 will be installed. The version you have will determine the configuration you need to setup so check your version with:

apache2 -v

An useful article that explains how to migrate from 2.2 to 2.4 will explain the configuration differences.

If you receive the error Could not reliably determine the server's fully qualified domain name... this is a friendly reminder to change your ServerName to localhost in your httpd.conf or apache2,conf in etc/apache2 and restart apache2 with:

service apache2 restart

Once Apache2 is installed we need to edit one of its configuration files to make it more compatible with the Drupal install we will be doing in the the next segment.

nano /etc/apache2/mods-enabled/dir.conf

Edit the line below, moving 'index.php' to the front of the line, directly after ' DirectoryIndex' like below:

IfModule mod_dir.c

DirectoryIndex index.php index.html index.cgi index.xhtml index.htm


For Drupal and other content management systems, you'll need mod_rewrite turned on:

sudo a2enmod rewrite ssl

In order for the above to take affect we need to restart Apache2 with:

service apache2 restart

After restarting we can test our Apache2 by using putting the ip address as the URL. You should be directed to the Apache2 Ubuntu Default Page.

Part 4 – Install MySQL

Next we need to install MySQL and its dependencies.

apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

After you say yes to the install, a prompt window will appear for you to enter your new mysql password. Once confirming the password you will be returned to the terminal. Now you are able to login to MySQL.

mysql -u root -p
To exit mysql type exit or q

Next, we can initialize the mysql tables with the code below (this does not need to be done while logged in to mysql):


This should return the following:

Installing MySQL system tables...

Filling help tables...

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system


To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cloud-server-01 password 'new-password'

Alternatively you can run:


which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with:

cd /usr ; /usr/bin/mysqld_safe

You can test the MySQL daemon with

cd /usr/mysql-test ; perl

Please report any problems at

Now we can secure our mysql installation.


You will get the note below. This sets a scripts of security questions to answer and prompts you in the first question to change your root password.



For proper security some of the questions and our recommended answers include:

remove anonymous users - Y
disallow root login remotely - Y
remove test database - Y

Part 5 - Installing PHP

Finally we need to install PHP and its dependacies.

Make sure you are using the php version that will work best with your OS and your version of Drupal. For example Ubuntu does not work well with PHP 5.3.

For Drupal 7 PHP 5.2.5 or higher (5.4 or higher recommended). And for Drupal 8 PHP 5.4.5 or higher is recommended.

apt-get install php5 libapache2-mod-php5 php-pear php5-gd php5-mcrypt php5-curl php5-cli php5-dev

Depending on how much space you need or if you would like to edit your php.ini go to:

sudo nano /etc/php5/apache2/php.ini

In the php.ini file you can change variables such as:

memory_limit = 256M
post_max_size = 25M (toward bottom)
upload_max_filesize = 10M

After install you will have to restart apache2 once again.

service apache2 restart

Part 6 - What's Next?

Now that your LAMP server is set-up you can follow our security guide to make your server more secure or install Drupal. Please see our next ariticles to continue.