1

I'm using wamp server. My domain for my all projects is http:localhost/

The projects are in subfolders. For example: http:localhost/project-a/

I would like to set http:localhost/project-a/ as project domain so that I can easily manage relative paths.

Whenever i'm using relative paths or server URIs, i need to include the subfolders in relative paths or others for local server and remove them when transferring to live servers. these are very painful when i'm frequently updating scripts for many projects.

I guess that I can set them as domain using apache configuration. I'm not sure how.

1 Answer 1

3

In your local hosts file, define the following:

127.0.0.1 projecta.example.com

Then, using Apache's virtual host facility, define a virtual host for that domain:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/www/project-a/public_html"
    ServerName projecta.example.com
    <IfModule env_module>
        SetEnv CanonicalName projecta.example.com
    </IfModule>
    ErrorLog "/logs/project-a/apache_error.log"
    CustomLog "/logs/project-a/apache_access.log" combined
    <IfModule rewrite_module>
        RewriteLog "/logs/project-a/apache_rewrite.log
        RewriteLogLevel 4
    </IfModule>
</VirtualHost>

<Directory "/www/project-a/public_html">
    Options FollowSymLinks Includes
    AllowOverride all

    Order Allow,Deny
    Allow from all
</Directory>

... or something to that effect compatible with your local setup. See the Apache Virtual Host documentation for help in setting up a virtual host.

What you end up with is projecta.example.com resolving to the root of the "server" (virtual server, in fact) that "hosts" the project. You will then cease using http://localhost/project-a as the URL, and start using http://projecta.example.com (or whatever URL you devise). You might need to restructure your current directories a bit, since it appears that you are running your local test environment all from one root server.

Note that the above is not a complete solution, but intended to get you started. There are probably things in the above specific to my set-up that you will not need, or will need to change. There will be other things you'll need to configure/enable in your Apache server to get it all working together properly--some of it dependent on your local environment and/or requirements.

1
  • 2
    Note that questions related specifically to setting up virtual hosts or otherwise configuring Apache might best be asked over on Super User, Webmasters or Server Fault, depending on the nature of the question. I think your question, here, is relevant for StackOverflow because it deals with setting up a programmer's test environment.
    – RobertB
    Dec 31, 2012 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.