PHP artisan command fails when executing in pipelines

Dulce Hernandez Cruz June 25, 2020

Hello

I'm working on a Laravel project and when the pipelines are executed, it fails when executing the migration: php artisan migrate.

php artisan migrateIn Connection.php line 671: SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from inform ation_schema.tables where table_schema = bitbucket and table_name = migrati ons and table_type = 'BASE TABLE') In Connector.php line 70: SQLSTATE[HY000] [2002] No such file or directory

Here is part of my script:

image: lbausch/laravel-ci
definitions: steps:
-
step: &build-image
name: Build image
script:
#Copy Environment File
-
cp .env.pipelines .env
#Install Composer
-
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
-
composer install
# Migrate database
-
php artisan key:generate
-
php artisan migrate
-
chmod -R 0755 bootstrap/cache
services:
#Add MySql Database
-
mysql
services:
mysql:
image: mysql:5.7
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_DATABASE: 'bitbucket'
MYSQL_PASSWORD: 'bitbucket'
MYSQL_USER: 'bitbucket'

 

I confirmed that in this docker image the drivers are enabled:

PDOPDO support => enabledPDO drivers => mysql, sqlitepdo_mysqlPDO Driver for MySQL => enabledClient API version => mysqlnd 7.4.4

Does anyone know to solve this error? 

1 answer

0 votes
ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 25, 2020

The Mysql error message

SQLSTATE[HY000] [2002] No such file or directory

shows that artisan via php pdo connects to the mysql server via a socket file. this is not available in the pipeline and it therefore fails.

instead the mysql service is reachable via the ip address 127.0.0.1. change the artisan/laravel configuration from "localhost" to "127.0.0.1" and then it should work.

it is a special thing that mysql connects via a socket if "localhost" is used.

maybe setting the DB_HOST environment variable to 127.0.0.1 does it already.

Dulce Hernandez Cruz June 25, 2020

@ktomk yes, I already have this configuration in my .env file but it's not working

APP_ENV=testing
DB_CONNECTION=mysql
DB_HOST=127.0.0.1

LOG_CHANNEL=stack
DB_DATABASE=bitbucket
DB_USERNAME=bitbucket
DB_PASSWORD=bitbucket

  

ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2020

hmm, from the error message I was quite sure this would be it.

is the service properly starting (I would first of all assume that, but perhaps double check the mysql service output in the logs).

mysql takes some seconds to start, if it's not yet available, then there would be also connection problems (however I normally see these not with "file not found" but something along the lines like connection refused or could not connect, however not using PDO.)

maybe the .env is not effective? or it is effective but some other variables from the environment render it useless? (e.g. DB_HOST is set to "localhost" in a (pipeline) environment variable which then overrides the value in .env).

is more information available with verbose output of the artisan command? (I don't have it at hand, often this is a -v / -vvv / --verbose switch - just reading that with artisan verbosity might only affect error cases)

Dulce Hernandez Cruz July 2, 2020

@ktomk The connection is working, I tested by connecting to the database and making a query:

+ mysql -h 127.0.0.1 -u bitbucket -pbitbucket -e 'show databases;
'
Database
information_schema
bitbucket

But when executing the artisan command doesn't work. Also I tested by explicitly putting the environment variables:

export DB_DATABASE=bitbucket DB_USERNAME=bitbucket DB_PASSWORD=bitbucket

Something that it's weird is that in the mysql logs is that it doesn't display a hostname but an asterik:

hostname (bind-address): '*'; port: 3306

2020-06-28T23:37:05.443951Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2020-06-28T23:37:05.444019Z 0 [Note] IPv6 is available.2020-06-28T23:37:05.444615Z 0 [Note] - '::' resolves to '::';2020-06-28T23:37:05.444661Z 0 [Note] Server socket created on IP: '::'.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events