LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 July 22 2010

Kassem
Member

Configuring PHP on Shared Hosting?

Hey guys, there's something that really confuses me. When I watch video tutorials, all the work is done locally. There are very few (if any) videos that actually upload and get the application/website running online. Now using WAMP makes it very easy to play around with files, activate/deactivate certain PHP or Apache components/modules/whatever, and editing some files such as the php.ini and others.

Anyway, what I really want to know is how do I do the same stuff on shared hosting. Like sometimes I have to set certain paths to locate files that I need which are OUTSIDE the www folder. So yeah, how do I do that?

ex: I wouldn't want to place my Zend_amf files inside the root folder, I prefer to keep it outside.

Offline

#2 July 22 2010

arithma
Member

Re: Configuring PHP on Shared Hosting?

In most shared hosting servers that operate over ftp, you will have to host inside the public folder. A work around is to disallow public access to server-only files using an htaccess file.

Offline

#3 July 23 2010

Kassem
Member

Re: Configuring PHP on Shared Hosting?

arithma wrote:

In most shared hosting servers that operate over ftp, you will have to host inside the public folder. A work around is to disallow public access to server-only files using an htaccess file.

That's what I thought actually, but I have no idea how to do it. Google time :)

Offline

#4 July 23 2010

rolf
Member

Re: Configuring PHP on Shared Hosting?

Usually, you have a home folder for your account, and inside this folder another one which will be the webserver root (usually called public_http or www or something like that).
You can put the file in your account home folder. Or if you want to protect it with .htaccess just add an .htaccess file containing:

deny from all

(make sure to test it!)

Offline

#5 July 23 2010

Kassem
Member

Re: Configuring PHP on Shared Hosting?

Ok I've just finished reading a tutorial about the .htaccess file. You can do some nifty stuff using it. But still, I did not know how that's relevant to my question. The best way to solve my problem is by either editing the php.ini file and add to the "include_path" declaration, or by finding a work-around for it. Like if I placed a directory called "library" inside my /home folder of my shared hosting account, I want a way to be able to reference this directory in my code. How do I know the full path to my /home folder?

Offline

#6 July 23 2010

rolf
Member

Re: Configuring PHP on Shared Hosting?

Kassem wrote:

Ok I've just finished reading a tutorial about the .htaccess file. You can do some nifty stuff using it. But still, I did not know how that's relevant to my question. The best way to solve my problem is by either editing the php.ini file and add to the "include_path" declaration, or by finding a work-around for it. Like if I placed a directory called "library" inside my /home folder of my shared hosting account, I want a way to be able to reference this directory in my code. How do I know the full path to my /home folder?

You just use relative paths
Assuming you have a home directory with these subdirectories:
- public_www
- include
With public_www being your web root, and the php file you want to include from is public_www/index.php and your include file is include/stuff.inc then you just do in index.php:

include("../include/stuff.inc");

Otherwise, you can use the .htaccess solution in my last post and have your include files inside your web root.

------
EDIT: this is off topic, you don't need it, but its additional info... I never had to change include_path in php.ini, and to answer your question, to find your root, from public_www/index.php, do that:

// find the path of index.php
$tmp = pathinfo ( __FILE__, PATHINFO_DIRNAME);
// now go up one level:
$tmp = trim($tmp, " /"); // is there a trailing slash?? meh, just remove if present
$aTmp = explode("/", $tmp); // i like arrays
// remove one directory
array_pop($aTmp); // pop!
// stick everything back into a string
$path = implode("/", $aTmp);
// (that code is untested)

You dont need that... see relative the relative paths above... I'm just showing off :-D

Last edited by rolf (July 23 2010)

Offline

#7 July 24 2010

Kassem
Member

Re: Configuring PHP on Shared Hosting?

damn! I hate it when the answer to my question is so obvious and I start thinking of much more complicated solutions! Thanks rolf :)

Offline

Board footer