• Resolved LHAJACK

    (@lhajack)


    So I am trying to run two different sites that I am working on currently locally on MAMP.

    As MAMP draws the source files from the htdocs folder, I have two folders within there, each containing a separate WP install (site-1 and site-2). I also, have separate databases set up for each site in the phpMyAdmin area of the MAMP/local server, and each site’s config file is set up to reference the proper database.

    When I want to switch back and forth between the two sites, I have to change the Apache Document root from:
    /Applications/MAMP/htdocs/site-1
    to
    /Applications/MAMP/htdocs/site-2
    and vice-versa.

    This works just great… on the back end. When I do this, I am able to go into WP for each site, and all of the proper information (pages, plug-ins, blog posts, etc) is all there for each site.

    But when I go to view the site in the browser site-2 shows just fine, but for some reason that I have yet to figure out, site-1 results in 404 errors and/or blank pages.

    Before I put in site-2, site-1 worked just fine. But now, as I said, I am no longer able to view the site, though I can still edit everything through WP.

    Any clue why this is happening, and how I can fix it?

Viewing 11 replies - 1 through 11 (of 11 total)
  • You should not need to be changing Apache root at all,
    You can install multiple instances of any type of site in htdocs ; assuming u installed it correctly

    Moderator keesiemeijer

    (@keesiemeijer)

    Thread Starter LHAJACK

    (@lhajack)

    @ Root
    If I don’t specify the document root to the site-1 or site-2 folder through the Apache preferences, nothing works correctly when there are two sites in the htdocs folder.

    On the front end, site-1 still displays as blank pages or 404 errors and site-2 loses all of it’s CSS on the home page, and all of the links/subpages just bring you to a directory listing of the files in the htdocs folder. Plus WP doesn’t come up anymore at all for either site and trying to get to the wp-admin results in a 404 error.

    Wouldn’t be surprised if I did something incorrectly on the installation, but I can’t tell what. And what confuses me further is that WP is able to find everything in the dashboard/wp-admin area, but everything is missing when the browser tries to display it.

    Thread Starter LHAJACK

    (@lhajack)

    @keesiemeijer

    Thanks for the suggestion. I’ll look into that and see if I can get ti working.

    Thread Starter LHAJACK

    (@lhajack)

    So, I have been trying to get the virtual hosts to work, but no luck so far, and after looking a bit more into this, I think it’s just that I am using the free version of MAMP as opposed to MAMP Pro. From what I gather, one of the incentives for upgrading to Pro is it has the ability to support multiple sites/virtual hosts whereas the free one does not.

    I could be wrong though. I am often enough. If it is possible to do on the free version I would appreciate it if someone could enlighten me, otherwise, I’ll have to wait until the boss approves the upgrade and try it again.

    Moderator keesiemeijer

    (@keesiemeijer)

    No it’s possible on the free version. I do it myself.

    Edit the host file and the httpd.conf and flush the dnscache. Can you show us what you put in these files? Make sure you set Mamps ports to the default Apache and MySQL ports. maybe you need to make some changes in wp-config?

    Thread Starter LHAJACK

    (@lhajack)

    Ok, well here’s what I’ve got/tried, and maybe someone sees what I’m missing/doing wrong. (Sorry a bit long here)

    Attempt 1: On this one I tried using the ports and settings that worked before with one site in the MAMP preferences and working based off of that.

    On this try all of the source files for Site #1 were contained in /Applications/MAMP/htdocs/site-1
    Files for Site #2 were in /Applications/MAMP/htdocs/site-2

    I have a database set up for each site in phpMyAdmin.

    MAMP settings: (these are what MAMP is set to when I click “Reset MAMP ports”)

    Apache Port: 8888
    MySQL Port: 8889
    Apache Document Root : /Applications/MAMP/htdocs

    Site #1 WP_Config Settings:

    /** The name of the database for WordPress */
    define('DB_NAME', 'site-1');
    
    /** MySQL database username */
    define('DB_USER', 'user);
    
    /** MySQL database password */
    define('DB_PASSWORD', 'password');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');

    Site #2 WP_Config Settings:

    /** The name of the database for WordPress */
    define('DB_NAME', 'site-2');
    
    /** MySQL database username */
    define('DB_USER', 'user);
    
    /** MySQL database password */
    define('DB_PASSWORD', 'password');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');

    This is what I added in the host file:

    127.0.0.1 localhost
    127.0.0.1 localhost site-1.dev
    127.0.0.1 localhost site-2.dev

    And this is what I put into the httpd.conf file

    NameVirtualHost *
    <VirtualHost *>
    DocumentRoot "/Applications/MAMP/htdocs"
    ServerName localhost
    </VirtualHost> 
    
    <VirtualHost *>
    DocumentRoot "/Applications/MAMP/htdocs/site-1"
    ServerName site-1.dev
    <Directory "/Applications/MAMP/htdocs/site-1">
        AllowOverride All
    </Directory>
    </VirtualHost>
    <VirtualHost *>
    DocumentRoot "/Applications/MAMP/htdocs/site-2"
    ServerName site-2.dev
    <Directory "/Applications/MAMP/htdocs/site-2">
        AllowOverride All
    </Directory>
    </VirtualHost>

    Then I rebooted…

    No go. Browsers are unable to find the servers.

    Then, after copying the source files into Users/user_name/Sites I tried again with the following settings:

    MAMP settings: (these are what MAMP is set to when I click “Set to default Apache and MySQL ports”)

    Apache Port: 80
    MySQL Port: 3306
    Apache Document Root : /Applications/MAMP/htdocs

    WP_Config Settings: Nothing changed here.

    host file: Nothing changed here.

    httpd.conf file:

    NameVirtualHost *:80
    <VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs"
    ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
    DocumentRoot "/Users/user_name/Sites/site-1"
    ServerName site-1.dev
    <Directory "/Users/user_name/Sites/site-1">
        AllowOverride All
    </Directory>
    </VirtualHost>
    <VirtualHost *:80>
    DocumentRoot "/Users/user_name/Sites/site-2"
    ServerName site-2.dev
    <Directory "/Users/user_name/Sites/site-2">
        AllowOverride All
    </Directory>
    </VirtualHost>

    Rebooted and… still can’t find the servers.

    Then I just started throwing things at the wall seeing if anything stuck. Like using the MAMP ports from the first attempt with the httpd.conf settings from the second and different things like that, but no luck still.

    I’ve been going at this awhile now and seem to be making no progress.
    Anyone see my mistake?

    Moderator keesiemeijer

    (@keesiemeijer)

    First thing I see, set DB_USER and DB_PASSWORD to root for both sites

    /** MySQL database username */
    define('DB_USER', 'root');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'root');
    
    /** MySQL hostname */
    define('DB_HOST', 'localhost');

    is this the database you set up in phpmyadmin?

    define('DB_NAME', 'site-1'); (site-1 and site-2)

    the ports when clicking Preferences > Ports > Set to default Apache and MySQL ports are:
    Apache: 80
    MySQL: 3306

    My sites don’t live in the /Applications/MAMP/htdocs
    but in a folders:
    /Users/[My User Name]/Sites/site-1
    /Users/[My User Name]/Sites/site-2

    they don’t have to live in the:
    /Applications/MAMP/htdocs

    Moderator keesiemeijer

    (@keesiemeijer)

    also change this:

    127.0.0.1 localhost
    127.0.0.1 localhost site-1.dev
    127.0.0.1 localhost site-2.dev

    to this:

    127.0.0.1 localhost
    127.0.0.1 site-1.dev
    127.0.0.1 site-2.dev

    Thread Starter LHAJACK

    (@lhajack)

    Thanks for the help. The username and password were already ‘root’ I just changed them here (along with the site names) to be generic and also to make it clear what db/directory/etc was associated with which site.

    So this was kind of working for a while after re-installing MAMP, and doing fresh installs of WP and then changing:

    127.0.0.1   localhost
    127.0.0.1   localhost site-1.dev
    127.0.0.1   localhost site-2.dev

    to

    127.0.0.1 localhost
    123.0.0.1   site-1.dev
    127.0.0.1   site-2.dev

    and taking the quotations from the document root paths in the httpd.conf file to have:

    NameVirtualHost *:80
    
    <VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs"
    ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
    DocumentRoot /Applications/MAMP/htdocs/site-1
    ServerName local.site-1.dev
    <Directory "/Applications/MAMP/htdocs/site-1">
        AllowOverride All
    </Directory>
    </VirtualHost>
    
    <VirtualHost *:80>
    DocumentRoot /Applications/MAMP/htdocs/site-2
    ServerName local.site-2.dev
    <Directory "/Applications/MAMP/htdocs/site-2">
        AllowOverride All
    </Directory>
    </VirtualHost>

    For a short time I was able to view both sites through the browser and access both sites in WP. The only problem I was experiencing during this time, was for site-2– after publishing/updating posts and pages or changing certain settings, a blank page would load instead of the same WP page saying “Your post has been updated.” That was acceptable. I could still do everything I needed to do.

    But then I tried to add a third site into the mix. This is when things reverted back to problemland. Now site-3 worked fine, both in WP and when viewing the site. But now site-1 was accessible on the backend through WP, but I couldn’t view the actual site (it just loads a blank page, no errors), and site-2 wasn’t accessible through WP (just loads a blank page, no errors), but I can view that site through a browser.

    After some digging around and checking error logs I was able to find that the was an extra character/typo in my functions.php files that seemed to be tripping the sites up. Deleted that, and now everything seems to be in working order, at least for the time being.

    Thanks again for all of the help.

    Try this video. It worked for me and was easy.

    https://www.macappguide.com/mamp/

    I actually have my sites in my
    homefolder/sites/site1
    homefolder/sites/site2

    I have my MapPro servers as
    localhost
    localhosttwo

    This so worked!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Running Multiple Local Test Sites on MAMP’ is closed to new replies.