Virtualbox Ubuntu 18.04 permission issue to symlinked share host folder

0

1

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;
        }
}

TheRealPapa

Posted 2018-05-30T04:41:19.740

Reputation: 133

Hi, x64. I added the shared folder via VBox interface (auto-mount, permanent). Then created a simlink so the projects / shared folder is "sees" as /var/www/html. Doing an ls here shows the project on the host. It seems like my user papa and www-data cannot access the content of the shared folder pointed to by the simlink – TheRealPapa – 2018-05-30T06:14:35.333

"Checking the nginx process tells me it is being run by root:" No it does not. It is started by root, but runs as www-data. You would be mad nowadays to run a web-server as root. – Gerard H. Pille – 2018-05-30T08:08:14.503

Hi Gerard, this is just local dev env, so I just want it working, production will not be in a VM environment like this. – TheRealPapa – 2018-05-30T16:06:50.217

OK, added something to my answer. – Gerard H. Pille – 2018-05-30T19:34:18.353

Answers

1

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

Gerard H. Pille

Posted 2018-05-30T04:41:19.740

Reputation: 542

Hi Gerard, but this setup is working in Homestead for my Laravel projects. These sit on my Windows shared folder, yet are visible and executable by nginx (www-data) from the guest Ubuntu side. – TheRealPapa – 2018-05-30T16:05:57.683

Hi Gerard, the initial issue seems to point to nginx not having write access to /var/log/nginx/error.log also. Why would a vanilla installation have these access issues? – TheRealPapa – 2018-05-30T23:50:44.757

That was papa running nginx, not www-data. Try "sudo nginx -t". – Gerard H. Pille – 2018-05-30T23:55:48.153

Ahh got it! Thanks for that. Got rid of the error – TheRealPapa – 2018-05-31T00:28:06.027

Then you could perhaps accept the answer? – Gerard H. Pille – 2018-05-31T03:29:15.183

Hi Gerard, I am still getting permission denied in my nginx log and I get a 404 page now when accessing the server via browser – TheRealPapa – 2018-05-31T03:35:51.617

rebooted and now it works?! – TheRealPapa – 2018-05-31T03:40:37.883

Machine or virtualbox client? – Gerard H. Pille – 2018-05-31T04:03:25.330