Wednesday 29 August 2018

linux - Virtualbox Ubuntu 18.04 permission issue to symlinked share host folder


Trying to get a Ubuntu 18.04 installation for Wordpress on a Win 10 host. The host shares a folder with the VM, which is the root to multiple projects. This is a fresh VM built from the std Ubuntu 18/04 LTS x64 Server image.


I install nginx and I can see the Welcome page. I then delete the /var/www/html folder and re-create using a symlink to my shared folder:


sudo ln -s /media/sf_Wordpress /var/www/html

When I browse my server, I get 502 Bad Gateway.


If I cd into /var/www/hmtl I get permission denied. If I change to root I can access the folder and list all files in the share.


My nginx log says:


papa@wp:~$ tail -f /var/log/nginx/error.log
2018/05/30 05:05:05 [crit] 766#766: *4 stat() "/var/www/html/mysite1/" failed (13: Permission denied), client: 192.168.0.5, server: mysite1.com.au, request: "GET / HTTP/1.1", host: "mysite1.com.au"
2018/05/30 05:05:05 [crit] 766#766: *4 stat() "/var/www/html/mysite1/" failed (13: Permission denied), client: 192.168.0.5, server: mysite1.com.au, request: "GET / HTTP/1.1", host: "mysite1.com.au"
2018/05/30 05:05:05 [error] 766#766: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.0.5, server: mysite1.com.au, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mysite1.com.au"
2018/05/30 05:05:05 [crit] 766#766: *4 connect() to unix:/tmp/php-cgi.socket failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.5, server: mysite1.com.au, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.socket:", host: "mysite1.com.au"

I added www-data to vboxsf group. No difference.


Checking the nginx process tells me it is being run by root:


papa@wp:~$ ps -eo pid,comm,euser,supgrp | grep nginx
1888 nginx root root
1891 nginx www-data www-data,vboxsf

Using the suggestion from here, I ran:


sudo chown -R www-data:www-data /var/www/html

But it made no difference. Still 502 Bad gateway.


Running nginx -t shows:


papa@wp:~$ nginx -t
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2018/05/30 07:37:21 [warn] 1905#1905: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
2018/05/30 07:37:21 [emerg] 1905#1905: open() "/etc/nginx/sites-enabled/fca.conf" failed (13: Permission denied) in /etc/nginx/nginx.conf:62
nginx: configuration file /etc/nginx/nginx.conf test failed

My nginx config fca.conf for this site is:


# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}

server {
## Your website name goes here.
server_name mysite1.com.au;

## Your only path reference.
root /var/www/html/mysite1;

## This should be in your http block and if it is, it's not needed here.
index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

Answer



Do not forget your shared folder is not really a linux filesystem, only looks a bit like it. Copy everything from the share to a real linux filesystem, and try again.


Don't change the properties of the link


sudo chown -R www-data:www-data /var/www/html

Change the properties of the origin


sudo chown -R www-data:www-data /media/sf_Wordpress

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...