Laravel Dusk testing with Gitlab CI error, cant connect to port:9515: Connection refused - laravel

so i've been trying to setup Laravel with Gitlab, everything works fine now, however when the script tries to run my Browser tests, i get the following error
Curl error thrown for http POST to /session with params: {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--window-size=1920,1080"]}}]},"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--disable-gpu","--headless","--window-size=1920,1080"]}}}
Failed to connect to localhost port 9515: Connection refused
at vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:331
here is my .gitlab-ci.yml file
before_script:
- apt-get update
- apt-get install -qq git curl libmcrypt-dev libjpeg-dev libpng-dev libfreetype6-dev libbz2-dev
- apt-get install zlib1g-dev libzip-dev
- apt-get clean
- curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- docker-php-ext-install pdo_mysql zip
- cp .env.test .env
image: php:7.3
services:
- mysql:5.7
variables:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
DB_HOST: mysql
DB_USERNAME: root
stages:
- test
browser_test:
stage: test
script:
- echo "Starting pest tests"
- composer install
- php artisan dusk:install
- php artisan dusk:chrome-driver
- php artisan key:generate
- php artisan migrate
- php artisan serve & vendor/bin/pest
and this is my .env.test file
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=mysql
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
from what i could find is that the chrome-driver is'nt running,
Thanks for your answer.

the problem is solved by adding --no-sandbox to the chrome-driver setup
in tests/DuskTestCase.php add this
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
'--no-sandbox', <---------------------
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}

Related

unable to find user sail: no matching entries in passwd file

Please I'm working with Laravel on Docker, trying to run the sail command
./vendor/bin/sail composer install
in order to manage the laravel packages and install Tailwind CSS but it keeps sowing this message:
unable to find user sail: no matching entries in passwd file
I wonder what I'm missing! here is my docker-compose.yml file
version: '2.0'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: abdelazizmirasoft/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www/html/
volumes:
- ./:/var/www/html/
- ./php/laravel.ini:/usr/local/etc/php/conf.d/laravel.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver-upwork
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www/html/
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.32
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_USER: ${DB_USER}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
my .env file:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:5ndGfShEF7w6wfnnzMlGrG7A9IFOJrlh9G7VVw0BTgM=
APP_DEBUG=true
APP_URL=http://localhost
APP_SERVICE=app
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=upwork_clone
DB_USER=upwork_user
DB_PASSWORD=p#$sw0rd
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello#example.com"
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
and the Dockerfile
FROM php:8.0.5-fpm
# Copy composer.lock and composer.json into the working directory
COPY composer.lock composer.json /var/www/html/
# Set working directory
WORKDIR /var/www/html/
# Install dependencies for the operating system software
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
libzip-dev \
unzip \
git \
libonig-dev \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions for php
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
# Install composer (php package manager)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy existing application directory contents to the working directory
COPY . /var/www/html
# Assign permissions of the working directory to the www-data user
RUN chown -R www-data:www-data \
/var/www/html/storage \
/var/www/html/bootstrap/cache
# Expose port 9000 and start php-fpm server (for FastCGI Process Manager)
EXPOSE 9000
CMD ["php-fpm"]
Anyone can help with that?
Thanks
Laravel provides Sail, a built-in solution for running your Laravel project using Docker.
Laravel Sail is a Docker development environment included by default in Laravel since version 8. It allows you to quickly get a PHP development environment up and running, tailored for running Laravel applications with built-in support for NPM / Node.
So in order to build your containers properly I recommend to read about this article: How To Build a Responsive About Me Page with Laravel, Sail, and Tailwind CSS

Laravel running inside docker successfully but unable to see anything in the browser?

Have been following this tutorial making a few changes when needed: https://medium.com/#pierangelo1982/dockerize-an-existing-laravel-application-with-docker-compose-a45eb7956cbd
After running docker-composer build and docker-composer up all the migrations run successfully and I get a message saying the app is running on http://0.0.0.0:8000 Hover that url or the one specified in the tutorial show nothing.
Here is my docker file
FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql
WORKDIR /app
COPY . /app
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181
my docker-compose.yaml file
version: '2'
services:
app:
build: .
ports:
- '8009:8000'
volumes:
- .:/app
env_file: .env
working_dir: /app
command: bash -c 'composer install && php artisan migrate && php artisan serve --host 0.0.0.0'
depends_on:
- db
links:
- db
db:
image: 'mysql:5.7'
environment:
- MYSQL_ROOT_PASSWORD=1
- MYSQL_DATABASE=posts
- MYSQL_PASSWORD=1
volumes:
- ./data/:/var/lib/mysql
ports:
- '3306:3306'
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8090:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: 1
and my .env file
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:oD3DGqKdE7ne91FGu7YJzAJo721v56uVjAZGRGT6VNk=
APP_DEBUG=true
APP_URL=http://posts.test
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=posts
DB_USERNAME=root
DB_PASSWORD=1
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
Not really sure what is happening at this point since it seems everything is running fine but then I see nothing on the specified port.
Helloy, I think you should check your port forwarding config. Inside container you start web server with command
CMD php artisan serve --host=0.0.0.0 --port=8181
And then I don't see where in you docker-compose.yaml you forwarded this inner port 8181 to external machine host port 8000

MySQL Access denied for Laravel on Docker

I want to dockerize my laravel project and have done the configurations but whenever i run php artisan migrate command, i get this error
SQLSTATE[HY000] [1045] Access denied for user 'admin'#'172.16.238.10' (using password: YES) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
Clearly it says access is denied for the admin user but I can't really traced where the error is.
Below are the configuration file:
app.dockerfile:
FROM php:7.2-apache
COPY composer.lock /var/www
COPY composer.json /var/www
WORKDIR /var/www
COPY database /var/www/database
RUN apt-get update && apt-get install -y git gnupg && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get install -y nodejs
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
nano \
vim \
openssl \
git \
curl\
unzip
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& php composer.phar install --no-dev --no-scripts \
&& rm composer.phar
COPY . /var/www
RUN chown -R www-data:www-data \
/var/www/storage \
/var/www/bootstrap/cache \
/var/www/public
RUN apt-get install -y libmcrypt-dev \
libmagickwand-dev --no-install-recommends \
&& pecl install mcrypt-1.0.2 \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-enable mcrypt
COPY laravel.conf /etc/apache2/sites-available
RUN ln -s /etc/apache2/sites-available/laravel.conf /etc/apache2/sites-enabled/
RUN a2dissite 000-default.conf
RUN a2ensite laravel.conf
RUN a2enmod rewrite
RUN service apache2 restart
CMD php artisan serve --port=8000
EXPOSE 8000
docker-compose.yml:
version: '3'
services:
# The Database
database:
container_name: mysql_database
image: mysql:5.7
restart: always
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=laravel"
- "MYSQL_USER=laravel"
- "MYSQL_PASSWORD=admin"
- "MYSQL_ROOT_PASSWORD=admin"
ports:
- 3306:3306
networks:
myapp_net:
ipv4_address: 172.16.238.11
# The Application
app:
container_name: laraveldocker
build:
context: ./
dockerfile: app.dockerfile
restart: always
volumes:
- ./storage:/var/www/storage
env_file: '.env'
environment:
- "DB_HOST=database"
- "REDIS_HOST=cache"
depends_on:
- database
ports:
- "8000:8000"
networks:
myapp_net:
ipv4_address: 172.16.238.10
# redis
cache:
image: redis:3.0-alpine
volumes:
dbdata:
networks:
myapp_net:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.238.0/24
laravel.conf:
<VirtualHost *:80>
ServerName 172.16.238.10
ServerAdmin webmaster#localhost
DocumentRoot /var/www/public
<Directory /var/www/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.env:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:yS7v+khzJ1GxLVAtpyWd0gG/5SOwoZr/wsXH2h/VH2o=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=172.16.238.11
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=admin
DB_PASSWORD=admin
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
Is there anything I'm doing wrong?
There is no user named admin in database configuration.
Change "MYSQL_USER=laravel" to "MYSQL_USER=admin"

Bitbucket Pipeline Laravel with MySQL php_network_getaddresses

I use php7.2-fpm-stretch docker image and MySQL as an attached service. Following command runs successfully:
mysql -h 127.0.0.1 -u username -ppassword
However, when composer wants to run package:discover it ends up with the following error:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
The .env file has the following configuration for the database:
DB_HOST=127.0.0.1
DB_CONNECTION=127.0.0.1
DB_DATABASE=pipeline
DB_USERNAME=username
DB_PASSWORD=password
And my yml file is as below:
image: php:7.2-fpm-stretch
pipelines:
default:
- step:
caches:
- composer
script:
- apt-get update && apt-get install -qy git unzip mysql-client
#Some other non-related configuration
- composer install
- php artisan key:generate
services:
- mysql
definitions:
services:
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'pipeline'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: 'username'
MYSQL_PASSWORD: 'password'

php artisan migrate on Azure (in BitBucket pipeline)

I have setup a pipeline in BitBucket to automatically deploy my master branch of my project to an Azure Web App instance.
The app deploys the files and runs composer update as expected (although it does warn that it's running as root), but php artisan migrate --force returns:
Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access
denied for user 'forge'#'127.0.0.1' (using password: NO) (SQL: select
* from information_schema.tables where table_schema = forge and table_name = migrations)
I have already created the .env file, and when I run php artisan migrate from within a shell it runs successfully and the tables are created.
Being that 'forge' is the default user in database.php I figure .env isn't being loaded when the command is fired from the deploy script.
Is there something obvious I've missed to cause this issue, or should I somehow set it up to not run as root?
I could replace the database details in database.php but I feel that's the wrong thing to do.
edit
.env contents (with certain data replaced with ********):
APP_NAME=Laravel
APP_ENV=local
APP_KEY=********
APP_DEBUG=true
APP_URL=********
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=********
DB_DATABASE=********
DB_USERNAME=********
DB_PASSWORD=********
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
edit 2
I realise I'm yet to publish my bitbucket-pipelines.yml file:
image: php:7.2-fpm
pipelines:
branches:
master:
- step:
script:
- apt-get update && apt-get install -qy git curl libmcrypt-dev mysql-client && apt-get install -qy unzip git
- yes | pecl install mcrypt-1.0.1
- docker-php-ext-install pdo_mysql
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- composer update
- php artisan migrate --force
- php artisan serve --port=80 &
- sleep 5
- curl -vk http://localhost:80
deployment: staging
services:
- mysql
definitions:
services:
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: '******'
MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
MYSQL_USER: '******'
MYSQL_PASSWORD: '******'
MYSQL_PORT: '******'
I also have a .env.pipelines file:
APP_ENV=local
APP_KEY=******
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=******
DB_USERNAME=******
DB_PASSWORD=******
This error basically comes from the after changes in the .env file:
Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access
denied for user 'forge'#'127.0.0.1' (using password: NO) (SQL: select
* from information_schema.tables where table_schema = forge and table_name = migrations)
Whenever we change the DB_DATABASE, DB_USERNAME and DB_PASSWORD in .env file, we need to clear the cache.
After completion of .env edit, must be clear cache: php artisan config:cache
NOTE: If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed(In the past I've also faceout this problem, It's consider blank space as a password)
Without seeing your deploy script and how you are connecting with your Azure server you would need to put
php artisan config:clear // This will reload the .env file to cache
after you have connected to your server but before you run
php artisan migrate
Please checkout the link:
https://laravel.com/docs/5.7/configuration#configuration-caching
php artisan config:cache
The above command will just regenerate the cache for you. (if added as a part of deployment script)
Else you can use php artisan config:clear just to clear the existing config and fetch values from .env/config files (add as a part of your deployment script)

Resources