Why does working permisson of PHP script differs between server? - php

<?PHP
print "hello";
?>
I write this code and save as "1.php";
Then I upload this PHP script to my
server.
I have 8 diffrent free hosting server's accounts.
And I noticed that there are 2 types of
server settings.
(1)
"type A"
for exapmle, sqweebs.
We need to set the PHP file permission as 640.
This means that sqweebs server requires us
to give group permission for PHP script running.
If I set 604,then the server generate such a
errors.like,
Warning: Unknown:
failed to open stream:
Permission denied in Unknown on line 0
Fatal error: Unknown:
Failed opening required
'/www/sqweebs.com/1.php'
(include_path='.:/blahblah')
in Unknown on line 0
(2)
On the other hand ,there are other type
servers on this world.
"Type B",
for example, izfree.
On this server, I found that
I can make PHP script work if I give it
604 as the permission.
So I want to know why there are many server settings,
and what is the reason, and some other related
opinions.
like which server should I use ,or etc,etc.

The problem is probably with using the free hosts. They add server limitations, and most likely, disable/enable certain restrictions that they feel are fit for administering how you can behave on their site.

It probably depends on the permissions and under which group/user the apache is running. If it's running with your rights, you will be fine with 600, if the apache is not even in the same group as you are you probably need something like 604. All I'm saying is, it depends on the server configuration AND the file permissions. This is a wild guess, but if you really need something like 604, it could be a sign that there is potentially something wrong and other users maybe able to look into your home directory...

it is expected, by the webserver, that the file has to have the permission for the user that the webserver runs as, to open and run it.
So, if the webserver (say Apache) runs as www, then www should have read access to the file. (some run apache as www, and some run it as apache, or nobody).
When you upload the file, depending on how the umask is set, the file permission is set so. (so, on one host, the file could have permission 655 or other could be 600, when permission is not set explicitly).
It always helps if you know a bit about the OS you normally deploy your applications on. Mostly, PHP is deployed on *nix system, and permission scheme is nearly (almost always) same across all the *nix systems.
Try getting hold of "Unix system Administration Handbook" (by Evi Nemeth & Co). Its quite fun to read and easy to understand (it is an old edition .. but unix permissions have not changed)

Related

netbeans php remote server upload files

I'm a student, new to netBean php remote server. I was trying to upload php files to remote server through netbeans (on run). I'm sure everything in run configuration, ftp information is correct, I have rights to upload file to that folder.
And this error occur:
Message prompt:
"Cannot logout from server *name. Reason 250 OK. Current directory: *dir name"
Logs:
Log in output window:
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 17 of 500 allowed.
220-Local time is now 04:13. Server port: 21.
220-This is a private system - No anonymous login
220 You will be disconnected after 3 minutes of inactivity.
USER a4514022
331 User a4514022 OK. Password required
PASS ******
230-OK. Current restricted directory is /
230-362 files used (3%) - authorized: 10000 files
230 2476 Kbytes used (0%) - authorized: 1536000 Kb
TYPE I
200 TYPE is now 8-bit binary
CWD /public_html
250 OK. Current directory is /public_html
CWD /public_html
250 OK. Current directory is /public_html
Summary
Failed:
file test.php Cannot upload file test.php (unknown reason).
Runtime: 408 ms, transfered: 0 file(s), 0 KB
I don't get what happen. How to fix it?
I use netbean 6.9.1, windows 7 and java ver 7 (build 1.7.0_05) platform 1.7 Those numbers, I don't know which one is the version. I just put all those there. It seems I'm the rare one get this problem...
I Know you asked this and probably your problem has solved
but I write this for the another ones;
first check the Proxy.
Tools>Option>Proxy Settings
and then set on the "no proxy" .
It will probably be solved.
I had to select less secure option e.g. Encryption: Pure FTP option to get it working for GoDaddy setup.
This answer comes even later. I also had the error and ended up here in search.
My mistake was that I had the file I wanted to download in editing with another reader (outside Netbeans). In other words, the downloaded file could not be saved to local filesystem, because the opened file prevented that.

HTTP POST from Android to PHP not working for certain domain

I am trying to send data from an Android app to a PHP file on my server (school server) but I'm running into some problems. I have my own hosting space through SimpleHelix, and I was able to send the data just fine, but when I try to use my school's server, the PHP program returns the following error:
Notice: Undefined index: message in /home/alespurg/test_good.php on line 4
Warning: file_put_contents(androidmessages.html) [function.file-put-contents]: failed to open stream: Permission denied in /home/alespurg/test_good.php on line 9
Warning: file_get_contents(androidmessages.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/alespurg/test_good.php on line 11
All I have changed in my Java file is the URL that I need it to post to. Could there be restrictions on my school's server that prevent the post to go through? I've checked my permissions on the folders and files, they're all 775. Again, I know the program works, I'm just having problems with the server. I did not use the IP address of the domain for either one. I couldn't find it for my school's server.
EDIT:
<?php
// get the "message" variable from the post request
// this is the data coming from the Android app
$message=$_POST["message"];
// specify the file where we will save the contents of the variable message
$filename="androidmessages.html";
// write (append) the data to the file
file_put_contents($filename,$message."<br />",FILE_APPEND);
// load the contents of the file to a variable
$androidmessages=file_get_contents($filename);
// display the contents of the variable (which has the contents of the file)
echo $androidmessages;
?>
If the permissions are 775 that means that if the web server process isn't either (1) the user who owns /home/alespurg/ (not likely) or (2) a member of the group that owns /home/alespurg/ (also not likely) then it won't be able write to the directory.
Are you sure the web server process is the owner or a member of the ownership group for /home/alespurg/?
I'll assume your web server is apache, which usually runs as apache:apache or nobody:nobody. Judging from the directory structure, it's likely that /home/alespurg/ is owned by alespurg:alespurg or some derivation.
ADDENDUM
If you need to do things like this an apache process is not really the appropriate place. You may not know it but you can write php scripts and execute them from the shell environment on your server where you're logged in as the appropriate user to write to that directory. Further, you can have CRON run them for you if necessary. The web server process is an unnecessary middleman.

The server at www.localhost.com is taking too long to respond

A very strange thing is happening. I am running a script on a new server (it works on my current server and laptop).
The strange thing is that I only get it to (sort of) work when I increase memory limit to 1024M (!). It is extracting a large zip file and going through the files, so I thought it was normal. Instead of this script terminating or ending with errors. I get an error from my browser:
The server at www.localhost.com is
taking too long to respond.
Localhost.com? The web server is just localhost:9090 and I can see Apache is still running. Maybe Apache crashes momentarily and it can't find the server? But nothing about apache crashing in the log files.
This isn't a server issue, its more to do with my PHP script and memory usage I think, so no need to move to server fault.
What could be the problem? How can I narrow do the cause, I am at loss here!
The server is a windows server running Apache 2.2 with PHP version 5.3.2. May laptop and the other working server are running version 5.3.0 and 5.3.1 for PHP.
Thanks all for any help
Ensure that,
ini_set('display_errors','On');
ini_set('error_reporting',E_ALL);
ini_set('max_execution_time', 180);
ini_set('memory_limit','1024MB' );
I'd pop this in the top of the script and see what comes out. It should show you errors and the like.
The other thing, have you checked fopen and the path of the file which it's loading?
Abs said,
check files being zipped up can be zipped by PHP (permissions
especially on a Windows OS with multi
users)
I kept getting this problem too, and none of these sites really helped until I started looking at the same thing for people using Internet Explorer. The way I fixed it is to open up the system hosts file, located at C:\Windows\System32\drivers\etc\hosts, and then uncomment out the line that mentions ::1, which is needed for IPv6. After that it worked fine.
Somehow your system's munged up and isn't treating localhost as the local 127.0.0.1 address. Is your hosts file properly configured? This is most likely why you're getting the "too long to respond" error:
marc#panic:~$ host www.localhost.com
www.localhost.com has address 64.99.64.32
marc#panic:~$ wget www.localhost.com
--2010-08-03 22:41:05-- http://www.localhost.com/
Resolving www.localhost.com... 64.99.64.32
Connecting to www.localhost.com|64.99.64.32|:80... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.
www.localhost.com is full valid hostname as far as the DNS system is concerned.
I am not a php guru by any means but are you writing the extracted files to a temporary local storage location that is within the scope of the application? Because if you are not then I think what is happening is that the application is storing the zip file and extracted files in memory and then is attempting to read them. So if it is a large zip and/or the extracted files are large that would introduce a huge amount of overhead on top of the overhead introduced by your read and processing actions.
So if you are not already I would extracted the files and write them to disk in their own folder, dispose of the zip file at this point, and then iterate over the files in your newly created directory and perform whatever actions you need to on them.

php access network path under windows

within PHP (XAMPP) installed on a Windows XP Computer Im trying to read a dir which exists on a local network server. Im using is_dir() to check whether it is a dir that I can read.
In Windows Explorer I type \\\server\dir and that dir is being shown.
When I map a network drive a can access it with z:\dir as well.
In PHP I have that script:
<?php if( is_dir($dir){ echo 'success' } ) ?>
For $dir I tried:
/server/dir
//server/dir
\server\dir
\\server\dir
\\\\server\\dir
and
z:\dir
z:\\dir
z:/dir
z://dir
But I never get success?
Any idea?
thx
I solved it by changing some stuff in the registry of the server as explained in the last answer of this discussion:
http://bugs.php.net/bug.php?id=25805
Thanks to VolkerK and Gumbo anyway!
I love stackoverflow and their great people who help you so incredibly fast!!
EDIT (taken from php.net):
The service has limited access to network resources, such as shares
and pipes, because it has no credentials and must connect using a null
session. The following registry key contains the NullSessionPipes and
NullSessionShares values, which are used to specify the pipes and
shares to which null sessions may connect:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Alternatively, you could add the REG_DWORD value
RestrictNullSessAccess to the key and set it to 0 to allow all null
sessions to access all pipes and shares created on that machine.`
add RestrictNullSessAccess=0 to your registery.
You probably let xampp install apache as service and run the php scripts trough this apache. And the apache service (running as localsystem) is not allowed to access the network the way your user account is.
A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account.
This has several implications:
...
* The service presents the computer's credentials to remote servers.
...
You can test this by starting the apache as console application (apache_start.bat in the xampp directory should do that) and run the script again. You can use both forward and backward slashes in the unc path. I'd suggest using //server/share since php doesn't care about / in string literals.
<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo "\n</pre>";
Try the file: URI scheme:
file://server/dir
file:///Z:/dir
The begin is always file://. The next path segment is the server. If it’s on your local machine, leave it blank (see second example). See also File URIs in Windows.
Yes, I know this is an old post, but I still found it, and if anyone else does...
On Windows, with newer servers, verify the SMB is installed and enabled on the target machine.

Setting permission for PHP (or I_USER [I'm not sure here...]) to connect to iisweb.vbs

I have been trying to figure out a way to manage our domains at work and easily created a SimpleDNS class, but now I'm on the IIS Server Administration side of it and I'm just lost on what is going on.
Here is the PHP code I am running to test it.
<?php
$cmd = 'iisweb /create c:\websites\examplesite.com\www "Example Domain!" /d www.examplesite.com';
exec($cmd,$data);
print_r($data);
?>
But when I run it I get:
Array ( [0] => Error &H80041003: Access denied
I am completely stumped on how to set up permissions for this.
Here's the good part! When I run <?php exec('ping google.com',$data);?>: it works seamlessly.
I have no idea where to start when it comes to setting up the permissions for iisweb.vbs (the iisweb vbs file). I don't even know if I'm supposed to set up permissions on that file. I don't know if I'm supposed to setup a CGI option in the console. I'm lost.
Can someone help me out? What am I doing here?
Your code will be running under one of two identities.
The identity of the Application Pool that the website runs in (NETWORK SERVICE for example if the defaults were used). You can find this out by opening the property window for an application pool and selecting the Identity tab.
The identity of the website anonymous user which you can find in Website Properties -> Directory Security -> Authentication and access control (click the edit button).
FastCGI
If you're running PHP under FastCGI and the c:\php\php.ini configuration value fastcgi.impersonate = 1 then user identity be the site anonymous user (option 2) above. If fastcgi.impersonate = 0 then PHP scripts will execute under the identity of the application pool (option 1).
You can tell if PHP is configured to execute under FastCGI by looking at the .php scriptmap for the site (Website Properties -> Home Directory -> Configuration -> Application Extensions). If it's set to C:\WINDOWS\system32\inetsrv\fcgiext.dll then you're running FastCGI.
No FastCGI
If your .php script map is not configured to use C:\WINDOWS\system32\inetsrv\fcgiext.dll
then scripts will run under the identity of the site anonymous user (option 2 above).
In all cases the account used must have Administrators rights to be able to run the IIS admin scripts.

Categories