Page 1 of 1

Define Server Root(s)

PostPosted: 23. October 2007 22:36
by matt6805
First off, if this question is redundant I apologize. I searched for topics like it but found no direct answer.

I constantly run into the same issue everytime I start a new project using XAMPP. The issue is when I'm done with the project, I have to go back into the SQL and the PHP files to rename all instances of my C: drive and all http://localhost/ references to /, as that will be the live server root.

Is there an known way to define some kind of virtual root for each project? That way I could just take the sites I've developed here locally and depoly them directly to a live server root with out changing any paths in the files or SQL? Ideally, each new project folder that I create on my computer should act as a server root.

Any advise would be greatly appreciated.

PostPosted: 23. October 2007 22:41
by Wiedmann
That way I could just take the sites I've developed here locally and depoly them directly to a live server root with out changing any paths in the files or SQL?

The easiest way ist to use allways reallative paths in your projects...

PostPosted: 24. October 2007 17:44
by matt6805
Well that's the point exactly, I can't use relative paths. Unless I use absolute paths back to my XAMPP installation root, the applications I run like Wordpress for example will be broken.

Matt

PostPosted: 25. October 2007 22:13
by webmax
I've got round this by creating virtual hosts for each project.

I followed the ' Adding the VirtualHost Blocks' section from this page and it worked a treat.

http://textpattern.net/wiki/index.php?title=Using_XAMPP_(Apache-MySQL-PHP-Perl)_for_Windows

PostPosted: 26. October 2007 19:07
by djoey1982
yes that is the easy solution, but in theory you should always be able to use relative paths in php / html even if you have created seperate directories for them. MySQL if you program it right you always make 1 file that makes the connection to the database and include it where it is needed. Then you only have to change 1 file with the correct database parameters.. when you change from testing to live.

PostPosted: 27. October 2007 00:05
by webmax
Yep you can use relative paths, but once you start going down the directory tree it starts getting messy with lots of ../'s.

Its much easier and cleaner to reference your includes by $_SERVER['DOCUMENT_ROOT']."/p/include.php" than ../../../../../p/include.php

I usually put an if statement around my db call in my class file, and then pass the required credentials depending on which server the request is coming from, ie.

Code: Select all
if ($_SERVER['SERVER_NAME'] == 'localhost')
{
  host = 'localhost';
  user = 'username';
  pass = 'password';
  db = 'db_name';
}
else
{
  host = 'live_db_host';
  user = 'live_username';
  pass = 'live_password';
  db = 'live_db_name';
}

This saves having to make any changes at all when I move the files from local development to live www server.