Axvil
Axvil

Reputation: 31

Apache virtual host 404 not found

I just started learning php and I am trying to host locally my own php website by using XAMPP.

I wanted to create virtual host with:

URL: myphpwebsite.local

Port: 8088

But when I attempted to access this website through the browser I got a:

Not Found HTTP Error 404. The requested resource is not found.

Does anyone know what the problem is?

My httpd-vhosts.conf

NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
  DocumentRoot "C:/xampp/htdocs"
  ServerName localhost
</VirtualHost>

<VirtualHost myphpwebsite.local>
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
    ServerName myphpwebsite.local
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined

   <Directory "C:/Microsoft/Workspace/myphpwebsite">
    Order allow,deny
    Allow from all
   </Directory>
</VirtualHost>

And my C:\Windows\System32\drivers\etc\hosts file:

127.0.0.1       localhost
127.0.0.1 myphpwebsite.local

Any help would be appreciated!

Upvotes: 3

Views: 26358

Answers (4)

Achraf JEDAY
Achraf JEDAY

Reputation: 2104

Make sure that the port you are using is not being used by another service.

Upvotes: 0

Tom St
Tom St

Reputation: 911

  1. make sure there's file/htaccess/index or whatever in directory you want to open, 404 may comes from that ;)

  2. try using one below, eventually replace your port:

     <VirtualHost *:80>
         DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
         ServerName myphpwebsite.local
      </VirtualHost>
    
  3. the question is your Apache running/serving on port 8088? For example my xamp is running on 80 and 443...

  4. xamp control panel is very handy, it has nice logs button that will open your log files to show you php and apache errors etc. check it out.

Try going with default port, if it works it means that you need to play with ports if you really want to.

just a quick tip, .com is shorter than .local and if you're using chrome and it works like mine then most of the time something.local will redirect you to google search (and I like my search there, you can switch it off ;))

Upvotes: 3

Chris Brendel
Chris Brendel

Reputation: 700

The NameVirtualHost directive needs to match the value of VirtualHost exactly, and you need to specify the port in each instance. If you want to use port 8088 for myphpwebsite.local, you'd need to do:

NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
  DocumentRoot "C:/xampp/htdocs"
  ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1:8088>
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
    ServerName myphpwebsite.local
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined

   <Directory "C:/Microsoft/Workspace/myphpwebsite">
    Order allow,deny
    Allow from all
   </Directory>
</VirtualHost>

Notice the VirtualHost opening tags are identical; it's the ServerName value that actually tells Apache which domain this particular directive applies to. Restart your server after making the changes. Check out this page for more information: http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Hope this helps!

Upvotes: 0

Damon
Damon

Reputation: 4484

I don't know if I am much help, but using WAMP, here are my settings. I am listening on port 80, I use 8080 for my tomcat server.

hosts file

127.0.0.1  local.mysite.com

httpd-vhosts.conf

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

....

<Directory "c:/wamp/www">
    Options Indexes MultiViews FollowSymLinks
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "c:/wamp/www"
</VirtualHost>

<Directory "c:/wamp/www/path/to/site/root">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<VirtualHost *:80>
    ServerName local.mysite.com
    DocumentRoot "c:/wamp/www/path/to/site/root"

    ServerAdmin [email protected]

    ProxyPreserveHost Off
    RewriteEngine On
    AllowEncodedSlashes NoDecode
    #AllowEncodedSlashes On

    ErrorLog "c:/wamp/www/path/to/logs/error.log"
    CustomLog "c:/wamp/www/path/to/logs/access.log" common
</VirtualHost>

....

Then I can access my local site like this: http://local.mysite.com

Hope this helps...

Upvotes: 1

Related Questions