Welcome to WebmasterWorld Guest from 3.228.24.192

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Apache Virtual Hosts Configuration Issue (WAMP)

Problem referencing CSS files and other folders

     
3:16 am on Dec 6, 2016 (gmt 0)

New User

joined:Dec 4, 2016
posts: 5
votes: 0


  • Win 10 64-bit (localhost)
  • WampServer 3.0.6 64-bit
  • Apache Version 2.4.23
  • PHP Version 5.6.25
  • MySQL Version 5.7.14

    As the title suggests, I'm attempting to setup Apache Virtual Hosts on a WAMP installation. Everything is fine except the index page doesn't render CSS files in separate folders. For instance, c:/wamp/www/myproject/css (style.css), when I type in http://localhost/myproject, the content is displayed, but not the CSS file I'm including in index.php by way of <link rel="stylesheet" type="text/css" href="css/style.css">.

    I know it has something to do with the relative links on the local machine but I've been through about 10 tutorials and I've modified httpd.conf, httpd-vhosts.conf, hosts, and httpd-vhosts.conf a lot of different ways, stopped/started Wamp every time, cleared the cache. I just can't make my index file render the CSS. I've followed videos and tutorials to the letter but no joy.

    Is there anything else I can look at or try out? Thanks in advance.

    [edited by: phranque at 3:21 am (utc) on Dec 6, 2016]
    [edit reason] unlinked url [/edit]

  • 3:31 am on Dec 6, 2016 (gmt 0)

    Administrator

    WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

    joined:Aug 10, 2004
    posts:11846
    votes: 242


    what request is your server getting and what was the response?
    3:45 am on Dec 6, 2016 (gmt 0)

    Junior Member from GB 

    10+ Year Member Top Contributors Of The Month

    joined:Oct 16, 2002
    posts:182
    votes: 3


    What happens when you try to visit the css file directly?
    http://localhost/myproject/css/style.css
    Is it served?

    Perhaps you could post the relevant parts of your config files to help with diagnosis.
    6:33 pm on Dec 6, 2016 (gmt 0)

    Senior Member from US 

    WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

    joined:Apr 9, 2011
    posts:15889
    votes: 876


    For instance, c:/wamp/www/myproject/css (style.css), when I type in http://localhost/myproject, the content is displayed, but not the CSS file I'm including in index.php by way of <link rel="stylesheet" type="text/css" href="css/style.css">.

    Have you changed any DirectorySlash settings? (Should be the same in 2.2 and 2.4) By default,
    http:///localhost/myproject
    would redirect to
    http:///localhost/myproject/
    (with final slash) which in turn would serve content from
    /myproject/index.html
    unless you've set a different extension in a DirectoryIndex directive. And this, in turn, would lead a local link (no leading slash) to serve content from the /myproject/ directory.

    Have a closer look at your mod_dir settings.
    10:24 pm on Dec 6, 2016 (gmt 0)

    New User

    joined:Mar 17, 2016
    posts: 14
    votes: 3


    I just can't make my index file render the CSS


    If you check the network traffic in the browser for your CSS file then the URL-path the browser is trying to use to access the file should provide a clue as to what is happening.


    I'm attempting to setup Apache Virtual Hosts ... //localhost/myproject


    Aside: If you are then you shouldn't be setting it up so your project (ie. website) is in a subdirectory off the localhost. Is your production site going to be in a subdirectory? The advantage of using a VirtualHost is that you can use any host (ServerName) and DocumentRoot you want.
    12:10 am on Dec 7, 2016 (gmt 0)

    Senior Member from US 

    WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

    joined:Apr 9, 2011
    posts:15889
    votes: 876


    you shouldn't be setting it up so your project (ie. website) is in a subdirectory off the localhost

    Good point. I don't know about WAMP, but assuming it works the same as MAMP, the default is
    localhost/
    which would be exactly equivalent to
    example.com/
    as far as your browser is concerned. In MAMP, the default location for your site files is in the same physical directory as the MAMP installation (i.e. deep in the bowels of some directory you would never normally visit), but this is easy to change.

    If you've only got one domain, you shouldn't have to mess with virtual hosts at all; WAMP will do it for you. (In the case of MAMP, if you do have multiple domains, you have to either pay for the big-budget version, or manually edit your computer's hosts file along with the VirtualHost info and possibly use a different port number.)
    11:13 pm on Dec 10, 2016 (gmt 0)

    New User

    joined:Dec 4, 2016
    posts: 5
    votes: 0


    Thank you for all of your replies, though they've forced me to rethink how this should all work.

    To start from scratch, I reinstalled WampServer. As mentioned by w3dk and lucy24, I am able to create an index.html file that recognizes my CSS folder and style.css via "file:///C:/wamp64/www/index.html" or "http://localhost/index.html". That being said, Wamp automatically includes an index.php entitled Server Configuration. Check out the following screenshot: [snipped].

    I assume the Server Configuration page is there for a reason. But what if I need my homepage to be index.php instead of index.html? I'd no longer have access to the Server Configuration controls. That's the first issue...can I just rename the index.php file so I can still access the controls if my home page is index.php?

    In my web hosting account, let's say - mywebsite.com, I have a sub-directory that points to a domain name called myotherwebsite.com, the latter just being a sub-directory in the public_html folder under mywebsite.com. So for WampServer, my goal is to create content for mywebsite.com (http://localhost) and also the content for the sub-directory - myotherwebsite.com. This is the second issue...wouldn't it be necessary to create a virtual host for the sub-directory?

    I hope that makes some sense. I appreciate all of the replies so far.

    [edited by: phranque at 2:54 am (utc) on Dec 11, 2016]
    [edit reason] see forum Charter [/edit]

    2:57 am on Dec 11, 2016 (gmt 0)

    Administrator

    WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

    joined:Aug 10, 2004
    posts:11846
    votes: 242


    I assume the Server Configuration page is there for a reason. But what if I need my homepage to be index.php instead of index.html? I'd no longer have access to the Server Configuration controls. That's the first issue...can I just rename the index.php file so I can still access the controls if my home page is index.php?

    i would not have that config page in any way publicly accessible.
    put it in a directory that requires some type of authentication.
    6:36 am on Dec 11, 2016 (gmt 0)

    Senior Member from US 

    WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

    joined:Apr 9, 2011
    posts:15889
    votes: 876


    put it in a directory that requires some type of authentication.

    More authentication than is provided by being physically located on your personal computer and nowhere else?

    But what if I need my homepage to be index.php instead of index.html?

    Here I would do hands-on experimenting. If you park the Server Configuration page somewhere else (don't delete it, of course), or rename it, and then put in your own index.php page, does everything continue to work normally? Seems like the page would only be needed if you're changing something. (Here I can't compare, because MAMP works as an application with its own Preferences, independent of the quasi-server function.)

    my goal is to create content for mywebsite.com (http://localhost) and also the content for the sub-directory - myotherwebsite.com. This is the second issue...wouldn't it be necessary to create a virtual host for the sub-directory?

    Yes, probably--and since it's under your own control, you certainly don't need to use the asymmetrical "primary/addon" configuration just because that's how your current host does it.

    Someone else will know for sure, but I think that officially WAMP/MAMP/whatever-Linux-calls-their-version is only supposed to work with one site at a time. On my version, I had to do three things:
    -- tell MAMP to use port 80 instead of its default 8888 (I have no idea why, it just refuses to work on multiple hosts otherwise);
    -- go into Terminal to edit my computer's hosts file to add more names (after much hunting, I found an online article that explained how in words of two syllables, which I need when dealing with Terminal);
    -- add VirtualHost sections to the MAMP config file.

    :: memo to self: send MAMP some ### money, because they certainly deserve it ::