CI4 Spark migrate fails to connect to db with devilbox |
Hello all - first time poster here...
I am using a corporate restricted laptop requiring me to develop in containers. I am using Devilbox in conjunction with Docker desktop, which is a tool that nicely puts together various LAMP stack options in containers to provide for a development environment. Each component (httpd, mysql, php, etc) is in a separate container and thus has a different IP address. Devilbox requires that the IP address be used for the db hostname within its own internal network - the ports are then mapped to the host computer allowing for the host computer to appear as though it were running the application locally/natively. Devilbox is up and running as is CI4 within the devilbox environment. I have connectivity to the mysql db via CI4 and have validated it via the following code in the home::index controller: PHP Code: $db = db_connect(); The CI4 debugger is reporting a good connection to the db via the code above: PHP Code: Database (1 total Query, 1 unique across 1 Connection) The issue is that when I attempt to run spark migrate from the command line, it cannot connect to the db. The command used which fails is: PHP Code: php spark migrate --all The error message returned is the following: PHP Code: CodeIgniter v4.4.3 Command Line Tool - Server Time: 2023-12-06 20:53:23 UTC+00:00 The logs for the error message are as follows: PHP Code: ERROR - 2023-12-06 21:02:43 --> Error connecting to the database: mysqli_sql_exception: Operation timed out in /Users/p482017/devilbox-3.0.0-4/data/www/ci4.db/htdocs/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php:184 I am looking for information preferably how to resolve this db connection issue for spark, but at a minimum, understanding on how spark works for db connections and why it appears to be different than the CI4 methods. TIA...
Try home controller as CLI? Connecting ok?
https://codeigniter4.github.io/userguide...un-via-cli $ cd /path/to/project/public $ php index.php home index
Simple CI 4 project for beginners codeigniter-expenses
You need to go into the docker container to use PHP in the container.
If you want to use PHP on your host OS, you need to configure for it. (12-07-2023, 02:51 PM)kenjis Wrote: You need to go into the docker container to use PHP in the container. Host computer is configured for PHP. Otherwise, it would return that php can't be found, and spark migrate would not run at all. spark migrate is running and attempting to connect. [EDIT] You are right. This seems to work - running it from the container. My apologies for the quick and inaccurate response. An explanation of why this is the case would be helpful to me.
A docker container is kind of another PC in your Host PC.
That is, you have two (or more) PCs. You just configured the docker containers by devilbox. So PHP in the container can access MySQL in the container. But you did not configure PHP (I don't know you installed PHP) on your host PC. If you want to access MySQL in the container from your host PC, you need to configure the network, and PHP and its database configuration. (12-07-2023, 05:05 PM)kenjis Wrote: A docker container is kind of another PC in your Host PC. Yup - I got that much thx. I have PHP installed on the host computer - I don't know why spark migrate didn't connect to the db, but it did run on the host, it just failed to complete. The host computer has access to the db, that's how I manage the db. At this point, it is working, but I still don't understand why it didn't work from the host. |
Welcome Guest, Not a member yet? Register Sign In |