3

Goal :- set up virtual host correctly.

currently I am working on MAC system version 10.10.05 os x yosemite.

I have configured apache2,php and mysql using XAMPP

I have follow all the necessary steps for configuring virtual host.

my file /private/etc/apache2/extra/httpd-vhosts.conf would be like

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
    <Directory "/Applications/XAMPP/xamppfiles/htdocs">
        Options Indexes FollowSymLinks Includes execCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName emsv2l.localhost.com
    ServerAlias emsv2l.localhost.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/emsv2"
    ErrorLog "/private/var/log/apache2/apple.com-error_log"
    CustomLog "/private/var/log/apache2/apple.com-access_log" common
    ServerAdmin webmaster@dev.plutustec.com
        <Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2">
                Options Indexes FollowSymLinks Includes ExecCGI
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName emsv2l-backend.plutustec.com
    ServerAlias emsv2l-backend.plutustec.com
    DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/emsv2-backend/public“
    ErrorLog "/private/var/log/apache2/apple.com-error_log"
    CustomLog "/private/var/log/apache2/apple.com-access_log" common
    ServerAdmin webmaster@dev.plutustec.com
        <Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2-backend/public“>
                Options Indexes FollowSymLinks Includes ExecCGI
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

So, Now if i write http://emsv2l.localhost.com/ would be redirect to project instead it's showing directory structure.

enter image description here

my /etc/hosts file would be like

##
# 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
#127.0.0.1      dev.local
#127.0.0.1     emsv2l-backend.plutustec.com             # emsv2-backend
#127.0.0.1     emsv2l.plutustec.com             # emsv2
#127.0.0.1      plutustec.com #localplutus site
127.0.0.1 emsv2l.localhost.com
127.0.0.1 emsv2l-backend.plutustec.com

Any help would be appreciated.

Shashank Shah
  • 2,077
  • 4
  • 22
  • 46

3 Answers3

2

You need to disable directory listing, to do that replace this:

<Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
</Directory>

With:

<Directory "/Applications/XAMPP/xamppfiles/htdocs/emsv2">
        Options FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
</Directory>

Then reload apache.

For more details check here

Then one more thing, do you have an index.php or index.html within your: /Applications/XAMPP/xamppfiles/htdocs/emsv2?

lloiacono
  • 4,714
  • 2
  • 30
  • 46
  • Indexing should not be required to turn off. It might actually be something you want to use. But indeed check for an index.* file – G4Hu May 24 '17 at 09:28
  • I have tried above but it's not working changed content of the file and restart apache. – Shashank Shah May 24 '17 at 09:36
1

Did you follow the guide for configuring vhosts to the letter? If so, are you sure that the Apache you configured is the one that is currently listening on port 80? XAMPP should have it's own Apache built in and it doesn't run off the default config. Your XAMPP httpd.conf should contain:

# XAMPP VirtualHosts dir
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf

To solve fastest just:

cp -iv /private/etc/apache2/extra/httpd-vhosts.conf /Applications/XAMPP/etc/extra/httpd-vhosts.conf

If asked for overwrite confirmation press 'y'

G4Hu
  • 338
  • 1
  • 3
  • 18
0

in my case,

i'm using macOS Mojave (Apache/2.4.34). In /etc/apache2/httpd.conf file search for the text "IfModule dir_module". Check the IfModule directive/tag contain any index.php. If no the add index.php after index.html. Hope this will save you.

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
sh6210
  • 4,190
  • 1
  • 37
  • 27