While working on different website projects on localhost, I found it very difficult to manage the sites in single document root. Even it requires to remember and type long urls in browser. So I decided to setup virtual servers for each projects, it is very convenient when we, as web developers, have virtual server dedicated to each project we are working on. We don’nt need to remember the long urls for project, the project files dont get messed, we can put those wherever we want even on windows partitions. Hence, we get the improved manageability.
Fedora 9 has apache configuration directory in /etc/httpd. The main configuration file httpd.conf is in conf direcory. Other include files are in conf.d directory. We will configure vhost.conf file in conf.d directory, if this file is not there, create one. I will assume that the project directory named webproj1 is in home directory of user. Copy the following code in vhost.conf file.
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot /home/user/webproj1
ServerName webproj1.localhost
DirectoryIndex index.php
<Directory "/home/user/webproj1">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Make sure that the following line in httpd.conf is not commented. It will automatically include and load configurations from our vhost.conf file.
Include conf.d/*.conf
Now restart apache server. Run the following command as root to restart httpd.
/etc/init.d/httpd restart
While restarting httpd, selinux will prevent httpd to access webproj1 folder. To allow access to webpro1 folder, use chcon command as root.
chcon -t httpd_user_content_t webproj1/
Now again restart apache server and the virtual server should be available at 127.0.0.1.
COMMENTS
No Comments