Apache error "Could not save png to "

Issues related to applications and software problems
Post Reply
bachoA4o
Posts: 3
Joined: 2019/01/15 10:05:20

Apache error "Could not save png to "

Post by bachoA4o » 2019/01/15 10:30:36

I'm trying to run a perl script that displays information about an interface and graphs in .png format.
The script must save the graphs in /var/www/html/grafika directory .
It displays the web page with the text but no graphs. Error log :

Code: Select all

AH01215: ERROR: Could not save png to '/var/www/html/grafika/graphHour.png
But when i run the script from the terminal and then access the web page the graps are there being displayed
Permmissions and ownership of /grafika (and dirs above) :

Code: Select all

drwxrws---. 2 root apache   6 Jan 15 12:15 grafika
I start the web server as user "apacheuser" and group "apache" , the group has full permissions on every directory.
I know its not right to give full permissions but this is a testing configuration.

pjsr2
Posts: 614
Joined: 2014/03/27 20:11:07

Re: Apache error "Could not save png to "

Post by pjsr2 » 2019/01/15 11:54:32

Writing to that directory may be forbidden by SELinux.
What is the SELinux context of the /var/www/html/grafika directory? You can see the SELinux context with

Code: Select all

ls -aZ /var/www/html/grafika
If you are new to SELinux, start reading with https://wiki.centos.org/HowTos/SELinux

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Apache error "Could not save png to "

Post by TrevorH » 2019/01/15 12:16:02

Ideally you never want to give the web server write access to a directory that also contains the code that it's running. If you have the option to save the files in a directory that isn't the one where grafika runs from then you can set the context on that to one that allows writing.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

bachoA4o
Posts: 3
Joined: 2019/01/15 10:05:20

Re: Apache error "Could not save png to "

Post by bachoA4o » 2019/01/15 13:08:00

pjsr2 wrote:
2019/01/15 11:54:32
Writing to that directory may be forbidden by SELinux.
What is the SELinux context of the /var/www/html/grafika directory? You can see the SELinux context with

Code: Select all

ls -aZ /var/www/html/grafika
If you are new to SELinux, start reading with https://wiki.centos.org/HowTos/SELinux
Yes that was the problem and i found that minutes after i posted the question , i set /grafika dir in domain httpd_sys_script_rw_t so scripts can read/write in it . Thanks for the fast answer :)

bachoA4o
Posts: 3
Joined: 2019/01/15 10:05:20

Re: Apache error "Could not save png to "

Post by bachoA4o » 2019/01/15 13:09:33

TrevorH wrote:
2019/01/15 12:16:02
Ideally you never want to give the web server write access to a directory that also contains the code that it's running. If you have the option to save the files in a directory that isn't the one where grafika runs from then you can set the context on that to one that allows writing.
Taking a note on that , i will change it . Thanks :)

Post Reply