7

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.

usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
  • 2
    I don't think you need to make all files executable. Ordinary php include scripts don't need the flag. It's only advised for commandline scripts. Hence use a few `chmod +x */*.php` and `chmod +x */*/*.php` only in the appropriate tools folder. – mario Dec 27 '10 at 15:04
  • @mario, if I recall correctly it's a possible (though probably uncommon) server setup that makes use of the "X Bit Hack". – Álvaro González Dec 27 '10 at 15:08
  • You should always qualify your chmod commands. `chmod a+x *.php*` will set the execute bit for user, group and world. This is implicitly what you're doing anyway, but clearer. You may only need to set executable for user and group (`chmod ug+x`) depending on your situation, and if this will work you should do it that way. – sorpigal Dec 27 '10 at 15:49
  • For security reasons I would avoid using `a` or `o` (or implying `a` by leaving a qualifier out). It's safer to have `ug+x,o-x` – Dennis Williamson Dec 27 '10 at 19:47
  • Sorry Dennis, but since Apache runs as wwwrun, it is **required** for scripts to be executable by others – usr-local-ΕΨΗΕΛΩΝ Dec 27 '10 at 22:29

2 Answers2

16

Use bash in the MediaWiki directory

find . -iname "*.php" | xargs chmod +x
shfx
  • 1,261
  • 1
  • 11
  • 16
2

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.

philonous
  • 3,621
  • 3
  • 27
  • 24
  • Because chmod can operate on multiple files at once and because this operation will not fail when done in parallel you should be using `+` instead of `\;` to close your `-exec`. – sorpigal Dec 27 '10 at 16:48
  • '*.php*' was thought to match .php and .php5, not subdirectories ;) – usr-local-ΕΨΗΕΛΩΝ Dec 27 '10 at 22:31
  • Don't use `+` when you have no idea on the amount of the items in the resulting list. This will introduce a Bohrbug into your script. If the list is big enough, you will exceed the maximum length of the executable command line (OK, I know it is larger than 2 Mbytes, but it is still unsafe) – karatedog Dec 27 '10 at 23:07
  • @djechelon: Of course it was thougth to match ".php" and ".php5", but your problem was that it didn't work for subdirectories. Nevertheless a subdirectory named "subdir" (including several files ending with ".php" or ".php5" itself) won't be considered, simply because "subdir" does not match "*.php*". Therefore the executable bit is not set for "*.php*"-files in "subdir" ... ;) – philonous Dec 28 '10 at 13:05