开发者

How to develop for multiple websites in parallel?

If it makes any difference, I am using Xampp on windows for my web server & PHP (all web pages are PHP based, some include JS, all include CSS file).

The point is that I have a local directory which represents http://localhost and if I want to develop multiple websites I have to copy them all under that directory.

And since most of them have CSS, images and many have JS, I end up with the images/JS/CSS for all websites mixed in to http://localhost/images, http://localhost/css, etc.

And when I come to upload them it's a nightmare. I am worried that I might forget to upload some vital files, or to upload files that do not belong to the site.

What's the solution?

In my case, all files are PHP, so should I tw开发者_如何学Ceak $_SERVER['DOCUMENT_ROOT'] but I wonder what the general approach by professional web designers is.


You can do this with virtual hosts. See this tutorial here for how to set up virtual hosts on windows with xampp.

Then, you can emulate host names by editing your hosts file. You can add fake names that refer to your site. I like to use the .tst top level domain which is not real so it won't interfere with anything. Here's a tutorial for Windows on how to edit your hosts file (not sure what version of windows you're using?):

So, if you had two sites, let's call it site1 and site2, you set up two virtual hosts, call them site1.tst and site2.tst. Add the virtual host definitions in xampp, and then add those names to your hosts file to refer to 127.0.0.1 (localhost). This allows you to go to http://site1.tst/ and http://site2.tst/ in your browser.


Make directorys www/Project1 , www/project2 etc and put the contents likewise.. Now the point is that if you want to take the first project, go to http://localhost/project1. All th php files, css, images etc for project1 will be inside the folder www/Project1.. Similarly your project2 will be accessed through http://localhost/project2


If you want to set up VirtualHosts, so you can visit http://foo.local or http://bar.local (example names of websites/projects you're working on) on your local machine, find your Apache configuration file (named httpd.conf in Apache1.X or apache2.conf in Apache2.X). This file tells you where your virtual hosts live (usually with an Include directive on the bottom of the file).

Let's assume the project you're working on is foo.com. You'll need to add this to either the bottom of your httpd.conf/apache2.conf files or as a new file in your virtual hosts directory (just name it something appropriate like foo.com.conf or foo.local.conf or something).

<VirtualHost *:80>
    ServerAdmin webmaster@foo.local
    ServerName foo.local
    DocumentRoot /where/your/website/files/are
    ErrorLog /where/your/logs/go/foo.local-error_log
    <Directory /where/your/website/files/are>
        Options FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

(where "/where/your/website/files/are" is the directory where your current project is, where "/where/your/logs/go/foo.local-error_log" is any directory/file that you'd like to store your logs in, where the location in your <Directory> directive is the same as the location of your DocumentRoot)

Then you need to restart Apache. If it complains, look at the error and try to fix it based on what it says.

Then you need to add a fake host to your hosts file so that when you visit http://foo.local in your browser it points to your local computer. The hosts file is /etc/hosts in Linux/BSD/OS X/Solaris or C:\WINDOWS\system32\drivers\etc\hosts in Windows. You'll need to edit this file as root / with sudo or pfexec (in BSD/Linux/Solaris/OS X) or as an Administrator in Windows.

Add the following line:

127.0.0.1 foo.local

To the bottom of this file (or anywhere that makes sense, as long as it's on it's own line).

Here's some more info to get you going:

http://httpd.apache.org/docs/2.0/mod/core.html#virtualhost


You can set up a Virtual Host for each of your local websites. With this solution you don't even have to copy your sites to your xampp/htdocs folder.

Read this article, it covers everything:
http://ailoo.net/2008/07/set-up-multiple-virtual-hosts-on-xampp-for-windows/

You have to edit 2 files, and you're good to go.


Use virtual hosts. And set up a local host entry for a domain name for each site like example.local

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜