Define Server Root(s)

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Define Server Root(s)

Postby matt6805 » 23. October 2007 22:36

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.
matt6805
 
Posts: 7
Joined: 23. October 2007 22:24

Postby Wiedmann » 23. October 2007 22:41

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...
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby matt6805 » 24. October 2007 17:44

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
matt6805
 
Posts: 7
Joined: 23. October 2007 22:24

Postby webmax » 25. October 2007 22:13

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
webmax
 
Posts: 3
Joined: 13. February 2007 17:52

Postby djoey1982 » 26. October 2007 19:07

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.
djoey1982
 
Posts: 6
Joined: 25. October 2007 19:30

Postby webmax » 27. October 2007 00:05

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.
webmax
 
Posts: 3
Joined: 13. February 2007 17:52


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 137 guests