Zend Framework Testing - Day 3 - VirtualHost
by mr. H8ers6th
Sep
2008
Setting up my Linux desktop for virtual hosts.
After watching this: Zend Development part 1. I decided I wanted the same setup. So for this, I decided to setup my server for virtual hosts.
First thing I did was open up my hosts file, in fedora this is located at /etc/hosts. And added 127.0.0.1 “tab” “tab” zendtest, “tab” being the tab key on your keyboard. You could just use a space if you really don’t care how it looks.
I then opened up my httpd ( located on fedora at /etc/httpd ) directory as root and added a folder virtualhosts with a file inside called v.hosts.conf, I know there are many ways I could have done this ( i.e. kept it in httpd.conf ), but I chose this method instead. Now when I want to add a virtual host I just have to edit /etc/httpd/virtualhosts/v.hosts.conf. So in my conf directory ( /etc/httpd/conf/ ) I made a new file called httpd.conf.backup and copied the contents of httpd.conf to it, just in case I accidentally screw something up. and then I proceed to butcher my httpd.conf file.
I opened up my httpd.conf file and right under the end of your default directory settings ( i.e. <Directory “/var/www/html” > “bunch of configurations” </Directory> ) add this
<Directory "/var/www/sites/*" >
Options FollowSymLinks
AllowOverride All
</Directory>
After doing that I went all the way down to Section 3 and selected everything in that section and cut it and pasted it to v.hosts.conf. I replaced what was there with ” Include virtualhost/*.conf “, of course minus the quotation marks. I used *.conf just in case I wanted to make different conf files for different virtualhosts with different ip’s or names. So now my httpd.conf file would include the virtualhost/v.host.conf or any .conf file when it was restarted.
now time to butcher the v.host.conf file. I uncommented the NameVirtualHost and added 127.0.0.1 like this
NameVirtualHost 127.0.0.1
I then proceded to butcher the default virtual host like this
<VirtualHost 127.0.0.1>
DocumentRoot "/var/www/html"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerAdmin admin@zendtest
DocumentRoot "/var/www/sites/zendtest/public_html"
ServerName zendtest
ErrorLog /var/www/sites/logs/error_log
CustomLog /var/www/sites/logs/access.log common
</VirtualHost>
You don’t have to have a ServerAdmin, the default in your httpd.conf will be used if this is missing.
DocumentRoot are the place where http://zendtest/ files are, in this case /var/www/sites/zendtest/public_html.
Servername is set to where your website will be located in the browser, but just for your local machine i.e http://zendtest/.
ErrorLog and CustomLog are optional too. If you don’t have these set they will go to the default, which in my case is logs/error_log and logs/access_log. If you do have these enabled you will need to create a folder called logs in your /var/www/sites/zendtest/ directory. I think this is a better way of making the virtualhost with error logs saves from reading though your default error logs.
Then close this file. If you want to start apache now you can, but apache will not start. This is because I don’t have the directory structure that the Document Root is asking for. So I proceed to /var/ww directory and make a new folder called sites and I open the folder and add zendtest and then open that folder and make public_html or I just do this in a termial using su and make the whole directory structure like this:
[bigus_dickus@localhost ~]$ su
Password:
[root@localhost bigus_dickus]#mkdir -p /var/www/sites/zendtest/public_html
#you could also use mkdir -p /var/www/sites/zendtest/logs to make your log folder
Terminal commands are faster. The -p or –parent, if the file exists then it will not be overwritten, my user name is not bigus_dickus and –help behind any command is usually helpful.
Now when you restart httpd in the services or by command, my command with fedora 8 would be:
[root@localhost "yourusername"]# /sbin/service httpd restart You’ll goto http://zendtest/ and in my case see the fedora apache page.
Now you cannot write in these files without being root so you can either open Krusader- root mode and change the folder proerties by GUI or you can type in the terminal this:of course with “yourusername” as your user name. I do this because I am the only real user of this computer and I have configured my user name in the root group. If I am logged into my computer as said user, then I can edit anything in the sites directory without having to login as root user.
[root@localhost "yourusername"]# chown “yourusername” -R /var/www/sites
Alright now that the virtual host is setup, I will get into eclipse.

