I just downloaded MediaWiki software on my server for installation. After decompressing it, I noticed that PHP files were not executable.
I ran chmod +x *.php* (there are also .php5 files) but it didn't work in subdirectories.
How can I add the executable flag to all PHP scripts inside the MediaWiki folder recursively scanning the subfolders?
Thank you in advance.
Use bash in the MediaWiki directory
find . -iname "*.php" | xargs chmod +x
It does not work in subdirectories, because *.php* does not match any directories and hence does not include it.
Therefore you should use something like find ./ -iname "*.php*" -exec chmod 755 {} \; with the respective bits to set.
Related
The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.
When trying to update plugins from the admin interface. I’ve set the user to www-data for both directories and files … but nothing works.
What do I have to do to simply being able to use Wordpress as it is intended?
This issue is usually caused by incorrect file permissions or ownerships on your server (rather than being a problem with the plugin itself). Basically, WordPress isn’t able to properly access its own plugins folder, and as a result, can’t put the updated plugins files in there.
Permissions
Permissions can be set to 644 for files and 755 for folders. To do so, you can run two quick find commands.
To make all folders in your website path with 755 permissions run the following command
find /path/to/your_website -type d -exec chmod 755 {} \;
To make all files in your website root directory with 644 permissions, you can run
find /path/to/your_website -type f -exec chmod 644 {} \;
Please make sure to change /path/to/your_website with your real path.
Ownership
Ownership means which user and group are controlling the files. Usually, that’s www-data. So what you’ll need to do si
sudo chown -R www-data:www-data /path/to/your_website
Please make sure to change /path/to/your_website with your real path.
Once you do it, that’s it, you are good to go.
I have a couple of PHP-based projects (that are working fine locally), but I'm looking to host on the same server as my Wordpress site/portfolio.
I have put those folders in public_html folder in my file structure but they are generating a 404 error when I try to load them.
HTML based pages work fine, for PHP it's not. Does anyone have any ideas?
I'm sure I'm missing something fairly obvious but am at a loss at the moment...
You need to change the permission of files. Either change it via command line,
find foldername -type d -exec chmod 755 {} \;
find foldername -type f -exec chmod 644 {} \;
Or change it via cPanel,
Change permission for files to 644 and folders to 755
I'm trying to make some sort of cloud application on a headless raspbian machine.
The testing happens on a wamp-server running on windows8.1. PHP version is 5.6
The code works fine on my testing windows, but I run into issues when running the same code on my linux server. I've narrowed down the issue to the fact that (the linux user behind) my PHP code doesn't have write permissions on the folder where it should store files.
I can think of two ways to solve the issue: either give that php-user permissions, or change the user behind the php code. The last one would be quite interesting if it was possible to change per-script.
So, for my concrete question:
1) Where can I find what user is being used by my PHP code?
2) Can I change what user my PHP code uses, preferably on a per-project basis?
EDIT:
My script was running as root, as is shown by echo get_current_user();. I changed ownership of all files to root:webhosting, which was previously ftpuser:ftpgroup. However, when setting permissions to 770 I get access denied
EDIT2:
When using var_dump(posix_geteuid()); instead of get_current_user();, i get UID 33, which matches user www-data.
SOLUTION:
By looking at the EUID with var_dump(posix_geteuid(); I was able to validate the actual user, which does NOT match the get_current_user();. Changing the directroy and all files in it with sudo chown -R www-data:www-data <root of site> I managed to set the correct permissions.
I am not sure what the specifics are but normally when I have issues like that I change the ownership to www-data:www-data and if necessary for upload folders I change the folder permissions to 0755 and inside files permissions to 0644.
EDIT
I changed the permissions setting for security purposes.
You're PHP/Apache user is probably www-data. You probably want to run something like this.
sudo find path/to/project/ -exec chown www-data:root {} \;
File permissions may also be a problem. If so, run something like this.
sudo find path/to/project/ -type d -exec chmod 775 {} \;
sudo find path/to/project/ -type f -exec chmod 664 {} \;
This question already has answers here:
Recursively chmod/chown/chgrp all files and folder within a directory
(3 answers)
Closed 6 years ago.
I think my question explains everything. I want to use php's chmod() function to set a 777 permission on a folder, its subfolders and files.
Any Help is appreciated. THX.
chmod("Folder",0770);
function in php allow you to change permission of file and
for recursive change use exec
exec ("find /path/to/folder -type d -exec chmod 0770 {} +");//for sub directory
exec ("find /path/to/folder -type f -exec chmod 0644 {} +");//for files inside directory
make sure that your webserver have write access to the Folder.
Check these for more detail
http://php.net/manual/en/function.chmod.php
http://www.w3schools.com/php/func_filesystem_chmod.asp
There's a long winded way to do it in php, I would personally do it via the command line which PHP can interact with.
On the command line (Linux/Unix) you can do chmod options permissions filename
To recursively change permissions you would do chmod -R 0777 masterFile
So in PHP you would do exec("chmod -R 0777 masterFile");
-R means recursive so it would go to your sub-folders
The long winded way to do in PHP alone would be to get an array of the sub folders and do a foreach loop and run the chmod() function in PHP, but this way is cleaner.
See this link for more information on linux/unix chmod
Hope this helps.
I'm trying to recursively chmod all directories with php, and using:
find /path/to/dir -type d -exec chmod 777 {} \;
Works great from the command line, but using it from the server:
exec('find /path/to/dir -type d -exec chmod 777 {} \;');
Does nothing. Any ideas? Is it permission related? The path is the real path server level.
When you run it on the command line, you're running it as your user which probably is the owner of the path. When you exec() from PHP it is the Apache user that is doing it. Only the owner a a file/dir can chmod it. To confirm this is the case, try to run your exec() script from the PHP CLI Interactive Shell. Within the Interactive Shell, you can run PHP code but it will execute as your user.
If that turns out to be the cause, you must first chown the dir and it's sub files/dirs to be owned by the Apache user.