subject: Drupal 7 - How To Set Up Ubuntu 12.04 Lamp Stack The Easy Way [print this page] This post is all about how to install Ubuntu for your Drupal 7 site. Theres a lot of happenings in the world of Ubuntu. Ubuntu 12.04 LTS, codenamed "Precise Pangolin", is out integrating many improvements over the earlier versions. The packages are newer along with some command line syntax changes. As a whole, creation of the LAMP stack for your Drupal 7 site (with PHP 5.3 and MySQL 5.5) has been never this easy.
However, there are still a few steps to get everything going, but as you'll see it has become a lot easier than before.
This post is written, assuming the following things:
You have Ubuntu 12.04 already installed on your server. (Download) (Release notes)
You know your server's IP address.
You can direct your desired (sub-)domain at your server. Nuances of DNS are not covered here.
You want to set it up for Drupal. (These instructions may also apply for other LAMP-based CMSs.)
You have a computer with shell (SSH) access to your server, and your account has root or sudo access.
Note: This post does not cover MAMP, WAMP, DAMP, commandline bootcamp, and so on.
Setting up Ubuntu for Drupal: Step by step
1. Initial Preparation
The initial preparation has not changed. To do this, follow the same things that you have done earlier. Things that have changed, are mentioned below.
2. Setting up Apache
This step involves the setting up of VirtualHost configurations. In order to do this, you are required to have Apache2 installed. However, now we don't have to do it the old way. There's a new apt to do that
apt-get install lamp-server^
This package actually does what you think it does. It installs all the LAMP basics: Apache2, MySQL, PHP, and supplementary stuff. It's really cool!
Note: Remember the ^ at the end of the line as it's really necessary.
If you are not logged in as root or via sudo su -, you will need to prepend most commands in this post with "sudo".
After this, youll have to restart Apache, again with new command syntax
service apache2 restart
Ensure sure you have the latest updates.
apt-get update
apt-get upgrade --show-upgraded
There is a lot more to install, but first let's get to the basic setup.
3. Configuring VirtualHost stuff
There are a few steps here.
Add your IP address to the ports.conf file
Please note that in these instructions, your site's domain is represented by "example.com" and your server's IP address is represented by "12.34.56.78". Every time you see them in the examples here, you should replace them with your domain name and server's IP address, respectively.
nano /etc/apache2/ports.conf
Replace "*:80" with your IP address, so it looks like this:
NameVirtualHost 12.34.56.78:80
Setting up your server's default configuration
nano /etc/apache2/sites-available/default
Edit as such:
You would also want to update the DocumentRoot value, where you want to install your Drupal root.
DocumentRoot /var/www/example.com/html
Note: In case you are using Git to deploy your site, you will then want to make sure the DocumentRoot value aligns with the path that will result from your Git checkout. For instance, if you are installing from a GitHub project titled "foobar" and inside of it you have a folder "html" that contains your Drupal installation, your DocumentRoot value might be /var/www/example.com/foobar/html/.
Configuring name-based virtual hosts
At this point you would want to create a file in /etc/apache2/sites-available/ for each of your sites on the server.
Youll have to repeat this process for each site you are setting up. Please note that separate sites will have different DocumentRoot values, whereas a Drupal multisite setup will share the same DocumentRoot value.
Creating your website folders
The first thing that youll have to do is to create the folder for your logs. If you're using Git, the logs path should be outside of your Git repository.
mkdir -p /var/www/example.com/logs
This command will create your logs folder, and the domain folder containing it.
Next create your website html folder(s). Doing this will actually depend on how you're going to install your site on the server. If you are using scp or sftp or otherwise copying your Drupal code files directly onto the server, you will want to create the folder to hold them. Keep in mind that your DocumentRoot value that you enter above must match where your actual document root ends up being on the server. In case you are going to be deploying via Git, then you don't need to do that; Git will create it when you git clone the repository onto the server from /var/www/example.com/.
Enabling the virtual domain
a2ensite example.com
You are required to do this command for each domain or subdomain you're configuring here.
Reloading Apache
service apache2 reload
Assuming that you have configured the DNS for your domain to point to your server's IP address, virtual hosting for your domain should now work. There's still more server preparation to do so you can run Drupal.
4. Installing supplementary packages
These provide added functionality required or recommended for Drupal.
GD2
This provides your server image manipulation tools like resizing, which is necessary for Drupal 7's image module to work.
apt-get install php5-gd
pear
apt-get install php-pear
make
apt-get install make
At this point we can install things in other ways than via apt-get.
uploadprogress
uploadprogress provides your Drupal UI the upload progress bar, as opposed to the spinner, when uploading a file.
pecl install uploadprogress
Now add the extension to php.ini (the easy way). Just the following one liner:
[Note: in our case, uploadprogress is installed fine, according to status reports. However, acervulus reports that the above command has an incorrect path, and that the correct path should be:
In case the first version doesn't work, then you might try this other one.]
Next step: Reload.
service apache2 reload
Drush
In case you don't know about Drush module, then you are required to stop right here and learn about Drush first. Installation on Linux is rather easy. First, add the drush channel.
pear channel-discover pear.drush.org
Now install Drush.
pear install drush/drush
Test by typing:
drush
now, you should get a nice big output of available Drush commands.
Git
There are many great arguments for deploying code to your server via Git. Installing Git is easy:
apt-get install git
Please note that Git methods for handling site deployment details cant be covered as they are beyond the scope of this post.
5. Boost server security
There are quite a few things that you can do to help enhance your sites security. Few helpful links has been provided below.
Configuring firewall rules
There always have been a lot of discussions about how best to configure these rules. We found these following posts to be pretty helpful:
Note: Ubuntu has a tool available: Uncomplicated Firewall. It's built in to Ubuntu, but disabled by default. https://help.ubuntu.com/community/UFW
Installing Fail2Ban
Now, this will actually help in protecting your site from the attempts of cyber criminals.
apt-get install fail2ban
Configure Fail2Ban by entering the following command:
nano /etc/fail2ban/jail.conf
There you can set bantime and maxretry settings.
After its configured, Fail2Ban monitors your log files for failed login attempts. After an IP address has exceeded the maximum number of authentication attempts, it will then be blocked at the network level and the event will be logged in /var/log/fail2ban.log.
Securing MySQL
This is the trick that shields your database.
mysql_secure_installation
The default answers to the prompts should be fine.
Securing PHP
More security shield, this time for PHP.
apt-get install php5-suhosin
Restart Apache2.
service apache2 restart
6. Creating your database(s)
Log into MySQL.
mysql -u root -p
The -u defines the mysql user, which in here is mysql root user, 'root'. You will be prompted for the MySQL root password. You know that you are in, when you get a prompt like this:
mysql>
After this is done, create your database. In this example, the database name is 'foobar', the database user is 'trelayne', and the user password is 'p4ssw0rd'. You should change these to the actual database name, database user and passwords you want for your database. Make sure that you note these down, because you are going to need this info when you set up your Drupal site.
Create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci;
Please note that the ";" at the end of the line. That is needed for MySQL to execute the command.
Now, define the user and permissions for the database. We are going to keep things simple in here:
grant all on foobar.* to 'trelayne' identified by 'p4ssw0rd';
Now its time to wrap this up and quit MySQL:
flush privileges;
quit
7. Configuring PHP
nano /etc/php5/apache2/php.ini
Now heres a big file. You will be required to search through the file to find these value configurations.
You will want to boost the default memory limit value.
memory_limit: 128M
128MB is the default for Precise Pangolin. In case you are usinga lot of modules, or a heavy processes then you may need to increase this memory_limit value even higher. We have used 256M on heavier production sites.
The other settings that you may want to change are upload_max_filesize and post_max_size, as these limits depend on the fact how big of files you can upload via the Drupal user interface. Please keep in mind that PHP is not really good at handling big uploads, so if you're running an active community site, then you may not want to raise the upload limits, on the other hand, you might actually want to lower them.
If you are looking for more information, please refer to http://drupal.org/requirements for details and nuances on php settings.
Now, its time to restart Apache2.
service apache2 restart
For clean URLs:
a2enmod rewrite
And again:
service apache2 restart
All done! Now, that should cover everything. You can now pull in your system files, import your database, point your settings.php file to your database, and also load your site via web browser.
Conclusion
This post was written based on some personal trial and error mode of experience as well as thing learnt over the web. So, we are pretty sure that corrections and inputs are needed in this post to make it perfect and actually helpful. Thus, we are sincerely asking for your kind inputs and comments regarding this. Please feel free to share your thoughts and give us a piece of your mind. Thanks for engaging!
Valuebound is a leading Drupal Development Company providing Enterprise Drupal web solutions. For more information on Drupal Development,contact usatinfo@valuebound.com