# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
build:
docker:
- image: circleci/php:7.2-node-browsers
- image: circleci/mysql:5.7-ram
steps:
- checkout
- run: sudo apt update # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev
- run: sudo docker-php-ext-install zip bcmath
- run: sudo apt-get install mysql-client
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "composer.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
# Retrieve Laravel Nova using credentials stored in CircleCI
- run: composer config http-basic.nova.laravel.com ${NOVA_USERNAME} ${NOVA_PASSWORD}
- run: composer install -n --prefer-dist
- save_cache:
key: v1-dependencies-{{ checksum "composer.lock" }}
paths:
- ./vendor
- restore_cache:
keys:
- node-v1-{{ checksum "package-lock.json" }}
- node-v1-
- run: npm install
- save_cache:
key: node-v1-{{ checksum "package-lock.json" }}
paths:
- node_modules
# prepare the database
- run: mysqladmin create test --user="root" --password="root"
- run: php artisan migrate --env=testing --force
# run tests
- run: ./vendor/bin/phpunit
When it reaches - run: mysqladmin create test --user="root" --password="root" I get the following error:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
I’ve tried rerunning the job with SSH to see if I can do it there, but nothing seems to work. I’m baffled as to what I could be doing wrong, and am even referencing other CircleCI configs that have worked.
I’ve been at this for hours and would greatly appreciate it if someone could point me in the right direction.
You’re trying to connect to a socket, but MySQL is running on the local host interface. Update your connection string to connect to 127.0.0.1 instead of localhost and that should work.
Thanks, @levlaz! That got me one step further. Now the php artisan migrate is throwing the following:
php artisan migrate --env=testing --force
In Connection.php line 664:
could not find driver (SQL: select * from information_schema.tables where t
able_schema = test and table_name = migrations)
In PDOConnection.php line 31:
could not find driver
In PDOConnection.php line 27:
could not find driver
Error: Exited with code 1
Where are you defining the php-mysql library? Is it in your composer file, or do you expect it to be in the environment? You might need to install it as a part of this step. run: sudo apt-get install mysql-client
Note that mysqladmin does not use the same driver as PHP would.
I looked into this a bit more and it looks like the php-mysql package is missing in the base image upstream.
# prevent Debian's PHP packages from being installed
# https://github.com/docker-library/php/pull/542
RUN set -eux; \
{ \
echo 'Package: php*'; \
echo 'Pin: release *'; \
echo 'Pin-Priority: -1'; \
} > /etc/apt/preferences.d/no-debian-php
This is the package that I am used to installing to connect PHP and MySQL together.
It looks like instead, its adding a module called mysqlnd.
--enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
--enable-mysqlnd \