Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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