Chmod all php files recursive

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.

asked Dec 27, 2010 at 14:54

usr-local-ΕΨΗΕΛΩΝusr-local-ΕΨΗΕΛΩΝ

25k29 gold badges150 silver badges283 bronze badges

5

Use bash in the MediaWiki directory

find . -iname "*.php" | xargs chmod +x

answered Dec 27, 2010 at 15:02

3

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.

answered Dec 27, 2010 at 15:11

philonousphilonous

3,2413 gold badges26 silver badges24 bronze badges

4

How can I recursively chmod everything inside of a folder?

e.g. I have a folder called var which contains many subfolders and files.

How can I apply chmod 755 recursively to this folder and all its contents?

asked May 23, 2018 at 10:13

Chmod all php files recursive

1

Please refer to the manual (man chmod):

-R, --recursive
change files and directories recursively

chmod -R 755 /path/to/directory would perform what you want.

However…

  1. You don't usually want to 755 all files; these should be 644, as they often do not need to be executable. Hence, you could do find /path/to/directory -type d -exec chmod 755 {} \; to only change directory permissions. Use -type f and chmod 644 to apply the permissions to files.

  2. This will overwrite any existing permissions. It's not a good idea to do it for /var — that folder has the correct permissions set up by the system already. For example, some directories in /var require 775 permissions (e.g., /var/log).

So, before doing sudo chmod — particularly on system folders — pause and think about whether that is really required.

answered May 23, 2018 at 10:19

Chmod all php files recursive

slhckslhck

215k65 gold badges580 silver badges570 bronze badges

4

For a PHP-based web site, many sources like this one recommend 755 for directories and 644 for files.

If you are in the DocumentRoot of the website, you can set this as follows:

find . -type d -exec chmod 755 {} \;

find . -type f -exec chmod 644 {} \;

answered Jun 25, 2020 at 1:11

If you wish to apply chmod to a specific directory/ file you can make use of find as following:

find . -type f -name "*.sh" -print0 |xargs -0 chmod 755

answered Mar 20, 2020 at 0:01

Chmod all php files recursive

To set the rights for all files (to 644) and all directories (to 755) in your directory YOUR_CATALOG at once you can use this:

find YOUR_CATALOG -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +

answered Oct 19, 2020 at 9:37

Chmod all php files recursive

KornelKornel

1193 bronze badges

You can give all permission for your localhost

sudo chmod -R goa=rwx /path/to/directory

answered Sep 21, 2021 at 21:21

Chmod all php files recursive

1

How do I apply chmod to all subdirectories?

Changing permissions with chmod To modify the permission flags on existing files and directories, use the chmod command ("change mode"). It can be used for individual files or it can be run recursively with the -R option to change permissions for all of the subdirectories and files within a directory.

How do I set permissions in PHP?

Use the is_readable() , is_writable() , is_executable() to check if a file exists and readable, writable, and executable. Use the chmod() function to set permissions for a file.

How do I chmod a whole directory in Linux?

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.

Which octal number is used for read and execute permission in PHP?

The parameter "mode" consists of three octal number components: access restrictions for the owner, user group in which the owner is in, and everybody else in this order. Number 1 means that we grant execute permissions, number 2 means that we make the file writeable, and number 4 means that we make the file readable.