Drupal Virtual Private Server

8th of July, 2012

I've collected a set of instructions that I use when setting up a new VPS for running Drupal 7. I use VPS with Debian instead of the standard PHP hosting to gain more control of the hosting setup and also to be able to run other services, such as Apache Solr.

These instructions are for use on a freshly installed Debian Squeeze system. The setup is used for hosting a PHP website using Apache, MySQL and additional instructions for setting up Apache Solr. I run my websites on Drupal 7 and the instructions here should be good for any PHP based site.

Why Debian? I've been using a lot of different Linux distributions, from Slackware in 1999 to SuSE, RedHat, Gentoo etc. I've also been using Ubuntu some years back, and while Ubuntu is good for desktop, I started out with that for my VPS systems. However, the distributions update quite often and I decided to go with what Ubuntu is based on, namely Debian. Debian is a distribution focusing on stability and in-frequent changes, this is exactly what I need since I have limited time to keep the systems up to date.

1. Basic LAMP and tool install

apt-get update
apt-get install patch rsync curl python ssmtp vim php5-curl 
                php5-gd php-apc libapache2-mod-php5 
                mysql-server php5-mysql

2. Shell setup

Copy drush scripts to /root/tools. Add following lines to .bashrc:
export PATH=$PATH:/root/tools/drush
export EDITOR=vim

3. Configure web server

These instructions are for setting up without virtual hosts. I prefer to keep each site on a separate system.

Add following line to /etc/apache2/httpd.conf:

ServerName yourdomain.com

Edit /etc/apache2/sites-available/default to reflect hosting directory and to remove "AllowOverwrite None" Enable modrewrite:

a2enmod rewrite

Now create hosting directories. I keep my site under /var/Sites:

mkdir /var/Sites/yourdomain-prod/www
chown www-data:www-data /var/Sites/yourdomain-prod/www

4. Create database

Create database with mysqladmin: These are the SQL commands to run after the DB is created to create a user:
CREATE USER 'youruser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON youruser.* TO 'youruser'@localhost 
	  IDENTIFIED BY 'yourpassword';
flush privileges;

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
ON yourdb.*
TO 'youruser'@'localhost' IDENTIFIED BY 'yourpassword';

5. configure php:

Modify /etc/php5/cli/php.ini and /etc/php5/apache2/php.ini:
memory_limit = 256M
allow_call_time_pass_reference = On (for Drupal)
Change upload size limit to 20Mb:
upload_max_filesize = 20M
post_max_size = 20M

6. APC

APC is a PHP compile cache, used for performance:

edit /etc/php5/conf.d/apc.ini and make it contain:

extensioion=apc.so
apc.enabled="1"
apc.filters="-/vote/.*" (drupal specific)
apc.shm_size="96"

7. Mail

SSMTP, edit /etc/ssmtp/ssmtp.conf to send via external SMTP server.
hostname=yourdomain.com
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES
AuthUser=
AuthPass=
AuthMethod=LOGIN

9. Drupal cron

Setup cron job. Use the command
crontab -e:
to edit the crontab.

Adjust time:

2 * * * * curl --silent --compressed http://yourdomain.com/cron.php?cron_key=

10. Solr

I run Solr using Tomcat.

Install Tomcat and download Solr:

apt-get install tomcat6 tomcat6-admin
wget http://mirror.nohup.it/apache//lucene/solr/3.6.0/apache-solr-3.6.0.tgz

Then follow the Solr install instructions found here: http://pabloseminario.com/2011/02/22/installing-solr-on-debian-6-0/

Restrict the ip range of the apps to certain ip, make /etc/tomcat6/Catalina/localhost/ROOM.xml contain:

<Context path="/"
    antiResourceLocking="false">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
              allow="127\.0\.0\.1"/>
</Context>

Then copy ROOT.xml to solr.xml and change path to ="/solr". Now, copy schema configuration file from drupal module:

cd /var/lib/tomcat6/solr/conf
mv schema.xml schema.bak
mv solrconfig.xml solrconfig.bak
mv protwords.txt protwords.bak
cp /var/Sites/yourdomain-prod/www/sites/all/modules/apachesolr/schema.xml .
cp /var/Sites/yourdomain-prod/www/sites/all/modules/apachesolr/solrconfig.xml .
cp /var/Sites/yourdomain-prod/www/sites/all/modules/apachesolr/protwords.txt .

11. Keep machine up to date

Setup apticron to run every day. If packages are out of date you will receive a mail apt-get install apticron Edit /etc/apticron/apticron.conf to set your email address. Setup cron with crontab -e:
# Each day
0 0 * * * /usr/sbin/apticron


  
comments powered by Disqus