My server is in /var/www/html I have a php script in /var/www/html/fileio_test/io_test.php
By default, Apache on Ubuntu runs as www-data.
Let's assume your folder is located in /var/www/mysite.
You can do this:
chown -R www-data:www-data /var/www/mysite
chmod -R og-r
/var/www/mysite
After doing this,www-data
(the Web server) will have full access to the site's files, while other non-root users will have no access at all.If you wish to allow select users to access the site, you can make the folder group-readable and add those users to the group www-data.
Set correct permissions on your apache files
In order for this file to be readable for both the user "djameson" as well as the webserver, you need to do 4 things:
chown
)of the file, so that it is owned by the user django and the group you just set up.chmod
) allow read permission by the group.if some of your files are outside of www directory and you would like to provide access to files outside of apache environment you may use chmod -R o+rx
Above would give "other users(also include apache user)" permission to read/execute files
As your file residing in your Home directory, I would suggest one of following approaches.
Give 0777 permission to file itself.
chmod 0777 /home/djameson/test.txt
Change Ownership to apache user www-data and give owner-write permission.
sudo chown www-data:www-data /home/djameson/test.txt
chmod 0744 /home/djameson/test.txt
Add your user to www-data group or vice-verse add www-data user to your group. And then group write permission.
sudo usermod -a -G www-data djameson
chmod 0764 /home/djameson/test.txt
NOTE : I am assuming apache user name & group name is www-data & www-data respectively. You must change accordingly your server apache username/group name.