Fatal Error when uploading file - Apache config

Hi,

I try to upload a file on my cakephp app thanks to Josegonzalez/Upload. I’ve got an error, I guess due to apache configuration. In local everything works, but not in my server.
By the way, file upload with wordpress or with a simple PHP form works on my server. I had to specify in my php.ini

upload_tmp_dir = /tmp

to make it work for Wordpress. I also tried

open_basedir = /tmp
or
;open_basedir = /tmp
or
open_basedir = /tmp/apache2 (I created a folder in /tmp with www-data as owner)

but it still does not work for cakephp.

The following is my error

Fatal error: [InvalidArgumentException] Invalid stream reference provided #0 /home/rom1/public_html/cakephp/vendor/zendframework/zend-diactoros/src/Stream.php(58): Zend\Diactoros\Stream->setStream('/tmp/phpKu6O1j', 'r') #1 /home/rom1/public_html/cakephp/vendor/zendframework/zend-diactoros/src/UploadedFile.php(164): Zend\Diactoros\Stream->__construct('/tmp/phpKu6O1j') #2 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequest.php(460): Zend\Diactoros\UploadedFile->getStream() #3 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequest.php(361): Cake\Http\ServerRequest->_processFiles(Array, Array) #4 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequest.php(300): Cake\Http\ServerRequest->_setConfig(Array) #5 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequestFactory.php(56): Cake\Http\ServerRequest->__construct(Array) #6 /home/rom1/public_html/cakephp/vendor/cakephp/c in /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Error/ErrorHandler.php on line 180



Warning: file_exists(): open_basedir restriction in effect. File(/home/rom1/public_html/cakephp/logs/error.log) is not within the allowed path(s): (..) in /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 188



Warning: file_put_contents(): open_basedir restriction in effect. File(/home/rom1/public_html/cakephp/logs/error.log) is not within the allowed path(s): (..) in /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133



Warning: file_put_contents(/home/rom1/public_html/cakephp/logs/error.log): failed to open stream: Operation not permitted in /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Log/Engine/FileLog.php on line 133



Fatal error: [InvalidArgumentException] Invalid stream reference provided #0 /home/rom1/public_html/cakephp/vendor/zendframework/zend-diactoros/src/Stream.php(58): Zend\Diactoros\Stream->setStream('/tmp/phpKu6O1j', 'r') #1 /home/rom1/public_html/cakephp/vendor/zendframework/zend-diactoros/src/UploadedFile.php(164): Zend\Diactoros\Stream->__construct('/tmp/phpKu6O1j') #2 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequest.php(460): Zend\Diactoros\UploadedFile->getStream() #3 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequest.php(361): Cake\Http\ServerRequest->_processFiles(Array, Array) #4 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequest.php(300): Cake\Http\ServerRequest->_setConfig(Array) #5 /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Http/ServerRequestFactory.php(56): Cake\Http\ServerRequest->__construct(Array) #6 /home/rom1/public_html/cakephp/vendor/cakephp/c in /home/rom1/public_html/cakephp/vendor/cakephp/cakephp/src/Error/ErrorHandler.php on line 180

If I can’t make it work I guess I’ll be forced to implement my simple PHP script in cakephp to upload a file, at least this works.

Read this:

according to above, look for your option in httpd.conf not php.ini or check somehow settings of you open_basedir and make your temp folder in this path (configure).

Thanks for your reply.

I finally understood that the problem was not in my php.ini. I tried to change open_basedir there but it never worked.

As I’m working with userdir, I had to go to /etc/apache2/mods-available/userdir.conf
And change

php_admin_value open_basedir ".."

To

php_admin_value open_basedir ..:/tmp

But I can’t get why it was working with Wordpress and not CakePHP…