Hello!
I am brand new to PHP, but I'm a software engineer, so it shouldn't be too hard for me. I am trying to use it for a simple HTML form that will send an E-mail to me when a visitor to my web page wants to contact me. I found sample code, and it works -- as long as the PHP script is in the httpdocs folder of my web server. But the web page I got the sample from said it's not a good idea to have the PHP code where it can be retrieved from my site, so I tried moving it to another folder on my server. My provider gives me a folder named "bin" and a folder named "cgi-bin". I tried putting it in cgi-bin. When I opened my test form and clicked the Submit button, I was surprised to see the dialog box asking if I wanted to open or save the file. No, I want it to be run! I tried putting it in the bin folder, but I got "permission denied". But it's my own folder, I think! And its permissions indicate that I should be able to put files in there.
So, a couple of questions: What permissions should the folder containing PHP scripts have? What permissions should the PHP scripts themselves have? Is read permission sufficient, or do they need execute permission as well? I presume that the structure of folders provided by a hosting service to a web site owner is more or less standard. What folder are PHP scripts normally stored in?
Thank you very much!
RobR
PHP script runs in one folder but not another
Moderator: General Moderators
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: PHP script runs in one folder but not another
I believe the idea behind having a cgi-bin folder is to include() the file you want in there. So, you would have a file in the httpdocs folder that has a call to the include() function with the path to the email file (probably '../cgi-bin/sendemail.php' or something like that).
Like this:
http://us3.php.net/manual/en/function.include.php
Like this:
Code: Select all
<?php
include('../cgi-bin/sendmail.php');
?>Re: PHP script runs in one folder but not another
The idea of /cgi-bin/ folder is to put executables there. PHP files (usually) are not executable and processed by webserver itself (most of the time it would be Apache with mod_php). So you just put them (those that you want to be accessible from outside) under your document root, and set the webserver to process them (instead of sending their contents to the client).
Re: PHP script runs in one folder but not another
Please see this comment from php.net
Create a folder called php-bin and try it there please. Although I would not recommend you organize your code in a folder called "bin". That would be kind of like throwing everything in your house into the closet piled up where the door doesn't close. Instead you want meaningful directories. Like classes that deal with user authentication should go in a folder called user.
Normally I keep everything *above* or outside the web root, except for an index.php which is my "single entry point". I use mod_rewrite (an Apache module/setting) to pretty up the URLs and my index.php keeps the application encapsulated. You don't want a 1,000 files just hanging around in the public_html because it breaks encapsulation, too many places to edit for a simple change (like security changes) that way.
So a request to /view/user/1 actually invokes index.php?module=user&action=view&id=1
This way I can edit from a single place, to add things like logging, or authentication, or whatever my programming task is that day.
Are you on windows or linux? What web server are you running? Can you post the output of running the phpinfo() command in PHP? Can you send us the output of `ls -la` as executed from your web root (linux only)
Also the cgi-bin historically will have weird server settings not suitable for running PHP scripts, dating back to executable perl scripts. You can make yourself a executable PHP script but that would be like making yourself use punch cards, it would be going back in time.mbread at m-bread dot com
10-Feb-2007 05:23
If you have a problem with "Permission denied" errors (or other permissions problems) when including files, check:
1) That the file you are trying to include has the appropriate "r" (read) permission set, and
2) That all the directories that are ancestors of the included file, but not of the script including the file, have the appropriate "x" (execute/search) permission set.
Create a folder called php-bin and try it there please. Although I would not recommend you organize your code in a folder called "bin". That would be kind of like throwing everything in your house into the closet piled up where the door doesn't close. Instead you want meaningful directories. Like classes that deal with user authentication should go in a folder called user.
Normally I keep everything *above* or outside the web root, except for an index.php which is my "single entry point". I use mod_rewrite (an Apache module/setting) to pretty up the URLs and my index.php keeps the application encapsulated. You don't want a 1,000 files just hanging around in the public_html because it breaks encapsulation, too many places to edit for a simple change (like security changes) that way.
So a request to /view/user/1 actually invokes index.php?module=user&action=view&id=1
This way I can edit from a single place, to add things like logging, or authentication, or whatever my programming task is that day.
Are you on windows or linux? What web server are you running? Can you post the output of running the phpinfo() command in PHP? Can you send us the output of `ls -la` as executed from your web root (linux only)