I drive about 25 domains with different technologies like wordpress, drupal, b2evolution, lussumo vanilla, phpCMS etc. Most of that need a typical LAMP. That is a Linux, an Apache, a MySQL and a PHP. It’s common sense to have kind of test systems, systems where you can test your development work before bringing it up to production. For that I use one linux machine running OpenSuSE Linux 10.2 (basically some partitions on my laptop I use with a boot manager).
Goals of the development and testing environment
There are several goal to be met by my dev-env:
- Having production-near environment (Tools, Versions, OS)
- Having same code for testing as in production
- Having production-like network structure
- Having a permanent installation
How to setup lot’s of virtual servers on the development host
My first and most important hint: Don’t use yast2 for setting up the virtual apache hosts. That module is still buggy. Use it only to set up apache the first time.
Prerequisites
I assume you have apache2, MySQL4 or MySQL 5 and PHP4 or PHP5 up and running. All you need now is a virtual host, a new database and a new database user to run the dev-env. What you get from your production hosting provider is a domain, a database server, a database name and a database user.
Example: www.geekland.de
As an example I use my domain geekland.de. It is hosted by 1&1 and has the following attributes (not really exactly these
):
domain: geekland.de
db-host: db1234.1und1.de
db-user: dbo12345678
db-pwd: qwertz123
database: db12345678
CMS: wordpress 2.1
Tools: PHP5, MySQL 5, Apache 2
Setting up the local development domain
Because I don’t want to mingle the real domains, I use a TLD “.test” on my local machine. For the example that means, I set up the domain “geekland.test” on my host.
Setting up a virtual network interface
That’s an easy task within unix. As root use
ifconfig lo:1 127.0.0.2
and add in /etc/hosts
127.0.0.2 geekland.test www.geekland.test
Starting an apache virtual server on this virtual interface
Add the virtual server in your apache’s httpd.conf file:
NameVirtualHost 127.0.0.2
<VirtualHost 127.0.0.2>
ServerName www.geekland.test
DocumentRoot /srv/www/vhosts/geekland
</VirtualHost>
Now put your htdocs file into /srv/www/vhosts/geekland and don’t forget to restart your apache!
Create a database on your local MySQL server
Login in to your MySQL server via mysql command, then issue the following command:
CREATE DATABASE `db12345678` ;
Create a database user on your local MySQL server
Now create a database user and grant login rights:
CREATE USER 'dbo12345678'@'localhost'
IDENTIFIED BY 'qwertz123';
GRANT USAGE
ON * . * TO 'dbo12345678'@'localhost'
IDENTIFIED BY 'qwertz123'
WITH MAX_QUERIES_PER_HOUR 0
MAX_CONNECTIONS_PER_HOUR 0
MAX_UPDATES_PER_HOUR 0
MAX_USER_CONNECTIONS 0 ;
Now grant special rights (all) to the new user for the new database:
GRANT ALL PRIVILEGES
ON `db12345678` . *
TO 'dbo12345678'@'localhost'
WITH GRANT OPTION ;
Alias the DB-Server to localhost
As I don’t need any access to the hoster’s DB machine db1234.1und1.de. I alias that host to my localhost. With that simple trick I can use the same config (like wp-config.php) file on my dev-env as on the production environment.
In /etc/hosts modify the localhost line to contain the DB Server:
127.0.0.1 localhost db1234.1und1.de
Now you’re done. You can use all the same files on your production plattform and your development plattform now. The only thing you need to take care is to change the top level domain if necessary (i.e. in DB dump files of wordpress).
The next project
Your next project can be set up in exactly the same way, just change the virtual interface to lo:2 127.0.0.3 and the apache config accordingly.