Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Drew Butcher
Drew Butcher
33,160 Points

Moving Shirts4Mike into a subdirectory of htdoc

Once I finished the Shirts4Mike site I wanted to move the project into a sub directory of my htdocs folder so I created a folder in htdocs called "Shirts4Mike", then I went to the config.php file found in the "inc" folder and change the code to the following:

<?php
define("BASE_URL","/shirts4mike/");                         
define("ROOT_PATH", $_SERVER["DOCUMENT_ROOT"]."/shirts4mike/"); 

Now, when I type "localhost" into the url i see the subfolder "shirts4mike/" and when I click on this subfolder the page pulls up BLANK :( . Here is the link to the video by Randy Hoyt

Best, Drew

2 Answers

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

If you are getting a white screen, then you have a PHP error somewhere. It could be a simple syntax error like a missing semi-colon, but I suspect that the problem lies in where you have required the config.php file. Double-check each page to see if some work and some don't. If this command ...

require_once('../config.php');

... can't find the file, then it will produce an error and generate a white screen.

Hi,

I think you can try to define your ROOT_PATH constant as:

define("ROOT_PATH", dirname( $_SERVER["PHP_SELF"] ) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR);

If you do so, the BASE_PATH constant, should work as you defined above.

PHP, among others, have following constants defined by default:

$_SERVER["PHP_SELF"] Contains the fullpath to the file. So in this case it will contain the full path to your config.php file. Instead of $_SERVER["PHP_SELF"] you can also use $_SERVER["SCRIPT_NAME"]

DIRECTORY_SEPARATOR Contains the symbol that your OS uses to separate directories in a PATH. For example in windows is \ while in linux is /

So when the ROOT_PATH is the defined like this in the config file:

define("ROOT_PATH", dirname($_SERVER["PHP_SELF"]) . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR);

It search in first place the fullpath to your file, in my case as I am using linux is: /var/www/shirts4mike/inc/config.php

The dirname function then takes out the name of the file and leaves only the path /var/www/shirts4mike/inc

Then it adds a directory separator /var/www/shirts4mike/inc/

Then a couple of points to go up one level (so if we are in inc, the .. tells php to go the shirts4mike folder /var/www/shirts4mike/inc/..

Finally we add another directory separator /var/www/shirts4mike/inc/../

I do not know if this is the best solution, but it worked for me and I hope it will work as well for you :)

Many thanks, have a nice day,

Edu