How to install and configure a development server for Drupal projects on Ubuntu 8.04 LTS Server, as a LAMP server in virtual machine.
We install here the LAMP and OpenSSH Server of Ubuntu 8.04 LTS Server.
The installation procedure of Ubuntu starts with choosing your preferred language (it's english in this tutorial).

At partitioning, I'm using the default, automated method, so partitioning the whole disk. Others can prefer the manual method, and define three partitions: the swap, the root and the home.
Don't forget to notice the name and password of your first user, you will need it later!

At the software selection, select the LAMP and OpenSSH server options, and just than continue.

Then it asks for the password of the MySQL root.

Some seconds later, the install is completed, and you can reboot. You can left your "CD" in the CR-ROM.

And at the end, log on with your user and password you noticed before.

So you have an Ubuntu LAMP server out of the box, let's add some supplementary packages we need for Drupal develpoment, like phpMyAdmin, the GD library of PHP, and so on.
Here we are going to upgrade to the latest packages, install Webmin and phpMyAdmin, the NFS common module, and some supplementary modules to PHP. At the end of this session, we will have all the components we need for the Drupal development environment.
First check whether new update packages are available to 8.04 LTS Server. To get the latest packages from Ubuntu, type to your terminal:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get autoclean && sudo apt-get autoremove
The downloads and install process can take some time, so be patient!

We download here the minimal package of Webmin, as well as some Ubuntu packages needed. For the whole functionality, many Webmin modules will be downloaded later, during the configuration process. To download the the minimal webmin package, type:
wget http://prdownloads.sourceforge.net/webadmin/webmin-1.420-minimal.tar.gz
sudo apt-get install perl libnet-ssleay-perl libauthen-pam-perl
The 1.420 version includes already the fixes of Webmin for Ubuntu 8.04. For the latest webmin version, check also the webmin home
To install webmin type:
mv webmin-1.420-minimal.tar.gz /tmp
cd /tmp
tar xf webmin-1.420-minimal.tar.gz
cd webmin-1.420
sudo ./setup.sh /usr/local/webmin
rm -rf webmin-1.420
rm -rf webmin-1.420-minimal.tar.gz
During install, accept defaults, set the webmin user and its password, and say yes to ssl and to start webmin at boot time.
To start Webmin, open your browser and type: https://your-ip:10000/ where 'your-ip' is the IP address the LAMP server. It is now a temporary link to check this step, but we will set up the permanent address later on. In order to manage your Ubuntu, you will need some more webmin modules and theme. We'll configure Webmin in Session 3.
In order to mount source files from other servers or clients, we need to install the nfs-common package of Ubuntu
sudo apt-get install nfs-common
It is the common tool for administrating the MySQL databases and tables during Drupal development.
sudo apt-get install phpmyadmin
In the configuration screen, select apache2.

After that, open your browser, and type: http://your-ip:10000/phpmyadmin/ where 'your-ip' is the IP address the LAMP server to have the PhPMyAdmin.
Because of the standard LAMP package does not contain a very important PHP graphical package used by Drupal, we install it, and also restart the webserver:
sudo apt-get install php5-gd
sudo /etc/init.d/apache2 restart
Now we have all of the packages for our development environment on Ubuntu LAMP server, we continue now with some configurations.
How to configure the LAMP server in a virtual machine for Drupal developments.
These are the configuration steps before Drupal install.
To work with NFS and web server, you'll need a fix IP and a domain name for the LAMP server. The quick-and-dirty solution is to edit some files like /etc/hosts and /etc/network/interfaces. Or you can install and config a BIND9 server for DNS and DHCP services.
We are going to have the quick-and-dirty solution, so let's login to the LAMP server and type:
sudo nano /etc/network/interfaces
Change this line in the file, where eth0 can be differ in your environment:
iface eth0 inet dhcp
... to these lines, but use your own IP and gateway addresses:
iface eth0 inet static
address 192.168.2.20
netmask 255.255.255.0
gateway 192.168.2.1
I will use in the following 192.168.2.20 as the fixed IP address of the LAMP server. Save (ctrl-o), exit (ctrl-x) and restart the networking:
sudo /etc/init.d/networking restart
Now adjust the hosts file:
sudo nano /etc/hosts
Add the following line at the end:
192.168.2.20 drupal.local drupal
192.168.2.30 host.local
One line refers the developer server (drupal.local), the other one is the hosts static IP address. Don't forget to use your own IP address! Save and exit.
I will use in the following drupal.local as the basic domain name on the LAMP server. You can have so many local domain names for your development projects, as you want, you just have to update the /etc/hosts
192.168.2.20 project1.local project1
192.168.2.20 project2.local project2
So from now on the LAMP server has a fix IP address, and can be found on your local network as drupal.local.
You can check the result with ping from a terminal of an other host:
ping drupal.local
We are going to use the SSH protocol to login to the LAMP server. It should work out-of-the-box, but first update the etc/hosts file of your host, as well. So open a terminal from your host, and type:
sudo nano /etc/hosts
Add the following line at the end:
192.168.2.20 drupal.local drupal
Save and exit, then you can login via ssh from a terminal of your host:
ssh user@drupal.local
Type yes, if it complains about the unknown authenticity of the LAMP server, and type your password also.
In best case, you are logged in, but here you are some steps for smooth usage.
This optional part is to upload your public key to the LAMP. If you don't have any public key, you can skip this section, but then you have to always supply your password during SSH login. See more details at http://sial.org/howto/openssh/publickey-auth/.
First, upload public key from host to guest. At the host's terminal:
scp ~/.ssh/id_rsa.pub user@drupal.local:
Next, configure the public key on the LAMP server. Login to LAMP and type:
ssh user@drupal.local
mkdir ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
rm ~/id_rsa.pub
Logout and close the terminal. From the next ssh login on, there is no more password needed.
If you need an SSH client on your host, type:
sudo apt-get install openssh-client
Instead of copy or ftp the drupal source to the web directory (/var/www) of the LAMP, we are going to setup a NFS mount. So we can store and edit our source away from the LAMP, but can do real-time testing using the LAMP server.
We assume here the source are properly exported at this point in your host (host.local), serving as an NFS server. To check it, type in a terminal of your host:
exportfs
How to setup an NFS server, see: http://www.howtoforge.com/perfect-nfs-on-ubuntu-8.04-amd64
On the LAMP server, start by creating the mounting points at /var/www
cd /var/www
sudo mkdir drupal6
sudo mount host.local:/home/www/projects/drupal-6.6 /var/www/drupal6
To check the mount, switch to /var/www/drupal6 and make a directory listing by ls. You should see the content in the mounting directory
If it's OK, then let's set up mounting also in boot time. Open the fstab file:
sudo nano /etc/fstab
and add one line to the end:
host.local:/home/www/projects/drupal-6.6 /var/www/drupal6 nfs defaults 0 0
So, that's it. We have the source code mounted into the LAMP servers web directory. To test it, type df at the LAMP servers terminal. Or go with your browser to: http://drupal.local/drupal6. It should start the drupal install procedure. But stop now here, we have some other steps ahead us.
We have to activate the Rewrite Engine in Apache. It is needed by Drupals "Clean-URL" feature.
sudo a2enmod rewrite
Next, we increase the memory limit of 16 MB in PHP5,
sudo nano /etc/php5/apache2/php.ini
Search for memory, and set it at least to 32M.
Don't forget to restart the webserver.
sudo /etc/init.d/apache2 force-reload
As the last step here, we also configure iptables, the build-in firewall of Ubuntu. You can skip this step, if you will have the LAMP server away from others.
So, let's check what we have running now:
sudo iptables -L
You will see something like this:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
As you can see, we are accepting anything from anyone on any port and allowing anything to happen.
To edit the firewall rules, dump the present configuration:
sudo iptables-save > ~/iptables.up.rules
Then open this file and replace the content by this:
*filter
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
# Accepts all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allows all outbound traffic
# You can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT
# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
# Allows SSH connections
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Allows ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
# Allows NFS connections
-A INPUT -p tcp --dport 111 -j ACCEPT
-A INPUT -p tcp --dport 2049 -j ACCEPT
-A INPUT -p tcp --dport 32771 -j ACCEPT
# log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Reject all other inbound - default deny unless explicitly allowed policy
-A INPUT -j REJECT
-A FORWARD -j REJECT
COMMIT
Then load this new configuration to the firewall by:
sudo iptables-restore < ~/iptables.up.rules
To check it, type:
sudo iptables -L
If it looks good, then move the config file to its place:
sudo mv iptables.up.rules /etc/iptables.up.roles
To switch on these rules at boot, edit the interface file:
sudo nano /etc/network/interfaces
Add this line to the loopback interface:
pre-up iptables-restore < /etc/iptables.up.rules
It should look like this:
# The loopback network interface
auto lo
iface lo inet loopback
pre-up iptables-restore < /etc/iptables.up.rules
Please note, this rule set is not the strongest one. We could also change the default ports, and so on. But for Drupal development, it should be enough.
How to install Drupal development environment.
So, up to now, there is a drupal core exported via NFS to the development server. Now we set up a new development project, adding specific modules and themes to the /sites directory. The /sites/all will contain all the standard modules, like CCK, Views, Mollom, Pathauto, which are used in every project. The project stuff (/sites/project-1.com, /sites/nw-cee.com and /sites/wepoca.net) will be set up and exported to the development server separately. The /sites directory will look like this:
defaults
all
- modules
- themes
- default.setting.php
project-1.com
- modules
- themes
- files
- setting.php
nw-cee.com
- modules
- themes
- files
- setting.php
wepoca.net
- modules
- themes
- files
- setting.php
So let's assume, we have a project directory in our host, and each Drupal project is listed there:
project-1.com
nw-cee.com
wepoca.net
Each project contains the content for the /site directory. For example, the nw-cee.com looks like this here:
v1
- modules
- themes
- files
- setting.php
v2
- modules
- themes
- files
- setting.php
In order to export the project specific stuff to the development server, type:
sudo nano /etc/exports
And add one line to the end:
/home/www/projects/nw-cee.com/v1 192.168.2.1/24(rw,no_root_squash,async,no_subtree_check)
Save and exit, than restart the NFS server
/etc/init.d/nfs-kernel-server restart
Check the result with exportfs.
Then we have to mount this on the development server.
cd /var/www
sudo mkdir nw-cee.com
sudo mount host.local:/home/www/projects/nw-cee.com/v1 /var/www/nw-cee.com
To make it permanent, update the /etc/fstab file, and add one line to the end:
host.local:/home/www/projects/nw-cee.com/v1 /var/www/nw-cee.com nfs defaults 0 0
We just need now a link in the development server, in order to bind the nw-cee.com directory into the drupal sites:
ln -s /var/www/nw-cee.com /var/www/drupal6/sites/nw-cee.local
Now we configure a virtual host for Apache.
(http://www.debuntu.org/2006/02/22/7-virtual-hosting-using-apache-2)
sudo nano /etc/apache2/sites-available/nw-cee.com.conf
Add this to the file. Replace nw-cee.local according to your project name.
<VirtualHost nw-cee.local>
DocumentRoot /var/www/drupal6
ServerName nw-cee.local
ServerAdmin webmaster@localhost
<Directory "/var/www/d6">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost>
Enable this new host, and restart Apache
sudo ln -s /etc/apache2/sites-available/nw-cee.com.conf /etc/apache2/sites-enabled/nw-cee.com.conf
sudo /etc/init.d/apache2 reload
As a last step, we just have to set up a database in MySQL, and run the Drupal install script.
mysql -u root -p
and enter the root password for MySQL. Recall, it has been set up during the install phase.
Once you have the "mysql>" promt, type:
create database nwcee;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON *.* TO 'YOUR-DRUPAL-USER'@'localhost' IDENTIFIED BY 'YOUR-PWD';
FLUSH PRIVILEGES;
exit
So you have now a database called 'nwcee' and a database user called 'YOUR-DRUPAL-USER' with privileges necessary for Drupal. This user will have the same access rights to all databases you create here.
And it's convenient to have an DBA user, creating and deleting databases, and for database maintenance tasks via phpMyAdmin. If you want to use the root here, it's also possible, but not recommended.
mysql -u root -p
In the "mysql>" promt, type:
GRANT ALL PRIVILEGES ON *.* TO 'YOUR-DB-ADMIN'@'localhost' IDENTIFIED BY 'YOUR-PWD' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
And now you can open your browser, type nw-cee.local and start the Drupal install procedure.