1
votes

Server version: Apache/2.4.34 (Unix) NOTE: This is not a Plesk or control panel questions. This is a custom PHP application hosted on a Rackspace dedicated server with no control panel.

I'm trying to utilize an existing SSL certificate for several sub-directories of a domain, but the architecture for the domain separates out two directories for non-secure/secure:

httpdocs
httpsdocs

I copied everything from httpdocs to httpsdocs and also forced traffic to https using .htaccess. Everything worked great until I tried the PHP file upload functionality.

Here's the bit of code that is failing from the secure side:

$path = "uploaded_files/".$row_query[0].'/'.$file_name;
copy($temp_file, $path);

In doing some debugging, I found that the temp file gets created: /tmp/phpanKT4N

but the error I see in the logs is: copy(uploaded_files/New Sub Folder/30052_testing.txt): failed to open stream: Permission denied in /var/www/vhosts/.com/httpsdocs/demo/resource/add_resource.php on line 108

I tried changing copy() to move_uploaded_file() but here's the error for that:

PHP Warning:  move_uploaded_file(uploaded_files/test/30054_testing.txt): failed to open stream: No such file or directory in /var/www/vhosts/<thedomain>.com/httpsdocs/demo/resource/add_resource.php on line 111
PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phpOC9YEF' to 'uploaded_files/test/30054_testing.txt' in /var/www/vhosts/<thedomain>.com/httpsdocs/demo/resource/add_resource.php on line 111

I searched stack and saw that ownership must match, but the permissions appear to be the same for httpdocs and httpsdocs.

The /tmp folder is owned by root:root and like I said this works perfectly from the non-secure folder. The non-secure and secure upload folders are identical:

httpdocs:

drwxrwxr-x+  8 theuser apache  4096 Sep 22  2015 uploaded_files

httpsdocs:

drwxrwxr-x+  8 theuser apache  4096 Sep 22  2015 uploaded_files

Is this a configuration, permissions issue, or what?

1
Sounds like the directory is restricted still. What are the user/mod set on httpdocs and httpsdocs themselves? (the parent) Are they the same too? - IncredibleHat
Also, it looks like you are trying to move a file into a sub folder of uploaded_files ... is that sub folder existing and have the same write privs for the apache user/group? - IncredibleHat
I just tried uploading to a sub-directory that definitely exists and has the same ownership and parent upload directory drwxrwxr-x+ 8 theuser apache 4096 Sep 22 2015 uploaded_files sub-directory drwxrwxr-x+ 2 theuser apache 4096 Sep 22 2015 HOA Covenents This works in the non-secure, httpdocs directory but not in httpsdocs. Is there anything I need to add or tweak possibly in php.ini to make this work in SSL? The directory/sub-directory permissions are identical in httpdocs and httpsdocs but only httpdocs works. - Mitch Moccia
Everything sounds like it should be working then :( I work in a SSL only structure too and no issues once I got the apache user and permissions right for directories that PHP touches. Sometimes I forget and make a new directory and then get those kinds of errors. Curious what the issue here is then. - IncredibleHat
Figured it out, posted the solution. Thanks for the assist - Mitch Moccia

1 Answers

0
votes

Figured this out... Ran the following:

First find apache's user:

egrep -i '^user|^group' /etc/httpd/conf/httpd.conf 

Result: User apache Group apache

Then ran this and it solved all the PHP file upload issues in httpsdocs:

chown -R apache:apache /var/www/vhosts/<thedomain>.com/httpsdocs/
chmod -R g+rw /var/www/vhosts/<thedomain>.com/httpsdocs/