Virtual hosting and PHP for local develpment
marios
Status: New User - Welcome
Joined: 04 Apr 2005
Posts: 1
Reply Quote
I have just recently installed The Xampp package on win2k for localdevelopment purposes.Well in any case,I might stick with it.
For now I will just keep it to find out how much tweakable it is,and wheather it can be adapted in a manner that would allow,to change different things to an approximization of the live Server environment.
Let me first tell you that I came accross this forum just by accident,and that I have been reading the related posts alllready and that I learnd allready many things that I didn't know.I am also not expertized on these subjects and if you do allow me,I have a couple of questions.
1)As you have nticed from above I have Appache 2 httpd,XAMPP,and what I can tell for newbies this is perfect easy to install for no techies and no problems so far running as a service,I upgraded The Zendoptimizer to version 2.5.7.,and it shows up normally in the php.info page,I switched on a couple of modules and ok.(mod_rewrite),the most important one.I need the latter because I have to do some test runs with a CMS that relies on a .htaccess file,
so I have to use rewrite rules in ht.access per directory.No as probably knownin the Appache world mod_rewrite is a voodoo magic module,that havilly relies on advanced Perl.I am absolutely note axperienced with regular expressions,but it seems that whenever I put the appropriate .htaccess file in web root folder
the CMS installation procedure is not able to see it.(Note:I just open .htaccess with notepad if I need to )
Below you can see the contents of my .htaccess file as provided by the CMS software package:
:: Code ::

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) – [PT,L]

RewriteRule ^(.*) /index.php

Now,my question now is this:Which directives must go in to the httpd.conf file to get this to work.(one additional information towargs this problem.The CMS has a certain feature in the admin panel that allows you to switch between messy and different options of clean URL mode,so when you wan't to use that feature=clean it needs the .htaccess file else it needs to be eliminated.)
2.My second question is directly related to virtual host containers on XAMPP,the out of the box root directory of the Server is .htdocs and
the XAMPP admin panels are one directory level below.
One somebody want's to test a site in the deault root it wouldn't
work because there is already a folder named images,which mixes things up,so most logically I've put in there a couple of folders to test different variations of the CMS on par.No here is the point where I get stucked,because even though everything is accessable,
I was thinking that this is like having a subfolder on the webroot level and conclusively not what I intended,since one major requirement of the CMS is to be in webroot or in the root of avirtual container.So here goes question 2.Is that right as I descibe as above,and do I need virtalhost setup, where should I place then my webfolders,and do I need user and public_html directory,and how can I handle file permissions on windows(for example if I have an Image folder that need's chmod back to 775 from 777)
3.)from where in the apache installation can I find out if php(4.3.10) is running as CGI api or as moduleand in case of the first possibilty CGI.
How the .htaccess file need's to be modified in order to reflect this Server environment.
Excuse me for my many questions and many thanks for any info in advance.

with best rgrds,marios
Pl
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hi Marios, welcome to the forums, and thanks for taking the time to do some reading before asking.

I'm not going to try to cover all your questions, since there's certain things you want to get running before moving onto harder stuff like mod_rewrite.

First, in your Apache folder, there is a file called httpd.conf. In windows, this is located in program files/apache group/apache2/conf.

This is were your virtual directories are set up. I don't know how XAMPP sets this up, since I install my server components individually, but I'll assume it's similar.

At the end of the httpd.conf file, you will find this:

:: Code ::
#
# Use name-based virtual hosting.
#
NameVirtualHost *

##LOCALHOST##
<VirtualHost *>
   ServerName localhost
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/program files/apache group/apache2/htdocs"
</VirtualHost>

Or something like that. This is the default directory Apache will use if no other site is requested. The only use this has is to test your Apache install. I never use this for anything else. Once Apache is running, you need to set up the actual site virtual host data.

Note the first line: NameVirtualHost *

This tells Apache to process any request it gets no matter what the IP is, more or less.

Sometimes there are other things that have to be adjusted in the httpd.conf file, but probably not in XAMPP's case.

IMPORTANT ! ! !
MAKE A BACKUP COPY OF httpd.conf BEFORE PROCEEDING.

Setting up a virtual domain/site
Now you're ready to start. To make a new virtual domain, you need to do two things. First, tell Apache about it, by adding it under the localhost one:

:: Code ::
NameVirtualHost *

##LOCALHOST##
<VirtualHost *>
   ServerName localhost
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "c:/program files/apache group/apache2/htdocs"
</VirtualHost>

## Site 1 ##
<VirtualHost *>
   ServerName site1
   ServerAdmin webmaster@dummy-host.example.com
   DocumentRoot "d:/web_stuff/site1"
   <Directory "d:/web_stuff/site1">
      AllowOverride None
   </Directory>
   php_value include_path ".;d:/web_stuff/site1/includes"
   DirectoryIndex index.php index.html index.htm
</VirtualHost>


Save httpd.conf, and restart apache. The path above must be exactly like that, except of course it would be the correct path for your web development folder.

Restart Apache so it can load this new configuration information.

Update your hosts file
Now you have to tell your operating system to look for 'site1' in Apache, not the web. To do this, go to the following folder:
c:\winnt\system32\drivers\etc\
and open the hosts file in a real text editor. Do not use Notepad to work on system files, it's a bad idea. You can get a real text editor for free, there are several good ones out there, Crimson Editor is very nice, small, and lightweight. Turn off your Notepad and don't ever use it again for web based work, or any work for that matter.

In hosts, which has no extension, it's just called plain old 'hosts', which notepad doesn't like, it also doesn't like .htaccess, and always wants to add the 'txt' extension, which is another reason not to use notepad. The real reason though is that notepad will insert proprietary, and invisible, characters sometimes into your scripts, which will break them.

You will see the item:

127.0.0.1 localhost

Add the new site you've created, site1 to this line. You can have about 10-15 items per line, after that Windows has a bug and will fail to load the site, solution, just make a new line, like this:

127.0.0.1 localhost site1

Save it, then create a test page, put it in the site1 folder root, call it index.html, then go to your browser and type in this in the address bar: site1
and hit enter. If all went well, you should see your test page.

If you don't see your test page, and did restart apache after adding the site1 virtual directory, it's time to figure out the problem.

When to use .htaccess or httpd.conf?
When I do site development, I turn off htaccess processing on my local box, that's because my htaccess files contain server specific commands, such as include paths, document root paths, and so on.

Almost all commands you can run in htaccess you can also add in the virtual directory configuration. However, until you get your virtual directory stuff working, I wouldn't worry about trying to get more esoteric stuff like mod_rewrite working.

In the virtual directory in httpd, the AllowOverride None
statement is what tells apache to use .htaccess or not, setting it to none makes it not use .htaccess, which is a lot easier to work with for development purposes.
Back to top
zerofire
Status: New User - Welcome
Joined: 20 Apr 2007
Posts: 2
Reply Quote
Jeffd the man wants a xampp based information not apache based. They are slightly diffrent from each other. If you want to make a virtual server in xampp you need to modify .../xampp/apache/conf/extra/httpd-vhosts.conf to get the virtual hosts. However every time I tried working with it the pages kept showing up as forbidden.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours