Welcome Guest, Not a member yet? Register   Sign In
virtualhost woes
#1

[eluser]Dunmail[/eluser]
I've a CodeIgniter site up and running on localhost. If I try and access it from another machine on my local network I get a 404 message.

I've a virtualhost set up in httpd-vhost.conf like this:

Code:
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Users/dunmail/Sites/myapp-dev"
    ServerName  myapp-dev
    <Directory /Users/dunmail/Sites/myapp-dev>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

My .htaccess file looks like:

Code:
Options +FollowSymLinks
rewriteEngine on

#RewriteBase /myapp-dev/

RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L,QSA]

It doesn't matter if I uncomment the RewriteBase directive, I get the same result. If I uncomment the second RewriteCond directive then I get a PATH_INFO warning on the front page of the site referring to

Code:
basename($_SERVER["PATH_INFO"])

This doesn't appear on any other page on the site even though the line of code that it is on is in a footer template that is used on every page. The site does work on localhost without this RewriteCond directive.

There are no errors in apache's error_log file.

If I change httpd-vhosts.conf to

Code:
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Users/dunmail/Sites"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/dunmail/Sites/myapp-dev"
    ServerName  myapp-dev
    <Directory /Users/dunmail/Sites/myapp-dev>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>

then the home page appears as bare bones html but no links work - they are all of the form: '/contact'. Also the page has no styling as the link to the stylesheet also doesn't work. In this mode I can go directly to the pages by typing the URI in to the address bar.

The addresses don't appear to be rewritten correctly for the remote machine as they are "192.168.1.4/contact" rather than "192.168.1.4/myapp-dev/contact". Modrewrite is enabled on the server as I use it elsewhere in non-codeigniter projects.

I'm missing something obvious here :-(
#2

[eluser]TheFuzzy0ne[/eluser]
First of all, I am by no means an expert on this subject, but I have had a fair amount of experience with troubleshooting these kinds of problems on my own server.

As such, some of the information I supply may not be 100% correct, so please do not take what I say as gospel. However, I'm hoping it might give you some more ideas about where to go from here.

[quote author="Dunmail" date="1362849883"]I've a CodeIgniter site up and running on localhost. If I try and access it from another machine on my local network I get a 404 message.[/quote]

I'm assuming you're running XAMPP?

[quote author="Dunmail" date="1362849883"]
My .htaccess file looks like:

Code:
Options +FollowSymLinks
rewriteEngine on

#RewriteBase /myapp-dev/

RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
[/quote]
.htaccess files can be a bit of a pain, because servers can interpret things differently.

You shouldn't need to specify the RewriteBase, and if you do, it probably should just be '/', because myapp-dev is set as being the document root in your vhosts file.

Your rewrite rule *might* need to be changed to one of the following:
Code:
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [L]

I've ditched the QSA, because I've no idea what it does, and I don't have it in my .htaccess file (which works).

[quote author="Dunmail" date="1362849883"]
RewriteCond directive then I get a PATH_INFO warning on the front page of the site referring to

Code:
basename($_SERVER["PATH_INFO"])

This doesn't appear on any other page on the site even though the line of code that it is on is in a footer template that is used on every page. The site does work on localhost without this RewriteCond directive.
[/quote]

That may be because it's not being set correctly when there's no path info being passed to the server. By that, I mean that you're calling index.php with no arguments.

[quote author="Dunmail" date="1362849883"]
If I change httpd-vhosts.conf to

Code:
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Users/dunmail/Sites"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Users/dunmail/Sites/myapp-dev"
    ServerName  myapp-dev
    <Directory /Users/dunmail/Sites/myapp-dev>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
</VirtualHost>
[/quote]

I'm not actually sure that localhost is a valid server name. I would recommend you make something up, such as myapp.dev and use that. You'll then need to add an entry to the hosts file on both machines, to map it to the correct IP address, then you can use a domain name instead of an IP address. It will also help if you ever decide to run multiple Web sites on that machine.

[quote author="Dunmail" date="1362849883"]
then the home page appears as bare bones html but no links work - they are all of the form: '/contact'. Also the page has no styling as the link to the stylesheet also doesn't work. In this mode I can go directly to the pages by typing the URI in to the address bar.

The addresses don't appear to be rewritten correctly for the remote machine as they are "192.168.1.4/contact" rather than "192.168.1.4/myapp-dev/contact". Modrewrite is enabled on the server as I use it elsewhere in non-codeigniter projects.
[/quote]

I think it's your .htaccess file that's messing this up for you. I think renaming it to something else (so that it doesn't get parsed anymore), will be a good starting point. Then you can fix your XAMPP problem with the .htaccess file out of the equation. Since .htaccess files (in my experience) are kind of volatile, it make sense to continue without it so as to avoid complications.

What OS are you running your server on?

[quote author="Dunmail" date="1362849883"]
I'm missing something obvious here :-(
[/quote]

It's certainly not obvious to me, I can tell you that much. Smile
#3

[eluser]Dunmail[/eluser]
Thanks for your response.

Should have said:

Running Mac OS X Lion. Not running XAMP but the default apache server and PHP with an installed MySQL. I had this setup on Snow Leopard then upgraded so have stuck with it.

I've tried the variations on the htaccess rule.

Just tried adding a simple project, basically a file with a call to phpinfo() in it. Put the file (index.php) in a folder - /Users/dunmail/Sites/vtest. Added a VirtualHost block to httpd-vhosts.conf like:

Code:
<VirtualHost *:80>
    DocumentRoot "/Users/dunmail/Sites/vtest"
    ServerName   vtest.dev
</VirtualHost>

No .htaccess file so that isn't in the way.

Same results - works on the local machine but not when I try to access it from another machine (actually an iPad).
#4

[eluser]TheFuzzy0ne[/eluser]
A couple more shots in the dark.

Could it be an issue with your firewall?

Do you use FastCGI? If so, setting cgi.fix_pathinfo to 1 might help.

Do you use PHPMyAdmin? Does that work as you'd expect?
#5

[eluser]TheFuzzy0ne[/eluser]
One more thing that's just occurred to me... Try setting up your virtualhost on another port and seeing if that makes any difference.

EDIT: Sorry, ignore that. I was thinking about the 404 error...
#6

[eluser]Dunmail[/eluser]
I've just installed MAMP, generally using the given defaults though I've set the ports to the usual defaults for apache and mysql.

My phpinfo "site" works locally but I can't access it from other machines on the network.

My codeigniter site still doesn't work.
#7

[eluser]TheFuzzy0ne[/eluser]
It certainly sounds like there's some external factor somewhere. I can't help thinking it's your firewall (although that wouldn't explain why it won't work on localhost). Are your other, non-CodeIgniter sites still working?

My only suggestion would be to ditch MAMP and consider looking into virtualisation. It's not ideal, but something is definitely not right, and it certainly doesn't seem like something obvious.
#8

[eluser]Dunmail[/eluser]
I *think* I know what the problem is. It's not mentioned in many places but the development machine also needs to be a DNS server so that requests to "my app-dev" get routed to the right place.

The inbuilt Apache server can handle requests to "192.168.1.4/~dunmail/Sites/myapp" which for now is good enough. Not sure why virtualHosts doesn't just piggyback on to this.
#9

[eluser]TheFuzzy0ne[/eluser]
I disagree. DNS should not be necessary unless you're hosting your server using a domain name, and it's externally accessible. DNS records basically help map a domain name to an IP address. In your case, you have your hosts file to map the domain name to the IP address. The server will receive the domain name, and map it to the appropriate directory (as per your hosts file).

Yes, some local networks use DNS, but that's to save them from having to update the host files on 50+ PCs. Smile

If you're using Firefox on your Mac, you can download an addon called Firebug. Firebug is extremely useful for developers. One of the (many) things it can do, it show you how long each request for a resource took, and what the response was. This might help you see where things are going wrong.

I'm 90% certain that DNS will not solve your issue.
#10

[eluser]Dunmail[/eluser]
Shouldn't I know - a bit of clutching at straws on my part.

If I turn off virtual hosts and access the site using "IP address/folder_name" Then it works as I expect.

I might put this one down to experience for the time being and come back to it when my mind is a bit clearer.

Thanks for your help.




Theme © iAndrew 2016 - Forum software by © MyBB