cydrobolt / polr

:aerial_tramway: A modern, powerful, and robust URL shortener
https://polrproject.org
GNU General Public License v2.0
4.98k stars 891 forks source link

Installation confusion, no DB tables, subfolder install, Nginx, etc. #496

Open zwebmedia opened 5 years ago

zwebmedia commented 5 years ago

Hi there, thanks so much for putting this in FOSS, looks like an excellent script. Sorry I don't know anything about Laravel or the other one you mentioned. I am on DO Ubuntu 16.04 LEMP stack, Ubunto 16, Nginx. I need to install Polr in a subfolder /go.

I followed the installation docs and it didn't work, so now I am backtracking, and going step by step to see where I am going off base. I copy .env.setup to .env ok.

Now, I notice that the MYSQL configs in those files are commented out. Basic question: do I need to edit them manually to my db configs? Or is that part of the setup script? The install procedure doesn't say to edit them, so I don't edit them.

When I access /go/setup, leaving MYSQL config commented out, I get error:

PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

So it is trying to access the database using default credentials, and obviously that won't work. OK fine.

If I manually edit the MYSQL statement to un-comment them, and add my db settings, it can access the db, but I get an error db missing tables.

QueryException in Connection.php line 651: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'polrdb.links' doesn't exist (SQL: select * fromlinkswhereshort_url= go limit 1)

It tells me some basic things are working, like access to .env and some of the code. If I set document root to /go/public, I get 404 file not found errors.

182.52.216.47 - - [02/Dec/2018:06:12:05 +0000] "GET /go/setup HTTP/1.1" 404 152 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0"

So document root is set to domain root, then I access /go/public/index.php in NGINX config file. It is likely the problem is here somewhere. I have included NGINX config below.

Thank you again Sir, and any recommendations are much appreciated.

Expected Behavior

That is my question. What is the expected behavior when I access /go/setup? I would not expect to get an error about missing tables.

Current Behavior

DB error, missing tables.

Possible Solution

/go/setup is not running for some reason.

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

Your Environment

Here is NGINX config section for /go folder:

# See if this is Polr link shortener folder access.
location ~ ^/go/ { 
    root /var/www/mydomain/html;
location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;

        fastcgi_pass    php;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param   HTTP_HOST       $server_name;
    }

try_files $uri $uri/ /go/public/index.php$is_args$args;
 }
overint commented 5 years ago

I followed the installation docs and it didn't work, so now I am backtracking, and going step by step to see where I am going off base. I copy .env.setup to .env ok. Now, I notice that the MYSQL configs in those files are commented out. Basic question: do I need to edit them manually to my db configs? Or is that part of the setup script? The install procedure doesn't say to edit them, so I don't edit them.

You should use the setup script as your config seems normal. If you are stuck, just clean everything and start again. https://docs.polrproject.org/en/latest/user-guide/installation/

Follow the instructions exactly, as per the docs making sure that the permissions are set correctly on the polr install folder.

Create the database, copy the example env to .env and then run use the setup wizard to configure your install.

If you cannot access the setup page, there is likely an issue in your nginx config or directory structure/perms.

zwebmedia commented 5 years ago

OK thanks for the info. I am continuing to troubleshoot this. One thing I do not understand is this: since I need to be installed in a subfolder "/go", that is what is passed to the router. The router is expecting "/setup" but it will receive ""/go/setup". In the log files I can see GET /go/setup - 404 File Not Found. Please can you tell me how is this supposed to work in a subfolder install? Thank you for assistance.

overint commented 5 years ago

OK thanks for the info. I am continuing to troubleshoot this. One thing I do not understand is this: since I need to be installed in a subfolder "/go", that is what is passed to the router. The router is expecting "/setup" but it will receive ""/go/setup". In the log files I can see GET /go/setup - 404 File Not Found. Please can you tell me how is this supposed to work in a subfolder install? Thank you for assistan

Do you see that error in the lumen logs, or in the nginx logs? You may have to complete the setup manually, setting everything in https://github.com/cydrobolt/polr/blob/master/resources/views/env.blade.php

overint commented 5 years ago

Alternatively, you could use a subdomain.

zwebmedia commented 5 years ago

OK I did a Google search and I found this thread on running Laraval in a subfolder on Nginx:

https://stackoverflow.com/questions/27785372/config-nginx-for-laravel-in-a-subfolder

Example Nginx config file for Laravel subfolder install:

location ^~ /laravel { alias /var/www/laravel/public; try_files $uri $uri/ @laravel;

location ~ \.php {
    fastcgi_pass unix:/var/run/php7-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include /etc/nginx/fastcgi_params;
}

}

location @laravel { rewrite /laravel/(.*)$ /laravel/index.php?/$1 last; }

zwebmedia commented 5 years ago

Ok making progress. After using the Nginx config snippet above, /go/setup is found:

"GET /go/setup HTTP/1.1" 200 31 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0"

Making some progress. Next problem is the screen is still blank. Checking the Nginx error logs, I can see:

open() "/var/www/mydomain/html/static/font/css/fontello.css" failed (2: No such file or directory) open() "/var/www/mydomain/html/static/font/css/animation.css" failed (2: No such file or directory) open() "/var/www/mydomain/html/static/js/vendor.a93310d51acbd9480094.js" failed (2: No such file or directory) open() "/var/www/mydomain/html/static/js/manifest.f2341edd686e54ee9b4a.js" failed (2: No such file or directory) open() "/var/www/mydomain/html/static/css/app.5d0189b6f119febde070b703869bbd06.css" failed (2: No such file or directory) open() "/var/www/mydomain/html/static/js/app.de965bb2a0a8bffbeafa.js" failed (2: No such file or directory)

These paths are not correct. They should have /go/public in them, but instead they have /static.

I am continuing to troubleshoot and thank you so much for any assistance.

zwebmedia commented 5 years ago

Stand by please. I see that my test file /go/phpinfo.php is also showing blank screen, so please allow me to fix this first thanks.

The code snippet has affected the php interpreter. My test file is found, but it's not running:

"GET /go/phpinfo.php HTTP/1.1" 200 31 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0"

Working on it. Commenting out the alias statement allows php to work.

zwebmedia commented 5 years ago

Another important reference link to add SCRIPT_FILENAME:

https://phpnews.io/feeditem/host-laravel-in-a-sub-directory-with-nginx

location ^~ /apps/billreminder {
    alias /var/www/BillReminder/src/public;
    try_files $uri $uri/ @laravel;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/BillReminder/src/public/index.php;
    }
}

location @laravel {
    rewrite /apps/billreminder/(.*)$ /apps/billreminder/index.php?/$1 last;
}
zwebmedia commented 5 years ago

I will need to take a break on this. A bit painful. Several hours spent and no success. Latest status is:

Browser access to /go/setup results in browser error message about missing DB tables:

PDOException in Connection.php line 319: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'polrdb.links' doesn't exist

Simultaneously, a very strange Nginx access log 500 error on /go/setup:

"GET /go/setup HTTP/1.1" 500 36131 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:62.0) Gecko/20100101 Firefox/62.0"

Also getting a Nginx error in error log:

*2 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 182.52.216.47, server: myserver, request: "GET /go/setup HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:"

I am thinking this is over my ability to get working :(

zwebmedia commented 5 years ago

Still struggling here. I commented out all MSQL config statement in .env. I tried to hard code the site URL in env.blade.php

I am clearly doing something wrong, but what? The install instructions have no information about how to install in a subfolder, or how to troubleshoot. I know you said follow the instructions, I am really trying to do that, but my problem is I can't do that, since there aren't any instructions for subfolder install. I am left guessing, and I don't know anything about Laravel or Composer, Nginx config is trial and error, and since I never ran Polr before, I don't know what /setup should be doing.

I turned on all PHP error reporting and messages and debug mode, and there are no PHP errors shown in the browser. How can this be? I mean there is clearly something very wrong with my install, right? Shouldn't the program know when it can't load a js library for example and alert me? How can it be that the only error message I see is about missing DB table? Obviously many things have gone wrong before that point (like the tables weren't created), right? Yet there no error message to alert me.

This looks like a fine script and thank you again for making it FOSS, but sadly I don't think I will be able to get this working with the info provided.

zwebmedia commented 5 years ago

I found this thread which might be helpful to someone:

https://stackoverflow.com/questions/37366484/is-it-possible-to-install-lumen-or-laravel-only-in-a-sub-directory

"Also, because Lumen gets the wrong path when used from a sub directory you will need to change the following line in Lumens public/index.php: from $app->run(); to $app->run($app->make('request'));"

That was posted in 2016 so perhaps Lumen has been fixed.