open function working in local server but not working on mail server
Very popular trouble:
Your local server works under Windows OS, so you can access your file without any trouble. But when you migrate from Windows to Linux, FreeBSD or other hosting you get "Access denied" error. So, you need to change access permissions to your file with FTP client or SSH.
Google for changing file permission. You will get a lot of step-by-step instructions for chmod linux command, SSH and s.o.
It will be much better, you post here some PHP output, such as warnings or errors.
Like Andrew said, it's probably a file permission problem.
If you're trying to open a remote resource (using a network protocol), you should check your phpinfo(): the configuration key allow_url_fopen must be set to on.
Could you copy/paste more details about your problem?
PHP version
complete error trace
file permissions
Related
Sorry if this a repeat of a question that has been asked before but I have not been able to find my exact situation. We are trying to migrate our website server from a Windows 10 VM (yes I know) to a Windows Server 2019 VM. We have some PHP on our site that writes files to some of our other servers on the same domain and have been able to do so without issue using file_put_contents like so:
file_put_contents("\\\\server\\folder\\folder\\folder\\".$filename, $file);
Now all of a sudden, to run the same code on our new server I get a Warning on this line, "Failed to open stream: Permission denied". I have permission to access this folder, I can browse to \server\folder\folder\folder and create a file there. I even tried mapping this server to a letter drive on my new web server, and still same error. I can put the file on the local C drive just fine but that's it.
Running fileperms on the folder path gives Warning: fileperms(): stat failed. Running is_writable on the folder path returns false, I just can't see how. Running it on the old Windows 10 web "server" returns true. I've read some things about needing to enable certain settings on the server you're trying to access, but I just can't think of what would allow one VM to access it and not another. Both VM's are logged in with the same user with admin rights. I can bring up the same folder in file explorer and write to it, just not via PHP. What obvious thing am I missing?
Thanks!
After weeks of banging our heads against the wall we finally figured this out. On our old web server, when right-clicking the website from the Sites file tree in IIS, under Manage Website -> Advanced Settings, the Physical Path Credentials field was set to the credentials needed to access these folders. On the new server it was blank. I'm not sure how this got missed but in any case, after entering the correct credentials here everything immediately worked.
I'm copying a file from $source to $destination.
If I execute copy($source, $destination) from PowerShell, it works.
If I call this copy($source, $destination) from Apache, it complains copy(...): failed to open stream: Permission Denied.
I am able to open up explorer and copy and paste file manually. I am using PHP 7.1, Apache 2.4 on Windows Server 2012R2.
Why is this happening? Could someone provide an insight?
If run under Windows Apache already has all the permissions it needs, as it runs under the LocalSystem account, which has extensive read/write access to local paths. This is inherited by PHP and the scripts it runs.
If there is a problem then –
The additional file permissions that have been set up afterwards are at fault (check Windows Event viewer).
The configuration has been incorrectly edited, such as the: WP upload path settings, php.ini temp folder location + upload settings, etc.
The Apache Service ‘Log On’ account has been changed from “LocalSystem” to something else (check Service’s Properties).
Possibly PHP’s open_basedir setting has been enabled in VirtualHost or .htaccess and is restricting the paths PHP can access.
Or there are internal PHP errors (check the website’s HTTP and PHP error logs).
EDIT
Since it is sugggested i add this solution possibility if you are stuck at point 3:
Create a user with extensive file permissions and change Apaches service to run under that user. I strongly suggest not to use the system admin user (or any admin user) profile for this.
I'm trying to download a file locally from a remote server but every time i access the file that contains the PHP code using the browser file_get_contents() fails because it doesn't have the permission to write to /var/www/html (Apache2). I tried using cURL but that didn't work either, checked to see if allow_url_fopen is on (it is) and added the php file to sudoers. I can't seem to find any solution online.
i think this is permission issue, see this maybe will solve your problem, pick that suit to your enviroment.
I'm using Apache and PHP. Webroot directory is /home/name/public_html
I want to include a file from /home/name/abc.php
include_one "/home/name/abc.php";
I got failed to open stream: Permission denied warning.
If i move the same file inside the webroot /home/name/public_html/abc.php
There is no error.
Apache User and Group has the permission to access the file /home/name/abc.php
I have another server with the similar configuration, it is working. Just want to know the possible reason.
I tried to run the PHP script directly in linux console, there is no permission issue. I guess the problem is in Apache configuration.
You should verify that php is really executed as the apache user. Depending on your configuration it might be possible that php is running under a different user, e.g. if your Apache is set up to use php-fpm.
If the server is a linux system, putting this
<?php
echo "<pre>";
var_dump(posix_getpwuid());
into a file and accessing via the web browser should show you the user informations.
I found the way to solve this issue from here. I have SELinux running on my Centos 7 Virtual Server.
I need to grant httpd permission to read from /home dir using:
sudo setsebool httpd_read_user_content=1
I am using a PHP application to generate links to files. Links are basically PHP files (abcd.php) with permission 644 put into a directory public with permission 755.
When I try to access public/abcd.php via browser I get a 500 Internal Server Error. If I change the file permission to 755, the system works.
I am using a cheap web server so I do not have much access to logs. What can be the cause of the problem? Can I solve the issue?
Thanks
644 on any server side script is likely to have problems because no executable flag is set
644 means that the owner can read and write and the rest of the world can read
755 means that the owner can do everything and the rest of the world can read and execute.
By rest of the world I really mean, other users on the server (eg. Apache which is likely to be the web server that your hosting runs upon)
Maybe PHP run as CGI on your server, and not as an Apache DSO module, so it needs the execution bit.
Try a phpinfo() to see if PHP run as CGI...