Andrei Pall

Linux Software Engineering

How to setup Symfony ownership and permissions on Debian Linux

There are basically two ways to setup your ownership and permissions. Either you give yourself ownership or you make the webserver the owner of all files.

Webserver as owner (the way most people do it, and the Symfony doc's way):

assuming www-data (it could be something else) is your webserver user.

sudo chown -R www-data:www-data /path/to/your/symfony/root/directory

if you do that, the webserver owns all the files, and is also the group, and you will have some problems uploading files or working with files via FTP, because your FTP client will be logged in as you, not your webserver, so add your user to the webserver user group:

sudo usermod -a -G www-data andrei

Of course, this assumes your webserver is running as www-data, and your user is andrei.

Then you set all your directories to 755 and your files to 644... SET file permissions

sudo find /path/to/your/symfony/root/directory -type f -exec chmod 644 {} \;

SET directory permissions

sudo find /path/to/your/symfony/root/directory -type d -exec chmod 755 {} \;

Your user as owner

I prefer to own all the directories and files (it makes working with everything much easier), so, go to your Symfony root directory:

cd cd /var/www/symfony #assuming this is your current root directory
sudo chown -R $USER:www-data .

Then I give both myself and the webserver permissions:

sudo find . -type f -exec chmod 664 {} \;   
sudo find . -type d -exec chmod 775 {} \;

Then give the webserver the rights to read and write to var

Whichever way you set it up, then you need to give read and write permissions to the webserver for var and any other directories the webserver needs to upload or write too (depending on your situation), so run the commands from bash above:

sudo chgrp -R www-data var
sudo chmod -R ug+rwx var

Now, you're secure and your website works, and you can work with the files fairly easily.

Newer >>