logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Local virtual hosts cannot serve pages from subfolders
Author
Chuanist



Joined: 16 Jul 2020
Posts: 2
Location: USA, Berkeley

PostPosted: Sun 08 Nov '20 19:22    Post subject: Local virtual hosts cannot serve pages from subfolders Reply with quote

Dear Web Geeks—

My local installation of Apache 2.4 on macOS does not enable browsers to serve web pages from files stored in subfolders of virtual hosts.

My commercial web host does serve pages from subfolders in the primary domain and from subfolders in the add-on domains. I would very much like to have this capability in my local testing environment.

My virtual hosts are defined on the Mac in httpd-vhosts.conf. All of my named hosts are available in a browser. One site stores index.php at the root-level and all other pages in a subfolder named ‘mhd’. (See screen shot of file hierarchy below.) Navigation links in ‘index.php’ come from a php ‘include’ statement that targets an unordered list from the ‘includes’ subfolder inside of ‘mhd’.

The browser also displays web fonts from the ‘fonts’ subfolder which, like ‘includes’, is inside the ‘mhd’ subfolder--two levels down from this virtual host's root directory.

When navigation links to page files inside subfolder ‘mhd’ are clicked on, the browser displays a download requester, instead of the expected web page. This requester is shown in the second screen shot below. If an application is chosen to display the page, an identical requester appears in a new browser window.

The message in the error log is:

Code:
[Fri Nov 06 22:11:19.599625 2020] [autoindex:error] [pid 580] [client 127.0.0.1:49546] AH01276: Cannot serve directory /Volumes/Data/Users/zen/Sites/machead/mhd/: No matching DirectoryIndex (index.html,index.wml,index.cgi,index.shtml,index.jsp,index.js,index.jp,index.php4,index.php3,index.php,index.phtml,index.htm,default.htm,default.html,home.htm,index.html,index.php) found, and server-generated directory index forbidden by Options directive


These index definitions are contained in httpd.conf. I tried adding *.php here, and placed this command in my user.conf file as well … but doing so does not make the navigation links in index.php work:

Code:
<IfModule dir_module>
    DirectoryIndex  index.html index.wml index.cgi index.shtml index.jsp index.js index.jp index.php4 index.php3 index.php index.phtml index.htm default.htm default.html home.htm *.php
</IfModule>


If anyone knows how to make the browser serve contact.php, design.php, etc. from the mhd subfolder I would be most grateful for a few words!

The virtual host in question is defined thus:

Code:
<VirtualHost *:80>
    ServerAdmin zen
    DocumentRoot "/Volumes/Data/Users/zen/Sites/machead/mhd"
    ServerName macheadtest.info
    ServerAlias www.macheadtest.info
    ErrorLog "/private/var/log/apache2/macheadtest.php-error_log"
    CustomLog "/private/var/log/apache2/macheadtest.php-access_log" common
</VirtualHost>


Access to this local virtual host is defined in my user.conf file:

Code:
<Directory "/Users/Zen/Sites/machead/">
  AllowOverride All
  Options Indexes MultiViews FollowSymLinks ExecCGI
  Require all granted
  Allow from all
</Directory>


In case it helps, here are the links in index.php:

Code:
<div id='topnav'>
    <ul>
<li><a href="index.php">the Mac Help Desk</a></li>
<li><a href="mhd/support-short.php">Support</a></li>
<li><a href="mhd/design-short.php">Design</a></li>
<li><a href="mhd/services.php">Services</a></li>
<li><a href="mhd/notes.php">About</a></li>
<li><a href="mhd/contact.php">Contact</a></li>
    </ul>
</div> <!--end topnav-->


Called by this php statement:

Code:
<?php include 'mhd/includes/topnav-outer.php'; ?>


Here is the file hierarchy inside the virtual host ‘Machead’:



Here is what the browser displays when a link is clicked on index.php:

Back to top
mraddi



Joined: 27 Jun 2016
Posts: 149
Location: Schömberg, Baden-Württemberg, Germany

PostPosted: Mon 09 Nov '20 10:18    Post subject: Reply with quote

Hello,

DirectoryIndex is a list of files that the webserver tries to open in exactly this order if no filename is provided within the request.
So if you request http://www.example.com/somedir/somefile.html the server tries to open this file. On success it is returned. Otherwise a 404 is sent to the client.
If you request http://www.example.com/somedir/ then there is no filename within this request. So the webserver tries to open the files from your DirectoryIndex in this order. The first match is returned to the client. If no file from the list is available it is checked if directory index is allowed ("Options Indexes"). If yes, then a generated list of all files within this directory is returned. Otherwise an error is returned (IIRC a "403 directory index forbidden").

Back to your config-snippets:
* I believe a "DirectoryIndex ... *.php" will not work as the webserver doesn't know which php-file to choose if there are more than one.
* Your DirectoryIndex is within the "IfModule dir_module". Why? Is this module loaded? Otherwise this configuration-line will have no effect. So you might move the DirectoryIndex to a better location within your config.
* Are you sure that the PHP-extension is loaded within your local Apache-installation? Check with a file (phpinfo.php) containing only these lines
<?php
phpinfo();
?>
and trying to open that in your browser by using the filename explicitely - http://www.example.com/somedir/phpinfo.php - do you see a long list of configuration-settings from php (in this case PHP seems to work) or does your browser try to download the exact file (then PHP is not configured correctly within your webserver).
* Try to check the syntactical correctness of your config-file with the parameters -S and -t:
apache2ctl -t
apache2ctl -S
which gives errors if some config-file contains errors and you see some information on your virtual-host-configuration. This only checks if Apache can read and understand all of the config-files, which is not necesarily what you want to have Wink
* Would be interesting what is in the response - try to save the support-short.php from your browser and open it with a text-editor.

Best regards
Matthias
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 09 Nov '20 16:13    Post subject: Reply with quote

How did you configure PHP in Apache? As Matthias mentioned the PHP module does not seems to be loaded or is not configured.
Back to top
Chuanist



Joined: 16 Jul 2020
Posts: 2
Location: USA, Berkeley

PostPosted: Fri 28 May '21 6:34    Post subject: Many Thanks for Your Suggestions Reply with quote

Yes, PHP 7.33 is running, and the index.php page is able to pull an image file from the gfx directory (two down from site root) and the menu include file (one folder down from the site root) using a php command embedded in the index.php file itself.

I will look at the directory definitions as you suggested, but the directories defined in vhost.conf point to the folders I intended, and the index file in each local site comes up in a browser.

Thanks too for giving me the Terminal commands to check out the Apache installation. It appears to be okay, though I do see one parameter (alisa) present in macheadtest.info that does not appear in the other entries. I will look at vhost.conf again:

zens-MacPro:~ zen$ apachectl -t
Syntax OK
zens-MacPro:~ zen$ apachectl -S
VirtualHost configuration:
*:80 is a NameVirtualHost
default server localhost (/private/etc/apache2/extra/httpd-vhosts.conf:24)
port 80 namevhost localhost (/private/etc/apache2/extra/httpd-vhosts.conf:24)
port 80 namevhost macheadtest.info (/private/etc/apache2/extra/httpd-vhosts.conf:32)
alias www.macheadtest.info
port 80 namevhost voice.test (/private/etc/apache2/extra/httpd-vhosts.conf:41)
port 80 namevhost phplearning (/private/etc/apache2/extra/httpd-vhosts.conf:49)
port 80 namevhost BBA.test (/private/etc/apache2/extra/httpd-vhosts.conf:57)
port 80 namevhost carecompanion.test (/private/etc/apache2/extra/httpd-vhosts.conf:65)
port 80 namevhost postpartumdoula.test (/private/etc/apache2/extra/httpd-vhosts.conf:73)
port 80 namevhost berkeleyresists.test (/private/etc/apache2/extra/httpd-vhosts.conf:81)
port 80 namevhost covidunmasked.test (/private/etc/apache2/extra/httpd-vhosts.conf:89)
port 80 namevhost martin.test (/private/etc/apache2/extra/httpd-vhosts.conf:97)
ServerRoot: "/usr"
Main DocumentRoot: "/Library/WebServer/Documents"
Main ErrorLog: "/private/var/log/apache2/error_log"
Mutex default: dir="/private/var/run/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/private/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="_www" id=70 not_used
Group: name="_www" id=70 not_used
zens-MacPro:~ zen$
Back to top


Reply to topic   Topic: Local virtual hosts cannot serve pages from subfolders View previous topic :: View next topic
Post new topic   Forum Index -> Apache