1

I use phpword, a ms-word document generator. It creates a temporary file then it renames it to the correct .docx format.

The user projop owns the php script and it run it as projop.

There isn't any httpd involved because it's a call from a TCL app using the exec function.

I created the php's temp folder in /home/projop/tmp and given 0777 plus made sure it's owned by projop:projop.

Should this belong to root group or maybe apache group? I'm on CentOS 6.5. not sure but I keep getting permission denied.

The php script Template.php that renames is also owned by projop

Warning: rename(/home/projop/tmp/yRRXn0,Mission Announcement Sheet - BB&T76.docx): Permission denied in /var/www/html/doc-generate/wwwroot/phpword/src/PhpWord/Template.php on line 340 Warning: rename

I dont know what's wrong. The user who owns the script is projop, the tmp folder is on the user's home directory and it's owned by projop.

Im not sure what's going on.

The /tmp folder permission:

[root@project-open-v40 projop]# ls -la
total 493808
drwxr-xr-x.  7 projop root        4096 Aug  6 09:40 .
drwxr-xr-x.  3 root   root        4096 Jul  9 09:37 ..
drwxrwxr-x.  4 projop projop      4096 Oct 16  2012 acs-bootstrap-installer-master
-rwxr-xr-x.  1 projop projop     27527 Jul 15 10:32 gain_fns.php
-rw-r-----.  1 projop projop      2487 Jul 17 11:49 logo.gif
-rw-rw-r--.  1 projop projop     52535 Jul 23 09:57 master
-rwxr-xr-x.  1 projop projop      3039 Jul 28 14:37 notifyPM.php
-rw-r--r--.  1 projop projop     59719 Aug  5 09:35 resetInvoice.php
drwxr-xr-x.  3 apache apache      4096 Mar 12 15:34 templates
-rw-r--r--.  1 apache projop   7966720 Jul  9 09:37 templates.tar
drwxrwxrwx.  2 projop projop      4096 Aug  6 09:54 tmp
drwxr-xr-x.  6 apache apache      4096 Mar  2 02:43 vendor
-rw-r--r--.  1 apache projop 211886080 Jul  9 09:38 vendor.tar
drwxr-xr-x. 18 apache apache      4096 Jul  7 10:40 wwwroot
-rw-r--r--.  1 apache projop 285624320 Jul  9 09:38 wwwroot.tar

/tmp folder contents:

[root@project-open-v40 tmp]# ls -la
total 152
drwxrwxrwx. 2 projop projop  4096 Aug  6 09:54 .
drwxr-xr-x. 7 projop root    4096 Aug  6 09:40 ..
-rwxrwxrwx. 1 projop projop 34854 Aug  6 09:53 G0pC83
-rwxrwxrwx. 1 projop projop 34854 Aug  6 09:42 lLm9Iz
-rwxrwxrwx. 1 projop projop 34854 Aug  6 09:46 NR8CSg
-rwxrwxrwx. 1 projop projop 34854 Aug  6 09:54 yRRXn0
Rémi Becheras
  • 14,902
  • 14
  • 51
  • 81
unixmiah
  • 3,081
  • 1
  • 12
  • 26

2 Answers2

2

use chmod to change the permissions of the file before you attempt to rename it - changing the permissions to the 0777 as you have for the folder.

http://php.net/manual/en/function.chmod.php

Also use http://php.net/manual/en/function.fileperms.php to return the current values of the file, see if there's anything unusual there?

Another alternative if this fails is to use the PHP script to load the contents of the file and then save the contents under a new name, and delete the original. This is the long process of what renaming in effect does. This is less than ideal but is an option.

Edit:

You may not be allowed to rename contents of the /tmp/ folder, as it is a dedicated and specified temporary folder, so instead of renaming it there, try the process above of opening the file and then renaming and saving it to another more permanent destination.

Martin
  • 22,212
  • 11
  • 70
  • 132
  • #Martin thank you -- I did that and that helped- but the issue was path to the file, I guess you need a path from and to - I don' t understand why php's error message couldn't give out a hint- took hours to figure out but thanks to you guys for the quick help. – unixmiah Aug 06 '15 at 14:19
2

Looking at the rename command warning:

Warning: rename(/home/projop/tmp/yRRXn0,Mission Announcement Sheet - BB&T76.docx): Permission denied in /var/www/html/doc-generate/wwwroot/phpword/src/PhpWord/Template.php on line 340 Warning: rename  

you're attempting to rename the file without specifying the path. This is then trying to rename to a different location from your expected /home/projop/tmp/

Try pre-pending the path to the second argument and trying again.

mproffitt
  • 2,409
  • 18
  • 24
  • yes, This will save the renamed file into the current PHP working directory. Good point I missed, +1 – Martin Aug 06 '15 at 14:11
  • @mplf thank you- i tried it and it's working well. I'm not sure why php didn't point out the error, something like "must specify destination folder" or something along that line- I've spent hours trying to figure out what's wrong. No where on the internet or on php.net's website it doesn't mention the error cause be caused from not specifying path- this should be something built in or have proper error message. – unixmiah Aug 06 '15 at 14:18