3

SOLVED: See my answer below

I'm experiencing the same issue that Austin Hyde experienced in this question. I have an SQLite database that I can read, but not write.

Specifically, I'm getting General error: 8 attempt to write a readonly database in /var/www/html/green/database.php on line 34

My issue diverges from his as follows:

-As recommended in the answers to his question, I've made the database world-writeable, as well as the folder in which the database resides, with no luck. I've also set the owner of the database to "apache" as well as "nobody", without success.

-I've set the entire path set 777, beginning at /var (which I hate to do), no joy.

-I've messed about with SELinux (I'm running Fedora 12) to let httpd do whatever it wants; nothing.

I feel that I'm almost certainly missing something simple here, but I'm out of ideas.

What permissions need to be on an SQLite file in order to allow PHP / Apache to read and write to it via PDO?

Edit: Another related question, adding weight to the hypothesis that I've got a write permissions conflict somewhere.

Community
  • 1
  • 1
Steve V.
  • 463
  • 4
  • 14
  • Preemptive disclaimer: I checked the FAQ's for both serverfault and superuser before posting here and neither one seemed like the appropriate place for this question. However, I'm not opposed to migration if it'll get me better answers. – Steve V. Dec 18 '10 at 07:05

1 Answers1

3

For those who can not afford to disable SELinux entirely, here is the way to go.

To make a directory (say rw_data) and all it's content writable to any process running in httpd_t domain type ie. web-server processes, use following command as root.

chcon -R -t httpd_sys_content_rw_t "/var/www/html/mysite/rw_data/"

you can check SELinux context labels with following command :

ls -Z /var/www/html/mysite | grep httpd_sys_content_rw_t

This works on Fedora 16, should work on other SELinux enabled distros too.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
pbera
  • 46
  • 2
  • 1
    httpd_sys_content_rw_t is erroneous, it's httpd_sys_rw_content_t actually. Additionally, chcon is useless as that information will be lost after the first SELinux upgrade when restorecon is run on the system. Use semanage instead, e.g. semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/mysite/rw_data(/.*)?" – bviktor Apr 12 '16 at 17:48