Configuring Apache2 for multisite (localhost)

Apache2 is one of the most popular webservers out there. If you develop websites, you want to have WAMP (Windows, Apache, MySQL & PHP), MAMP (Mac ...), LAMP (Linux ...) on your development machine.

I have LAMP installed on a Virtual Machine I'm using for development.

First things first; unless you're an expert, don't configure Apache2 to serve as a webserver. There are hosting services out there that have professionals doing these configurations, and they get attacked by hackers

A friend asked me how to configure Apache2 for multisite development. I told him it was easy and then spend the whole morning figuring out how easy it is. It's not hard, just follow the following steps... in no particular order.

I'm supposing you already have one site up and running.

1. Activate the Virtual Host module

    You can skip this if you already have more than one site

$ sudo a2enmod vhost_alias

2. Create a new configuration file from the default

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/wordpress.conf

3. Edit the configuration file

    Add ServerName, that's the URL you will want to use
    Modify DocumentRoot, that's where the actual files of your site will be

$ gksudo gedit /etc/apache2/sites-available/wordpress.conf
>   ServerName wordpress.local
>   DocumentRoot /var/www/wordpress

4. Edit the local DNS file. 

    Add an entry for the URL you have defined for ServerName

$ gksudo gedit /etc/hosts
> 127.0.0.1 wordpress.local

5. Add the site to Apache2

$ sudo a2ensite wordpress

6. Restart Apache2

    This should be the last step

$ sudo service apache2 reload

7. Check your localhost

    Open a browser and write wordpress.local in the direction bar. If everything is all-right (and you have an index.html in the DocuentRoot) your site is up and running.


----
When you stop developing a site and want to disable it, use the following command (followed by a restart)

$ sudo a2dissite wordpress

Comments

Popular posts from this blog

A simple way to show the 'cookie' warning

Linear Mortgage Calculation