TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-26-2011, 09:19 PM   #1 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default PHP doc_root

I am looking for guidance on how to change the document root setting for a website i have. in my HTDOCS folder in my installation of Apache i have several folders each for a different web project. However when when calling php global variables like $_SERVER['PHP_SELF'] i get a return of /holidaywebsite/index.php when what i want back is /index.php

I assume this is just a case of resetting the root in php? Can i do this in the php.ini file and if so how if, for example, i have my web project in a folder called holidaywebsite?

Thanks in advance for any help.
captainmerton is offline  
Reply With Quote
Old 03-28-2011, 02:27 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

This is a server setting which PHP's $_SERVER values are based on.
Why don't you create a virtualhost in apache pointing to your /var/www/holidaywebsite and now your $_SERVER['PHP_SELF'] would return index.php
tony is offline  
Reply With Quote
Old 03-28-2011, 05:32 PM   #3 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Thanks Tony. How do i create a virtual host in Apache? Is there no way to set this the php.ini file or use an htaccess file in the folder i have holidaywebsite?
captainmerton is offline  
Reply With Quote
Old 03-28-2011, 11:32 PM   #4 (permalink)
The Wanderer
 
Join Date: Dec 2008
Location: Houston, TX
Posts: 14
Thanks: 1
mjwalsh is on a distinguished road
Default

You would have to modify the httpd.conf file, personally I use cPanel on CentOS, the typically default virtual host entry would look something like this:

Quote:
<VirtualHost 69.64.91.228:80>
ServerName mjwalsh.net
ServerAlias www.mjwalsh.net
DocumentRoot /home/******/public_html
ServerAdmin webmaster@mjwalsh.net
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/mjwalsh.net combined
CustomLog /usr/local/apache/domlogs/mjwalsh.net-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User mjwalsh # Needed for Cpanel::ApacheConf
<IfModule mod_suphp.c>
suPHP_UserGroup ****** ******
</IfModule>
<IfModule !mod_disable_suexec.c>
SuexecUserGroup ****** ******
</IfModule>
ScriptAlias /cgi-bin/ /home/******/public_html/cgi-bin/


# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2/******/mjwalsh.net/*.conf"

</VirtualHost>
I took out the instances of the username and replaced them with ******. Obviously this is all not needed th emain thing you're looking at is the document root areas along with server name.
Send a message via AIM to mjwalsh Send a message via MSN to mjwalsh
mjwalsh is offline  
Reply With Quote
Old 03-29-2011, 06:41 PM   #5 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Thanks mjwalsh but I have zilch linux experience and very little apache experience. Maybe one for the future. is there any way i can throw something in the .htaccess file in the website directory to tell the server this is the root folder? Its Apache installed on Windows XP i'm running.
captainmerton is offline  
Reply With Quote
Old 03-29-2011, 07:10 PM   #6 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

It can't be done with just the .htaccess file. It's been a while since I've use windows and apache, here is what I would have done:


1.) The host file needs to be changed. In WinXP is the folder C:\WINDOWS\system32\drivers\etc\. You should be seen this already
Code:
127.0.0.1       localhost
now just add another line, so it will end up like this
Code:
127.0.0.1       localhost
127.0.0.1       holidaywebsite.local
(Note: I usually put .local on my local domains, but you don't need to)

2.) Now about the virtual hosts or vhosts. That depends what method you used to install your Apache server like using WAMP or XAMPP or just normal installation. I don't know, but I will assume you install it using the apache .exe file. The config file for vhosts is in C:\Program Files\Apache Group\Apache2\conf\vhosts.conf then add this:
Code:
<VirtualHost *:80>
    DocumentRoot C:/xampplite/htdocs/holidaywebsite/
    ServerName holidaywebsite.local
</VirtualHost>
The value of DocumentRoot is the folder where your website resides. Don't forget the trailing slash. If that file doesn't exists, create it. Then add this line to the C:\Program Files\Apache Group\Apache2\conf\httpd.conf file.
Code:
Include conf/vhosts.conf
3.) Do a quick configuration check. Open C:\Program Files\Apache Group\Apache2\conf\httpd.conf your file and make sure that the following part is not commented out by a preceeding # character:
Code:
Include conf/vhosts.conf
4.) Restart Apache.

That is a rough estimate of what needs to be done for a virtualhost.
tony is offline  
Reply With Quote
Old 03-29-2011, 07:36 PM   #7 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

Sorted. Thanks Tony. the vhosts file was already there in the extra folder and was pointed to in the httpd.conf file just needed the # removed. Required a bit of repointing to where my website resided in the Apache folder structure but a restart and i see the holidaywebsite folder prefix has gone when I access it through the browser and i echo $_SERVER['php-self'] in the code. Many thanks.

Any advice - I am currently running Apache on Windows XP but my shared webspace is Linux. Obviously i dont notice any difference because i dont see the server. But was thinking of moving to a Linux CentOS virtual server environment and trying to install that on my laptop as a development environment. I have literally never used Linux in my life. Is it easy to isnatll/get to grips with and is CentOS the best installation of it? Cheers.
captainmerton is offline  
Reply With Quote
Old 03-29-2011, 08:56 PM   #8 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I don't have much of a say on CentOS. Some servers at work use it, but they have been there since I was here. I've use openSUSE (very little) and I have use Ubuntu for the last 6 years. For starters, from what I see CentOS, Gentoo, Debian, and Ubuntu are good.

As of PHP very few things change from Windows Server to a Linux server, when you start. The manual tells you which functions/classes/libraries work only in linux. But if you want to start into the server world, just start with some linux distro and you will get the hang of it.
tony is offline  
Reply With Quote
Old 03-30-2011, 04:29 PM   #9 (permalink)
The Wanderer
 
Join Date: Dec 2008
Location: Houston, TX
Posts: 14
Thanks: 1
mjwalsh is on a distinguished road
Default

CentOS is definitely a favorite amongst web hosts for the linux distro. I am personally a linux systems admin so I do favor linux a bit over windows but in my opinion Linux is a lot easier to handle than windows is. It's also a lot more light when it comes to resources used. I think you'll like it once you get used to it a bit.
Send a message via AIM to mjwalsh Send a message via MSN to mjwalsh
mjwalsh is offline  
Reply With Quote
Old 03-30-2011, 04:59 PM   #10 (permalink)
The Acquainted
 
captainmerton's Avatar
 
Join Date: May 2009
Posts: 178
Thanks: 9
captainmerton is on a distinguished road
Default

I suppose my key consideration is my current webspace hosting package has all kinds of limits like 2 mysql databases each with a max space limit of 100Mb. I have a live website that is growly slowly but at some point i'm going to need the ability to do stuff on the server myself so was thinking of moving to a virtual server where there are several Linux options the default being CentOS. So want to make sure i'm not going to move to that and find i cant make head nor tail of it as ive never used Linux before. Sounds like CentOS is fine. I'll prob do some reading up on it. many thanks for your help guys.
captainmerton is offline  
Reply With Quote
Old 02-19-2013, 05:26 AM   #11 (permalink)
The Wanderer
 
Join Date: Feb 2013
Posts: 17
Thanks: 0
Rainman is on a distinguished road
Default

Welcome to mmoggg website to buy RS Gold, offer a lot, of course, Diablo 3 Gold and Cheap RS Gold, to be purchased at any time, at any time shipment, and Diablo 3 Gold Kaufen look forward to your visit!
Rainman is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
what are all the subjects in php? sarmenhb General 7 01-21-2008 05:41 PM


All times are GMT. The time now is 05:54 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design