0

I'm setting up a localhost and everything looks like it should work but whenever I go to site.local it loads the default Apache localhost page (It works!).

Here's a copy of my hosts file:

##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1    localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%1o0 localhost

#####
 DEV
#####
# SITE
127.0.0.1    site.local
::1          www.site.local

and my vhost:

<VirtualHost *:8080>
    ServerAdmin test@test.com
    ServerName site.local
    DocumentRoot "/Users/me/site"
    ErrorLog "/Applications/MAMP/logs/site.local-error_log"
    CustomLog "/Applications/MAMP/logs/site.local-access_log" common
    <Directory "/Users/me/site">
        Options Indexes FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

Things I've done to make sure it isn't a user error:

  • uncommented the line in the httpd.conf file to include my vhost file
  • used apachectl configtest to test my file (came back saying syntax OK)

Things to note:

  • I use port 8080 and 3307 for Apache and MYSQL
  • If I go to site.local:8080 it loads but doesn't render the elements as it should (instead loads the elements of the html in a list format)
  • this is off a FRESH install of MAMP
  • OS: OS X Yosemite version 10.10.5
  • MAMP Version: 3.5

I just don't see what's going wrong... any ideas?

UPDATE

localhost works as it should with port 80. 8080 = the default apache page, but 80 loads the site pages...

  • Can you post an screen shot of your browser with it on site.local:8080? – Allan Mar 8 '16 at 12:39
  • I can't no (not enough rep to upload one) - all it shows is a white page with 'it works!' in a h1 tag – TT12043205 Mar 8 '16 at 12:41
  • I'm not seeing a NameVirtualHost *:8080 directive prior to VirtualHost directive. – Allan Mar 8 '16 at 12:53
  • It's there (full vhost isn't posted) – TT12043205 Mar 8 '16 at 12:55
  • It would help if you posted that as well (use pastebin). Is your server configured to Listen on 8080 as well? – Allan Mar 8 '16 at 13:16
2

Based on your comment that when you go to site.local:8080 you get a white page with the words "It Works!" similar to the screen capture below

It Works!

What you are seeing is the webpage based on the global server configuration where the DocumentRoot is whatever default MAMP is set for.

You mention in your OP that

If I go to site.local:8080 it loads but doesn't render the elements as it should (instead loads the elements of the html in a list format)

Apache isn't going to render your webpage as a HTML list (unless you tell it to). More than likely what you are seeing is a directory listing similar to this:

Index Listing

You get that listing because of the line Options Indexes FollowSymLinks in your httpd.conf file. If you want to disable this, remove the word Indexes from that line and the listing will no longer show up.

Your Virtual Host Configuration

First, we need to understand how Apache handles virtual host requests. From the Apache documentation:

When a request arrives, the server will find the best (most specific) matching argument based on the IP address and port used by the request. If there is more than one virtual host containing this best-match address and port combination, Apache will further compare the ServerName and ServerAlias directives to the server name present in the request.

If you omit the ServerName directive from any name-based virtual host, the server will default to a fully qualified domain name (FQDN) derived from the system hostname. This implicitly set server name can lead to counter-intuitive virtual host matching and is discouraged.

If you notice, your host that is defined the global server configuration is the same as the virtual host.

This is probably where you are getting your error.

Now, my fix for this is a bit more involved initially, but infinitely more efficient because I try to avoid turing my machine into both a client and a server. I do all my development on a Mac with a Virtual Machine running my AMP server. This way I can mirror my production environment much closer and I don't have unnecessary services (like Apache and MySQL) running on OS X; they are all relegated to the VM. The VM has it's own IP, own server name, everything so when I point my browser to it, I know what results to expect.

I have a write up on how to install a FreeBSD VM on VirtualBox running on a Mac that has autostart enabled. If you are interested, I can share it with you.

  • I absolutely agree that VMs are the best approach. That is something that I think the Mac really does well with. If you just need a simple box to run a CMS or something, Homestead is probably the easiest and quickest way to do that. – bassplayer7 Mar 8 '16 at 17:27
  • Exactly...I, prefer to use VirtualBox with a FreeBSD host configured as close to what the hosting providers give you so there is little or no fixing of things when you try to upload your site to a production server. – Allan Mar 8 '16 at 17:38
  • it doesn't show the file structure, it shows the html but without any styling. And it isn't the MAMP default page it's showing, it's showing apache's (MAMP's page is a weird hub kinda page). I could use a VM but I shouldn't have to.. I can do this on Linux and Windows easily, os x is the only one that makes life difficult? (sorry if this seems ranty haha) – TT12043205 Mar 9 '16 at 9:40
  • Can you post your httpd.conf and the results to a shared folder like OneDrive, Google Drive or Dropbox? It's very hard to diagnose when you can see the code. – Allan Mar 9 '16 at 21:25
0

Preface:

  1. Executing apachectl configtest doesn't check /Applications/MAMP/conf/apache/httpd.conf for consistency but the default OS X Apache config file /private/etc/apache2/httpd.conf.

    You have to use /Applications/MAMP/Library/bin/apachectl configtest instead to check /Applications/MAMP/conf/apache/httpd.conf.

  2. The use of a fully qualified domain name in the form hostname.local is discouraged. These fqdns are reserved for Multicast DNS (mDNS). You may use .home, .development or .test.

Setup:

MAMP/Apache/hosts configuration:

/etc/hosts:

...
127.0.0.1       site.development
127.0.0.1       www.site.development
::1             site.development
::1             www.site.development

Apache port in MAMP: 8080 (WebStart disabled!)

Content of the file httpd-vhosts.conf

NameVirtualHost *:8080
...
<VirtualHost *:8080>
    ServerAdmin test@test.com
    ServerName site.development
    ServerAlias www.site.development
    DocumentRoot "/Users/me/site"
    ErrorLog "/Applications/MAMP/logs/site.development-error_log"
    CustomLog "/Applications/MAMP/logs/site.development-access_log" common
    <Directory "/Users/me/site">
        Options Indexes FollowSymLinks
        AllowOverride All
    </Directory>
</VirtualHost>

You may check your virtual hosts file with /Applications/MAMP/Library/bin/apachectl -S.

If you've set up your MAMP server properly and copied the default MAMP files index.php and MAMP-PRO-Logo.png to the folder /Users/me/site you will see the following "default" page:

MAMP website default start page

Entering http://localhost:8080/ in the browser will show the same page.

If you run no other instance of Apache (especially the default OS X Apache) you won't be able to connect to localhost:80 or site.development:80.


If you run another instance of Apache (e.g. started by launchd or invoked by sudo apachectl start you can connect to it by either entering localhost:80, site.development:80 or http://site.development:80. You will see the default Apache page:

enter image description here

If OS X Server is installed additionally you'll get to a "Welcome to OS X Server" page after entering localhost:80 even if Websites is disabled in Server.app:

enter image description here

  • the apachectl tests my MAMP one (I know this because I purposely created a bad vhost and it came back with the errors) - but aside from that I'll give this a go :) thanks – TT12043205 Mar 10 '16 at 9:05
0

index.html, info.php, index.py etc. reside under /var/www or /var/www/test or whatever you define in configuration. Look inside VM server whether UBUNTU or SUSE or whatever VMWare or VirtualBox and you cannot find /var/www. OS X doesn't play with open communities. There's no way you can make VM servers control browsers running on a Apple machine.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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