Search code examples
apache.htaccesslocalhostserverdocument-root

Change document root. Migrating from MAMP to AMPPS


I hope this does not seem like a stupid question: I have been using MAMP for several years, and what I love about it (as opposed to WAMP) is that I can open the app point the Web Server at any folder on my system and localhost will run as the root on that folder.

With AMPPS it seems everything is stored in www. So if I have lots of projects (which I do) I want to be able to write links to my assets as root based urls (for example):

 /css/main.css 

At the moment this will assume that www is the root, whereas I want

www/project1

www/project2

What is the best approach to handle this? And is there a way to make it more automated than having to change config every time I want to run the server.

CAVEAT (I am not particularly familiar with points 1 and 2):

  1. Can write a .htaccess file with rewrite rules (but will I need to change this per project, or can a single .htaccess file handle all of my projects, with multiple rules).

  2. Can I add multiple projects to httpd.conf? And does this require updates to the hosts file?

I can set base url tag in each project (although that seems really antiquated, and is not very portable when deploying files to another location).

What I really want to do is replicate the MAMP functionality of being able to point at any folder and run that as the root.

Apologies if this is a bit woolly.


Solution

  • OK, so I have most of this working.

    The issue to create an entry in the hosts file which is mapped to a name.

    So I can create a new domain in 'Add New Domain'

    I enter a url:

     /Applications/AMPPS/www/tmp
    

    And also add a domain name

     local.tmp
    

    Then run http://local.tmp in the browser. Now links to images, css and js will work if I set them as root links. Like:

     /css/main.css
     /js/site.js 
    

    The only issue is that I am using php includes for header and footer etc, and these have to be written relatively it seems.

    So:

     /common/header.php
    

    Won't work from inside a file, but that is OK I simply set that as relative (that is probably good practice anyway.

    Thanks to @Jigar for the pointers.