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 whatismyipaddress.com/blacklist 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.

https://www.digitalocean.com/community/tutorials/migrating-your-apache-c...

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.pl index.xhtml index.htm

/IfModule

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):

mysql_install_db

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

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

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:

/usr/bin/mysql_secure_installation

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 mysql-test-run.pl

cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems athttp://bugs.mysql.com/

Now we can secure our mysql installation.

mysql_secure_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.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

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 8.1+ or higher is recommended.

apt-get install php8.1 libapache2-mod-php8 php-pear php8.1-gd php8.1-mcrypt php8.1-curl php8.1-cli php8.1-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.