Migrating from Apache 1.3 to 2.0 on Debian Sarge
Created on 28th September 2005 05:00 AM.
I recently had to go through an upgrade from Apache 1.3 to Apache 2.0 on Debian Sarge. Despite significant differences in the configurations of the two versions of Apache, this can be a surprisingly smooth process if planned out well.
I'm assuming you already have Apache 1.3 installed, have root access to the server and have a number of sites configured as Virtual Hosts in your /etc/apache/httpd.conf file.The first step is to install Apache 2 with apt-get install apache2 apache2-common. This basic command will install the Apache server (check your /etc/apt/sources.list if the package isn't available). You may also want to install some additional packages, such as libapache2-mod-php4 and libapache2-mod-python for instance - either append those (with spaces for separators) to your original apt-get install command, or run separate apt-get install commands after the first. You should receive a message from Apt (Debian's package manager) telling you that a service is already running on Port 80 - your current Apache web server, and as a result it will disable Apache 2 by default. This is done by setting NO_START=1 in the configuration file /etc/default/apache2. Once we have reconfigured Apache 2 on a different port, we'll alter this to NO_START=0, and this will allow us to start Apache 2.
So, we have Apache 2 installed, but we can't start it, because it's using the same port as Apache 1.3. To change this, simply edit /etc/apache2/ports.conf by changing Listen 80 to Listen 8080 (or whatever port you want to use for testing purposes). Then you can change the NO_START entry to 0, and run /etc/init.d/apache2 start to start your shiny new Apache 2 web server.
The next step is to configure your Virtual Hosts. The configuration file layout is different between Apache 1.3 and Apache 2.0 on Debian - while Apache 1.3 typically has all of its Virtual Hosts information in the /etc/apache/httpd.conf file, Apache 2.0 separates each Virtual Host into a separate file in the /etc/apache2/sites-enabled directory. Say for instance your /etc/apache/httpd.conf Virtual Hosts section looks like this:
# Named VirtualHostsThis would translate in Apache 2 into two separate configuration files. In Apache 1.3, the first entry of your Virtual Hosts section serves as your "default" site - in other words, if someone comes to a site that's not configured in your Virtual Hosts section correctly, but is specified in public DNS as your server's IP address, they will be sent to this web site. In Apache 2.0, the default site is instead the first file (in alphabetical order) in the /etc/apache2/sites-enabled directory. After initial installation, there will be a symlink from 000-default in this directory to /etc/apache2/sites-available/default. As you can see from this, Apache 2.0 offers another level of abstraction in the Virtual Hosts by recommending putting the actual files in /etc/apache2/sites-available and then symlinking from there to /etc/apache2/sites-enabled. I would recommend following this convention, but it's not mandatory. In our example above, we would create two files, /etc/apache2/sites-available/default and /etc/apache2/sites-available/example.com. Our /etc/apache2/sites-available/default file would look like this:
NameVirtualHost *
<VirtualHost *>
ServerName incorrect.com
DocumentRoot /var/www/html/default
</VirtualHost>
<VirtualHost *>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html/example.com/html
CustomLog logs/www.example.com-access_log common
</VirtualHost>
NameVirtualHost *And our /etc/apache2/sites-available/example.com would look like this:
<VirtualHost *>
ServerName incorrect.com
DocumentRoot /var/www/html/default
</VirtualHost>
<VirtualHost *>We would then create symlinks to the /etc/apache2/sites-enabled directory with the ln -s command: ln -s /etc/apache2/sites-available/example.com /etc/apache2/sites-enabled/example.com.
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html/example.com/html
CustomLog logs/www.example.com-access_log common
</VirtualHost>
Now we have our Virtual Hosts configured, it's time to test. To start Apache 2, type /etc/init.d/apache2 start and fire up a browser and head to www.example.com:8080 (obviously, this will only work assuming you have a correct Virtual Host entry for a site that's DNS points to your server rather than www.example.com. Alternatively, you can add an entry in your /etc/hosts file of the client that you're browsing from to fool it into thinking it should be going to the IP address of your server).
If Apache 2 didn't start correctly, you will need to resolve some issues before you can proceed. Check your /var/log/apache2/error.log for details on any problems. In my own case, I have a number of sites running PHP with PostgreSQL/MySQL database backends, as well as a Zope/Plone instance that's being served from Apache using mod_rewrite. As a result, I had to install libapache2-mod-php4 and libapache2-mod-proxy-html. Additionally, I had to copy my existing php.ini file (/etc/php4/apache/php.ini) to /etc/php4/apache2/php.ini to make sure all my PHP settings were preserved. What's more, I also had to create symlinks from /etc/apache2/mods-available/proxy.load and rewrite.load to the /etc/apache2/mods-enabled directory. Once again, Apache 2 is modularizing its configuration layout. I see this a good thing (TM). My final step to resolve Apache 2 startup issues was to symlink /etc/apache/logs to /etc/apache2/logs, as that was my log file directory.
Assuming your testing has gone well, you're now ready to migrate to Apache 2.0! Let's stop Apache 2 if it's running (/etc/init.d/apache2 stop), and change the /etc/apache2/ports.conf to use port 80. Now stop Apache 1.3 with /etc/init.d/apache stop, and then fire up Apache 2 - /etc/init.d/apache2 start. You're done! Almost...
Our final clean up steps include making sure Apache 2 will start if the server is rebooted and making sure Apache 1.3 won't. To remove Apache 1.3 from our services that start on boot, simply remove the symlink in /etc/rc2.d (Debian's default runlevel). To do this, simply type rm /etc/rc2.d/*apache. You may also want to verify that /etc/rc2.d/*apache2 is in this directory and symlinked to /etc/init.d/apache2 - this will ensure Apache 2 is started on reboot, and should have been configured by Apt. In my case, I also had to restart Zope for the mod_rewrite module to work correctly.
Congratulations, and welcome to the world of Apache 2.0! Take a look around and enjoy...
This article orginally appeared on Linux.com

kharloss commented, on December 1, 2007 at 7:35 p.m.:
nice one. thanks