Apache2 [SOLVED]: PHP doesn't save to files

Apache2 [SOLVED]: PHP doesn't save to files

Home Forums Apache2 Apache2 [SOLVED]: PHP doesn't save to files

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #36905



    I have Apache 2 and PHP installed on a Raspberry Pi 1 B+ (RASPBIAN STRETCH LITE
    ). I have a website running on it with a textbox and a PHP script that is supposed to save the contents of the textbox to a text file on the server when the user submits.
    I tryed basically everything but the php script just wont save.
    PHP does get the textbox-content (I tested it – it works just fine).

    This is my PHP:

    include "code/multiPage/topBar.html";
    $dir = "/data/searches.txt";
    if ($_REQUEST) {
        $input = $_REQUEST["search"];
        file_put_contents($dir, $input, FILE_APPEND);

    PHP is working properly aside from this problem.

    The folder has read-write permissions for everyone.
    I have also tryed to let PHP create its own folder with code similar to this:

    if (!file_exists('path/to/directory')) {
        mkdir('path/to/directory', 0777, true);

    PHP can’t even do that.

    Thanks in advance for any help!



    Accepted AnswerAnswer

    I figured it out. The problem was that the webserver didn’t have permission to write to the directory. problem solved by running sudo chown -R www-data var/www/html/data thanks for the help! Have a nice day 😀

    Source: https://stackoverflow.com/questions/48027640/php-doesnt-save-to-files
    Author: Jonas Karg
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.