fr0tt / benotes

An open source self hosted notes and bookmarks taking web app.
https://benotes.org
MIT License
718 stars 49 forks source link

[SOLVED] Error while php artisan install #70

Closed ghost closed 1 year ago

ghost commented 1 year ago

I followed every step from docs, but when I enter docker shell to php artisan install this happens:

php artisan install
Initiate installation...

0/4 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command? (yes/no) [no]:
> yes

Application key set successfully.
1/4 [▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░]  25%
This will invalidate all existing tokens. Are you sure you want to override the secret key? (yes/no) [no]:
> yes

jwt-auth secret [SWfxPsPF0zaUoGb5KyPb5j5r2s3pEUHZDtLYLNIOkQrT3ZS3WrzCOEaX8I7dDHgq] set successfully.

2/4 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░]  50%

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command? (yes/no) [no]:
> yes

UnexpectedValueException

The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: No such file or directory
The exception occurred while attempting to log: The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: No such file or directory
The exception occurred while attempting to log: SQLSTATE[HY000] [1045] Access denied for user 'benotes'@'192.168.16.3' (using password: YES) (SQL: select * from information_schema.tables where table_schema = benotes and table_name = migrat
ions and table_type = 'BASE TABLE')
Context: {"exception":{"errorInfo":["HY000",1045,"Access denied for user 'benotes'@'192.168.16.3' (using password: YES)"]}}
Context: {"exception":{}}

at vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:146
142▕             restore_error_handler();
143▕             if (!is_resource($stream)) {
144▕                 $this->stream = null;
145▕
➜ 146▕                 throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened in append mode: '.$this->errorMessage, $url) . Utils::getRecordMessageForException($record));
147▕             }
148▕             stream_set_chunk_size($stream, $this->streamChunkSize);
149▕             $this->stream = $stream;
150▕         }

+9 vendor frames
10  [internal]:0
Illuminate\Foundation\Bootstrap\HandleExceptions::handleException(Object(UnexpectedValueException))

I'm pretty new with docker so I'm using portainer with a lot of other apps. I comment this because I thought it was a port error from mysql (I've had to change other mysql ports in the past to get things working), but I neither editing docker-compose.yml and manually hardcoding the port or editing DB_PORT at .env works.

While the php artisan install I choose yes on every step, but in the third I get this error.

Every file in the directory created by the git clone is writable by user and my user is the owner.

Thanks

fr0tt commented 1 year ago

Can you check if the path /var/www/storage/logs/laravel.log actually exists (or at least the directory /var/www/storage/logs) ?

Otherwise you need to make sure that you execute this command with the same user who owns /var/www/storage

ghost commented 1 year ago

/var/www/storage/logs exists, but it's empty. The owner is application:www-data`:

drwxr-xr-x    0 applicat www-data         0 Apr 17 16:30 logs

perms on www:

/var/www $ ls -la
total 1456
drwxr-xr-x    1 applicat applicat      4096 Apr 17 16:57 .
drwxr-xr-x    1 root     root          4096 Jan 10 23:47 ..
-rw-r--r--    1 applicat applicat       258 Jan 14 21:29 .editorconfig
-rw-r--r--    0 applicat applicat       599 Apr 17 16:53 .env
-rw-r--r--    1 applicat applicat       500 May 20  2022 .env.docker.example
-rw-r--r--    1 applicat applicat       357 Jun  8  2022 .env.example
-rw-r--r--    1 applicat applicat       424 Jun 29  2022 .env.sqlite.example
-rw-r--r--    1 applicat applicat       639 Mar  3 10:47 .eslintrc.js
drwxr-xr-x    1 applicat applicat      4096 Mar 10 10:28 .git
-rw-r--r--    1 applicat applicat       166 Mar  3 10:47 .gitattributes
-rw-r--r--    1 applicat applicat       370 Jan 14 21:29 .gitignore
-rw-r--r--    1 applicat applicat        36 Aug 20  2022 .prettierignore
-rw-r--r--    1 applicat applicat       174 Feb 24 19:11 .prettierrc.js
-rw-r--r--    1 applicat applicat       194 Jan 14 21:29 .styleci.yml
-rw-r--r--    1 applicat applicat      1465 Jan 14 21:29 Dockerfile
-rw-r--r--    1 applicat applicat      1062 May 20  2022 LICENSE
-rw-r--r--    1 applicat applicat       119 May 20  2022 Procfile
-rw-r--r--    1 applicat applicat      2321 Feb 24 19:11 README.md
-rw-r--r--    1 applicat applicat     15321 Feb 24 19:11 api.md
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 app
-rw-r--r--    1 applicat applicat       805 May 20  2022 app.json
-rw-r--r--    1 applicat applicat      1686 Jan 14 21:29 artisan
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 bootstrap
-rw-r--r--    1 applicat applicat      2036 Mar 10 10:28 composer.json
-rw-r--r--    1 applicat applicat    326212 Jan 14 21:29 composer.lock
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 config
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 database
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 docker
-rw-r--r--    1 applicat applicat      1159 Jun  6  2022 docker-compose.yml
drwxrwxrwx    1 applicat applicat      4096 Jan 10 01:08 html
drwxr-xr-x    1 applicat applicat      4096 Jan 10 01:27 localhost
-rw-r--r--    1 applicat applicat       206 May 20  2022 nginx.conf
-rw-r--r--    1 applicat applicat    955319 Mar 10 10:28 package-lock.json
-rw-r--r--    1 applicat applicat      2361 Mar 10 10:28 package.json
-rw-r--r--    1 applicat applicat      1251 Jan 14 21:29 phpunit.xml
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 playwright
-rw-r--r--    1 applicat applicat      3370 Jan 14 21:29 playwright.config.js
drwxr-xr-x    1 applicat applicat      4096 Mar 10 10:29 public
drwxr-xr-x    1 applicat applicat      4096 May 20  2022 resources
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 routes
-rw-r--r--    1 applicat applicat       569 Jan 14 21:29 server.php
drwxrwxr-x    1 applicat www-data      4096 Jun 29  2022 storage
-rw-r--r--    1 applicat applicat      1606 Mar  3 10:47 tailwind.config.js
drwxr-xr-x    1 applicat applicat      4096 Jan 14 21:29 tests
drwxr-xr-x   50 applicat applicat      4096 Mar 10 10:29 vendor
-rw-r--r--    1 applicat applicat      1550 Jan 14 21:29 webpack.mix.js
fr0tt commented 1 year ago

That's strange. Just to be sure you use docker-compose exec --user application app sh ? What are the permissions on the volume from the outside (docker/data/...) ? And out of curiosity do you have an user on your system with id 1000 ?

ghost commented 1 year ago

That's strange. Just to be sure you use docker-compose exec --user application app sh ?

Yup.

What are the permissions on the volume from the outside (docker/data/...) ?

Mmm I don't really know what you are asking me... I went to personal folder, then git clone the project and into the folder created by git did what's in the docs, but if you mean if I created a volume or something the answer is no. Otherwise, tell me which location I should look for, please.

And out of curiosity do you have an user on your system with id 1000 ?

Yup. uid

fr0tt commented 1 year ago

I'm talking about the directory that should be created inside the directory with your docker-compose.yml file (after you start the container containing the bind mounts). However in my previous post I wrote docker/data/ it's actually just data/, sorry. It should be owned by your user so use something like sudo chown -R 1000 data. Maybe that's the issue.

ghost commented 1 year ago

I've owned this folder recursively (chown -R), then I enter docker's shell (docker-compose exec --user application app sh) and php artisan install throw me this:

docker-compose exec --user application app sh
/var/www $ php artisan install
Initiate installation...

0/4 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command? (yes/no) [no]:
> yes

Application key set successfully.
1/4 [▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░]  25%
This will invalidate all existing tokens. Are you sure you want to override the secret key? (yes/no) [no]:
> yes

jwt-auth secret [BEHpMemKYHFFYRS16jXkjFjOccbXGkyQBVfkRTjGIZSvX5tgZRwd2Xza68q3tZhy] set successfully.

2/4 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░]  50%

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command? (yes/no) [no]:
> yes

Illuminate\Database\QueryException

SQLSTATE[HY000] [1045] Access denied for user 'benotes'@'192.168.16.3' (using password: YES) (SQL: select * from information_schema.tables where table_schema = benotes and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕         // If an exception occurs when attempting to run a query, we'll format the error
709▕         // message to include the bindings with SQL, which will make this exception a
710▕         // lot more helpful to the developer instead of just the database's errors.
711▕         catch (Exception $e) {
➜ 712▕             throw new QueryException(
713▕                 $query, $this->prepareBindings($bindings), $e
714▕             );
715▕         }
716▕     }

+30 vendor frames
31  app/Console/Commands/InstallCommand.php:57
Illuminate\Console\Command::call("migrate")

+13 vendor frames
45  artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
fr0tt commented 1 year ago

We're making some progress. Access denied means that your database user benotes misses permissions (or that it can't access the database at all but I'm not sure about that).

ghost commented 1 year ago

So I'm bit lost here. I've defaults conf in .env (except for http port):

APP_PORT=8002

RUN_MIGRATIONS=false

APP_NAME=Benotes
APP_ENV=production
APP_DEBUG=false
APP_URL=http://localhost:${APP_PORT}
APP_TIMEZONE=UTC

APP_KEY=base64:EAB3rEAqCq8O7FOx/JPQ/93q8P9EXcSOdb0bpi1M6wk=
JWT_SECRET=AxKmmeQLD1fi6Wi8C6apNDDYlFKlyaANKp72FRiV1wFOnPiXDSu9yhx8Rk3I5MIF
USE_FILESYSTEM=true

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3386
DB_DATABASE=benotes
DB_USERNAME=benotes
DB_PASSWORD=benotes

CACHE_DRIVER=file
QUEUE_CONNECTION=sync

MAIL_DRIVER=smtp
MAIL_HOST=
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME="Benotes"

JWT_ALGO=HS256

Everything else is untouched.

fr0tt commented 1 year ago

I tried to replicate it with your configuration and it failed. (I actually forgot to investigate if it's because you changed DB_PORT). What worked for me was to download a fresh copy of the env file and then afterwards changing APP_PORT to - in your case - 8002

ghost commented 1 year ago

Okay. I removed everything, benotes container and directory where I download initial files and started from scratch again, and worked this time.

I tried downloading the files by wget method, I don't know if that was the clue (it doesn't make sense) and as you, I have only changed APP_PORT. Thanks for your time (and patience). Closing the issue :)