VirtualHost setup always doesn't work

apache, hosts, mamp, virtualhost

Solution

Change 8080 to 80 its the default. But if you want your site to run on 8080, then you have to use it. Another solution might be to rewrite the url, that is when your server gets the url, it rewrites it with port number (8080).

First of all change Listen 8080 to Listen 80, as you want your application to be accessible only with http. In your http-vhost.conf file put following lines (of course after removing previous changes). In the following configuration yourDefaultHttpFolder means the default http folder. You might have changed it. So correct it depending on your system.

<VirtualHost *:80> 
   DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/yourDefaultHttpFolder"
   ServerName                127.0.0.1
   ServerAlias               localhost
   SetEnv APPLICATION_ENV    development
   SetEnv APPLICATION_DOMAIN localhost

   <Directory /Applications/mampstack-5.4.20-0/apache2/htdocs/yourDefaultHttpFolder>
      RewriteEngine on
      RewriteCond %{SERVER_PORT} ^80$
      RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P]
   </Directory>

</VirtualHost>

<VirtualHost *:8080> 
    DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/mext-pst-dashboard/web"
    ServerName mext-pst.local
    ServerAlias mext-pst.local
    SetEnv APPLICATION_ENV    development
    SetEnv APPLICATION_DOMAIN mext-pst.local       
 </VirtualHost>

This configuration is working on my server, when ever I try to access using 80 it rewrites the URL to my 8080 port and I see the content of that folder, not the the default index page.

Problem

I'm trying to set up a virtualHost for mampstack (NOT MAMP). This is what I've done so far: In my httpd.conf file I've checked ``` Listen 8080 ``` This is correct (I'm listening to the port 8080, NOT 80). Then I've uncommented: `Include conf/extra/httpd-vhosts.conf` in my `httpd.conf` file In my hosts file I have added the following: `127.0.0.1 mext-pst.local`. In `httpd-vhosts.conf` I've added: ``` NameVirtualHost *:8080 <VirtualHost *:8080> DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs" ServerName 127.0.0.1 ServerAlias localhost SetEnv APPLICATION_ENV development SetEnv APPLICATION_DOMAIN localhost </VirtualHost> <VirtualHost *:8080> DocumentRoot "/Applications/mampstack-5.4.20-0/apache2/htdocs/mext-pst-dashboard/web" ServerName mext-pst.local ServerAlias mext-pst.local SetEnv APPLICATION_ENV development SetEnv APPLICATION_DOMAIN mext-pst.local RewriteEngine on RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^ http://%{HTTP_HOST}:8080%{REQUEST_URI} [P] </VirtualHost> ``` Now when I go to `http://mext-pst.local/` I just get an error of my browser that he can't connect with the page ... . When I go to `http://mext-pst.local:8080/` I get the following error: ``` Proxy Error The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET /index.php. Reason: DNS lookup failure for: mext-pst.local:8080 ``` When I go to `http://mext-pst.local:8080/index.php` it works ...

Original source