#
Let’s see how easy it is to setup our demo stack PHP, NGINX, MySQL, Redis and Composer:
1 - Clone Laradock inside your PHP project:
git clone https://github.com/Laradock/laradock.git
2 - Enter the laradock folder and rename env-example to .env.
cp env-example .env
3 - Run your containers:
docker-compose up -d nginx mysql phpmyadmin redis workspace
4 - Open your project’s .env file and set the following:
DB_HOST=mysql
REDIS_HOST=redis
QUEUE_HOST=beanstalkd
上に書いてある通りに実行した後、ブラウザから localhostにアクセスすると 404 Not Found nginx が表示されます。
/var/www/
UnexpectedValueException
The stream or file "/var/www/storage/logs/laravel-2019-09-28.log" could not be opened: failed to open stream: Permission denied
http://localhost/
Hide solutions
Database name seems incorrect
You're using the default database name laravel. This database does not exist.
Edit the .env file and use the correct database name in the DB_DATABASE key
READ MORE
Database: Getting Started docs
root@067f2585e287:/var/www# php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] Connection refused")
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel", "root", "", [])
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
root@067f2585e287:/var/www#
root@067f2585e287:/var/www# php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = default and table_name = migrations and table_type = 'BASE TABLE')
at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] Connection refused")
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=default", "default", "secret", [])
/var/www/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
root@067f2585e287:/var/www#
まず、mysqlコンテナに入って、ipアドレスを調査。この環境では、172.23.0.2 です。
~/lara/laradock$ docker-compose exec mysql bash
root@52340d840f63:/# hostname -i
172.23.0.2
UnexpectedValueException
The stream or file "/var/www/storage/logs/laravel-2019-09-21.log" could not be opened: failed to open stream: Permission denied
$ docker-compose exec mysql bash
root@403e510891bb:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql DATABASE(設定用DB)に入り、ユーザの認証方法を変更します。
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user, host, plugin from user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| default | % | caching_sha2_password |
| root | % | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
6 rows in set (0.00 sec)
mysql> alter user 'default'@'%' identified with mysql_native_password by 'secret';
Query OK, 0 rows affected (0.11 sec)
mysql> select user, host, plugin from user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| default | % | mysql_native_password |
| root | % | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
6 rows in set (0.00 sec)
mysql> exit
Bye
mysql に default user でログイン(パスワードは先程設定した “secret”)して、default DATABASEを確認できたらOKです。
root@403e510891bb:/# mysql -u default -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| default |
| information_schema |
+--------------------+
2 rows in set (0.00 sec)
mysql> use default
Database changed
mysql> show tables;
Empty set (0.01 sec)
mysql> exit
Bye
root@403e510891bb:/# exit
exit
mysql> show tables in default;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default' at line 1
$ docker-compose exec mysql bash
# mysql --version
mysql Ver 8.0.17 for Linux on x86_64 (MySQL Community Server - GPL)
# mysql -u default -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
なんか超久しぶりの mysql ターミナルでドキドキします。
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | default | | information_schema | +--------------------+ 2 rows in set (0.03 sec)
ここまでは良かった……。
mysql> SHOW TABLES FROM default;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default' at line 1
mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
$ docker-compose exec mysql bash
# mysql -u default -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
DB確認 – OK!
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| default |
| information_schema |
+--------------------+
2 rows in set (0.03 sec)
defaultテーブルが見られない、またシンタックスエラー!
mysql> SHOW TABLES FROM default;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default' at line 1
mysql> \q
Bye
# exit
mysql> SHOW TABLES FROM default;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default' at line 1
mysql> \q
Bye
# exit
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Building workspace Step 1/219 : ARG LARADOCK_PHP_VERSION Step 2/219 : FROM laradock/workspace:2.5-${LARADOCK_PHP_VERSION} ERROR: Service 'workspace' failed to build: manifest for laradock/workspace:2.5-5.7 not found