This question is quite similar to this one : Apache not allowing PHP to create file
However, the difference is that I'm running Apache under a XAMPP setup.
PHP looks like this :
file_put_contents('image.png', base64_decode("iVBORw0KGgoAAAANSUhEUgAA…lb6PwMAAAAASUVORK5CYII="));
Here the warning message when setting error reporting to E_ALL
:
Warning : file_put_contents(image.png): failed to open stream: No permission in /opt/lampp/htdocs/contentdb/index.php on line 215
(translated it, was in german originally)
What I tried to solve it, according to the accepted answer, and what had already worked in a "normal" Apache setup :
sudo chown www-data:www-data "/opt/lampp" -R
# I also tried chown with <myUserName>:<myUserName>, but it didn't work either
EDIT : After searching a bit, I found the file properties.ini
. It contains what I need.
[General]
installdir=/opt/lampp
base_stack_name=XAMPP
base_stack_key=
base_stack_version=7.2.7-0
base_stack_platform=linux-x64
base_stack_service=
require_root_privileges=1
[Apache] <- THIS IS THE IMPORTANT PART
apache_server_port=80
apache_user=daemon
apache_group=daemon
apache_server_ssl_port=443
apache_root_directory=/opt/lampp
apache_htdocs_directory=/opt/lampp/htdocs
apache_domainname=127.0.0.1
apache_configuration_directory=/opt/lampp/apache2/conf
[MySQL]
mysql_port=3306
mysql_host=localhost
mysql_root_directory=/opt/lampp/
mysql_binary_directory=/opt/lampp/bin
mysql_data_directory=/opt/lampp/var/mysql/
mysql_configuration_directory=/opt/lampp/etc
mysql_arguments=-u root -S "/opt/lampp/var/mysql/mysql.sock"
mysql_socket=/opt/lampp/var/mysql/mysql.sock
[PHP]
php_binary_directory=/opt/lampp/bin
php_configuration_directory=/opt/lampp/etc
php_extensions_directory=/opt/lampp/lib/php/extensions/no-debug-non-zts-20170718
Next thing to try will be chown with daemon:daemon
.
But still, the error message keeps appearing, and the file isn't there yet, too.
Any help is greatly appreciated.
EDIT : Problem solved, see answer below.
After looking up the
properties.ini
file, I found out that my Xampp Apache User was called daemon :apache_user=daemon apache_group=daemon
Therefore, this :
did the trick !