Marthaj
asked on
Bash file erroring out on Ubuntu 20.04
I am having a problem successfully executing a bash file in Ubuntu.
The coding appears to be fine. The file basically check to see if a directory exists - if not it creates it and then assigns permission to it. It is for a symfony project.
It is to be executed with the web-site of the project i.e. /var/www/myproject
Here's a sample of the coding - very simple:
# Make the web/log dir if not exists
if [ ! -d web/log ]
then
mkdir -p web/log/error
mkdir -p web/log/failure
mkdir -p web/log/test
fi
chmod a+w web/log -R
and more sample:
echo Copying -dist files
cp -b -v apps/admin/config/app.yml-dist apps/admin/config/app.yml
Here is what I receive:
chmod: changing permissions of 'web/log/test': Operation not permitted
chmod: changing permissions of 'web/log/error': Operation not permitted
chmod: changing permissions of 'web/log/failure': Operation not permitted
PHP Warning: chmod(): Operation not permitted in /var/www/myproject.com/lib/vendor/symfony/lib/task/sfFilesystem.class.php on line 168
I have never added myself or any user or group to the www-data. No sure what it should be as to what to add. So I usually use sudo.
What am I doing wrong and how do I fix it ?
ASKER
Thank you for responding.
I am logged in to my server as marthaj - (administrator). I added myself to the www-data.
I also executed this to give execute permission to the install.sh file. this is what I executed:
chmod +x /var/www/myproject.com/ins tall.sh
That being so, shouldn't I be able to execute the install.sh and not receive those errors ?
I executed this: apachectl -S which tells me that the user/group is www-data. So doesn't it have control over my /var/www/myproject.com site then?
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
So if I am a part of the www-data now, why do I still receive the errors? Relaod Apache by systemctl reload apache2 ?
I am a bit confused here...as you can read..
I am logged in to my server as marthaj - (administrator). I added myself to the www-data.
I also executed this to give execute permission to the install.sh file. this is what I executed:
chmod +x /var/www/myproject.com/ins
That being so, shouldn't I be able to execute the install.sh and not receive those errors ?
I executed this: apachectl -S which tells me that the user/group is www-data. So doesn't it have control over my /var/www/myproject.com site then?
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
So if I am a part of the www-data now, why do I still receive the errors? Relaod Apache by systemctl reload apache2 ?
I am a bit confused here...as you can read..
Hi,
A dirty way to try and prove that the issue is permission related is to change the ownership of the web/log folder to www-data, so it can have the permissions to modify the folder. This does have security implications but you can always tighten permissions afterwards.
Cheers
A dirty way to try and prove that the issue is permission related is to change the ownership of the web/log folder to www-data, so it can have the permissions to modify the folder. This does have security implications but you can always tighten permissions afterwards.
Cheers
ASKER
Thank you for responding.
dfke - So do this:
And see what happens...
dfke - So do this:
sudo chown -R www-data /var/www/myproject.com
And see what happens...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for responding. It seems strange to me that I would still need to use sudo if I owned the folder. And yet, I can understand why the need.
To correct the problem, I need to alter the coding to include sudo preceding mkdir etc or execute the commands directly via terminal.
I will see what happens.
To correct the problem, I need to alter the coding to include sudo preceding mkdir etc or execute the commands directly via terminal.
I will see what happens.
you can reduce those 8 lines to 6
Open in new window
the account the web server is running as doesn't have permission to do that
you would need to make the account that the web server runs as either user or group owner
something like...
Open in new window