Search code examples
phpdebianprestashoplamp

Write permission denied on Apache2 / Debian 9


I have a VPS with apache2 php-fpm running prestashop, it's been working for years, but out of a sudden, prestashop is having trouble with permissions.

Apache's user and group is set to "www-data" the same as all the files and folders in the www folder. All permissions are set to 755 and 644 but cache/smarty (Had to set those to 777 so the store could keep working.)

I've checked that its a permissions problem as prestashop cant regenerate the .htaccess file from the backoffice (unless I set it to 777).

I'm not sure what to check or what can I supply to you. Any help is welcome. Thank you all for your time.

EDIT

I've been checking the processes for "apache2" and all of them were run by www-data.

Steadweb told me to check php-fpm, seems like thats the problem. But I'm not sure where to change that.

enter image description here


Solution

  • Tested on Debian 9.7, edit the following file:

    /etc/php/7.0/fpm/pool.d/www.conf
    

    And find the following, where user / group is declared. Update as follows:

    ...
    user = www-data
    group = www-data
    

    You'll need to restart the apache / php-fpm processes

    ressystemctl restart php7.0-fpm apache2
    

    Notes

    • This is bad practice, as you're opening up privileges for php-fpm. I'd make sure that specific directories / files have write permissions.
    • Set your web directory to ownership of your user chown -R user:www-data /path/to/website
    • Use the following commands to set the permissions for directories / files for you website
    cd /path/to/website
    find -type d -exec chmod 750 {} \;
    find -type f -exec chmod 644 {} \;
    
    • Then, open up specific files / directories that require writable access.