Set permission at /home/appUploads (This folder should be created on where your
front end vue application is deployed due. For example
/var/www/myApp/vueAppDeployed/index.js
Then your home folder needs to be created in /var/www/myApp/vueAppDeployed/home/appUploads
(we need to set permission at /home/appUploads is because we have .env file in laravel
specificed upload files will be located at /home/appUploads)
This directoy is not directly accessible, we will need to first set permission
for www-data to access then set symlink for our application to access
1) set permission for www-data to access
1. Add current user ubuntu to apache www-data group
sudo adduser ubuntu www-data .
2. Need to disconnect relogin for group to take effect
3. create /home/appUploads directory
4. sudo chown ubuntu:www-data /home/appUploads
5. chmod g+s /home/appUpload. When this is set any new folders or
files created inside my-ssl.ca will autmoatically inheirt group www-data.
When this takes effect , s will appear in for example drwxrws--- folder
6.
- The default permission for ubnutu for a new folder is 755, or 750 inside a user's home folder, for a file is 644 or 640 insider a user's home folder. We do not want that
- To change it, we need to add ACL, this requires group id. $id www-data, to see webdev groupid
- $sudo setfacl -Rdm g:group_id:rx /home/appUpload(Note setfacl requires sudo apt-get install acl)
- R is recursive, which means everything under that directory will have the rule applied to it.
d is default, which means for all future items created under that directory, have these rules apply by default. m is needed to add/modify rules. This command is to give future items created or copied to my-ssl.ca only read and execute permission (Caution, moved file will not obey this rule) When this has effect drwxr-x---+ a + will appear showing ACL has effect - use $getfacl folder to check if it is working. There should be default:user rwx, default:webdev:rw-
- For existing items use $sudo setfacl -Rm g:group_id:rx /home/appUpload
sudo usermod -a -G group user. (https://askubuntu.com/questions/79565/how-to-add-existing-user-to-an-existing-group)
For it to have effect, usually need user to re-login, for apache2 user, need to restart apache2.
sudo service apache2 restart.
2) set sym link for application to access
Symbolic Link
By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, / (root) directories (when enabled) and /usr/share (when enabledfor web applications).
If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.
The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www. This is different to previous releases which provides better security out of the box.
Allow more directory access :
vim /etc/apache2/apache2.conf.
Require all grant meaning allow access
Options FollowSymLinks means symbolic link can be established
<Directory /> | |
Options FollowSymLinks | |
AllowOverride None | |
Require all denied | |
</Directory> | |
<Directory /usr/share> | |
AllowOverride None | |
Require all granted | |
</Directory> | |
<Directory /var/www/> | |
Options Indexes FollowSymLinks | |
AllowOverride None | |
Require all granted | |
</Directory> |
wq!
sudo service apache2 restart
/*
*
*/
The above configuration allows all folders in /var/www can be accessed, and symlinks set up in /var/www to other directory can be followed.
to set up a sym link : https://askubuntu.com/questions/843740/how-to-create-a-symbolic-link-in-a-linux-directory
Use ln
:
ln -s /var/www/vhosts/ecash_cfe /var/www/vhosts/ecash-staging.com/ecash_root
-s
stands for symbolic link/var/www/vhosts/ecash_cfe
is the source file/var/www/vhosts/ecash-staging.com/ecash_root
is the link name
sudo mkdir /var/www/html/home#change groupsudo chown ubuntu:www-data homesudo chmod 750 home# link /var/www/html/home to /home/appUploads. So XXX/home/appUploads is accessing /home/appUploadssudo ln -s /home/appUploads /var/www/html/homehttps://joeyxff.blogspot.com/2021/06/apache-default-directory-access-and-how.html
Directly access the symlink folder is forbidden but symlink to a particular resource is good like
https://app.tronappca.com/wcstoreadmin/home/appUploads/super%20admin/Joey%20Xiang/products/6971cc9f-eb55-4063-8ef2-3d4293ce0a68.jpeg
is good
but
https://app.tronappca.com/wcstoreadmin/home/appUploads/super%20admin/Joey%20Xiang/products/
No comments:
Post a Comment