Welcome Guest, Not a member yet? Register   Sign In
DatabaseException on CLI Migration: "No such file or directory"
#1

Hello, 
I've encountered an issue while working with CodeIgniter 4 and MAMP PRO on macOS, specifically when running migration commands via CodeIgniter's Spark CLI tool. I'm hoping to get some insights into whether this might be a known issue, a configuration problem, or a bug.

Issue Description: 
When attempting to run database migrations using the PHP spark migrate command, I receive the following error:

CodeIgniter v4.4.5 Command Line Tool - Server Time: 2024-02-08 21:20:38 UTC+00:00

Running all new migrations...
[CodeIgniter\Database\Exceptions\DatabaseException]
Unable to connect to the database.
Main connection [MySQLi]: No such file or directory
at SYSTEMPATH/Database/BaseConnection.php:428

However, database connections work as expected when accessed through the web server (e.g., via browser), and a plain PHP script using mysqli can successfully connect to the database. 

Expected Output The migration command should successfully connect to the database and run any new migrations. 

Confirmed MySQL is running in MAMP PRO and accessible via PHP scripts run through the web server. 
Checked php.ini configurations for CLI and web environments to ensure MySQLi extension is enabled and tried specifying the MySQL socket path. 
Reached out to MAMP PRO support to clarify if this could be a configuration issue related to how MAMP PRO handles PHP CLI environments.
Reply
#2

(This post was last modified: 02-09-2024, 04:53 PM by kenjis.)

See
https://github.com/codeigniter4/CodeIgni...1935653119
https://github.com/codeigniter4/CodeIgni...1935872360
Reply
#3

You can check the php command that you are using with the `which` command.

Code:
$ which php
/usr/local/opt/[email protected]/bin/php

and the $PATH determines which php. The first one will be used.

Code:
$ echo $PATH

So if you want to use the MAMP's php, you need to set the $PATH.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB