Jump to content
Larry Ullman's Book Forums

Index.php Not Working In A Subdirectory


Recommended Posts

I'm using MAMP installed on Yosemite 10.10.2 installed at /Applications/MAMP. Everything worked perfectly when I had the files in the web root which is /Applications/MAMP/htdocs/. I then created a subdirectory named gtstore (/Applications/MAMP/htdocs/gtstore) and moved all the files into that directory. The code shown is copy & pasted from the files. 

 

I then made the edits shown in the Chapter 7, Server Setup "Using a Subdirectory" sidebar. This is the suggested change I made to .htaccess. The rest of the file was unchanged.

<IfModule mod_rewrite.c>

Options -MultiViews

RewriteEngine on

# For the subdirectory of the store:

RewriteBase /gtstore/

.

.

 


Next I made changes to the index.php file (/Applications/MAMP/htdocs/gtstore/index.php): 

// Require the configuration before any PHP code:

require('./gtstore/includes/config.inc.php');


 

When I linked to the subdirectory from the web root I get a PHP error, and shown in the php_error.log:

php_error.log: [20-Mar-2015 16:33:15 America/Los_Angeles] PHP Fatal error:  require(): Failed opening required './gtstore/includes/config.inc.php' (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/gtstore/index.php on line 7

 

This is the where the error is occurring:

6. // Require the configuration before any PHP code:

7. require('./gtstore/includes/config.inc.php');

 

I tried the .htaccess in two locations; /Applications/MAMP/htdocs/.htaccess and /Applications/MAMP/htdocs/gtstore/.htaccess, but not in both locations at the same time.

 

I've been working on this all day, checking and double-checking my work. Am I missing something simple here? Thank you for any help! BTW, great book! 

Link to comment
Share on other sites

Thanks for the nice words. The .htaccess and require are two separate issues. Your problem is with the require statement.. If a file is already in the gtstore folder and is including a file from within the includes directory--in that same folder, then you don't need to use "gtstore" in the require line. You should, most like, just be using require('./includes/config.inc.php')

Link to comment
Share on other sites

 Share

×
×
  • Create New...