So, after hours of Googling no right answer is found. Ive started the Laravel 8.x tutorial installation for Windows using Docker and Laravel's sail.
Now i want to use Xdebug and have absolutely no idea what to do.
in the root of the project there is a docker-compose.yml (this is the default)
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
PHP_IDE_CONFIG: 'serverName=localhost'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
# - selenium
# selenium:
# image: 'selenium/standalone-chrome'
# volumes:
# - '/dev/shm:/dev/shm'
# networks:
# - sail
# depends_on:
# - laravel.test
mysql:
image: 'mysql:8.0'
ports:
- '${DB_PORT}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '${REDIS_PORT}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
# memcached:
# image: 'memcached:alpine'
# ports:
# - '11211:11211'
# networks:
# - sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- 1025:1025
- 8025:8025
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
And in the vendor/laravel/sail/runtimes/8.0 folder there is a Dockerfile
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin \
&& mkdir -p ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
&& apt-get install -y nodejs \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
now what?
I'm on a Windows system
I want to connect it to PhpStorm
I had the same problem for VS Code on a Linux workstation.
Maybe my solution could work for you, too.
Apparently, XDebug is not installed at all with Laravel Sail. In order to include it, you have to modify the Dockerfile, edit docker-compose.yml and rebuild the containers.
Here is how I did.
I copied the Docker configuration Laravel Sail uses in a more convenient place:
cp -r vendor/laravel/sail/runtimes/8.0 ./resources/docker/
I changed the context and added a variable under args in the first lines of docker-compose.yml:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./resources/docker/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
XDEBUG: ${APP_DEBUG}
...
So the context points where I copied the original Docker configuration. I also decided to bind the new XDEBUG arg to the value of the APP_DEBUG variable inside the .env file, in order to switch off XDebug in a production environment.
Then, I changed the Dockerfile I copied before in order to include xdebug when building the containers. The script should also write the correct configuration options for Xdebug 3 inside php.ini:
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG XDEBUG
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin \
&& mkdir -p ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis
RUN if [ ${XDEBUG} ] ; then \
apt-get install -y php-xdebug \
&& echo "[XDebug]" > /etc/php/8.0/cli/php.ini \
&& echo "zend_extension="$(find /usr/lib/php/20200930/ -name xdebug.so)" > /etc/php/8.0/cli/php.ini" \
&& echo "xdebug.mode = debug" >> /etc/php/8.0/cli/php.ini \
&& echo "xdebug.start_with_request = yes" >> /etc/php/8.0/cli/php.ini \
&& echo "xdebug.discover_client_host = true" >> /etc/php/8.0/cli/php.ini ;\
fi;
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
&& apt-get install -y nodejs \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
After stopping, rebuilding and relaunching the containers:
$ ./vendor/bin/sail stop
$ ./vendor/bin/sail up --build -d
You can find out if XDebug is running:
$ ./vendor/bin/sail php -v
PHP 8.0.0 (cli) (built: Nov 27 2020 12:26:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans
For VSCode only:
Inside Preferences -> Settings under Debug you should check "Debug: Allow breakpoints everywhere".
Change the default launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html" : "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
There is a discarded PR for optional Xdebug 3.0 support in laravel/sail (PHP 7.4 and PHP 8). Please follow the discussion.
Check the commit, what to change in Dockerfile and docker-compose.yml. Don't forget to set the variables in your .env
I got XDebug to work with a web request after some help from the posters above.
I have quite a bit of experience with PHPStorm and XDebug 2.x. I am new to docker so there may be better ways to fix this. I have not yet figured out how to run or debug tests that rely on the database connection from inside PHPStorm (right click on a test to debug). They run successfully with breakpoints if I am "listening" to sail test (which will run the tests correctly) but PHPStorm can't find the MySQL database when running tests and I also get this error: "Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003"
Update 1/18/21 to fix local environment within PHPStorm so that it can find the database and the rest of the Docker network. Now I can successfully run tests and debug from within PHPStorm. With the current build of PHPStorm 2020.3.1 You need to add the network name where it asks for the network mode. I will be reporting this to them so it may get addressed soon.
Get your network name by running docker network ls. In this case it is myProjectName_sail.
NETWORK ID NAME DRIVER SCOPE
8e8635ce01a6 bridge bridge local
401307dbfaad host host local
ad8020ad629e myProjectName_sail bridge local
d85a9668cade none null local
Enter this in PHPStorm Preferences>PHP>CLI Interpreter>...
On to the fix for debugging web requests:
What I have:
Laravel Sail version 8.0
Xdebug version 3.0
PHPStorm version 2020.3 The version of PHPStorm is important as it supports PHP8 and Xdedbug 3.
What I did:
I installed vim in my docker container by adding this line to the Dockerfile: RUN apt-get -y install vim
This lets me view/edit files easily by running
docker exec -it mySite.test_1 vim /etc/php/8.0/cli/php.ini.
In this case I still edited the Dockerfile to generate the php.ini
You need to get your /etc/php/8.0/cli/php.ini file to look like this (client_host was the key):
[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
I added this to the Dockerfile as recommended by #Enea74. I was having trouble getting the conditional to return TRUE so I hard coded TRUE here for now:
RUN if [ true ] ; then \
apt-get install -y php-xdebug \
&& echo "[XDebug]" > /etc/php/8.0/cli/php.ini \
&& echo "zend_extension="$(find /usr/lib/php/20200930/ -name xdebug.so)" > /etc/php/8.0/cli/php.ini" \
&& echo "xdebug.mode = debug" >> /etc/php/8.0/cli/php.ini \
&& echo "xdebug.start_with_request = yes" >> /etc/php/8.0/cli/php.ini \
&& echo "xdebug.client_host = host.docker.internal" >> /etc/php/8.0/cli/php.ini ;\
fi;
I built the Docker containers by running sail build --no-cache
then sail up -d
sail php -v
returns:
PHP 8.0.0 (cli) (built: Nov 27 2020 12:26:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans
Now In PHPStorm do the following. I think that it discovered many of these settings on its own: I don't remember setting all of these values:
Hopefully this will help someone.
The underlying dockerfile can be found here.
In order to run xdebug you need to install the PHP extension.
Personally I like to use docker-php-extension-installer to install them.
Add these lines after line 35:
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions xdebug
Add these lines after line 35:
RUN sudo apt-get install php-xdebug
After that you need to configure Xdebug, PhpStorm and your browser.
configure xdebug to connect to you host machine
xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
xdebug.remote_host=host.docker.internal
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
both the remote_port and the remote_host are very important.
Make sure this port does not conflict with a service inside the container, in this case do not use 8000 as PHP already runs on this port.
configure PhpStorm
You need to create a server first under:
File > Settings > Languages & Frameworks > PHP > Servers
It is very important to correctly map the paths in this case:
.:/var/www/html
Which means your project root directory on the left should map to /var/www/html
Now it is time to create a run config. You can do this in the top right corner of PhpStorm under "Add Configuration..."
Use the screenshot as a guide.
lastly start the debug session in the browser, easiest way is to use the chrome extension Xdebug helper. Change the IDE key as configured earlier under settings and left click the extension icon > debug to start debugging.
Also do the same inside PhpStorm in the right corner.
My contribution to #Enea74 and #smenzer great answers above:
I successfully configured Sail with xdebug working on VSCODE on linux mint.
But when I run some phpUnit or sail test, it was not working as expected and received this message
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9000 (fallback through xdebug.client_host/xdebug.client_port) :-(
After a long search, I figured out that need to add this line on the Dockerfile of Sail after the apt install commands:
RUN ip -4 route list match 0/0 | awk '{print $3 " host.docker.internal"}' >> /etc/hosts
Rebuild the containers with
sail down
sail up --build --force-recreate -d
And then the xdebug start to work with phpunit tests on shell along with normal browser navigation.
Note: if the command 'ip' is not working, add the package 'iproute2' on previous apt install commands.
I'm in the same situation as OP and didn't find a solution, but this is what I found:
If you've installed xdebug via command line recently, chances are you've installed Xdebug V3 which has different config options than Xdebug V2. It doesn't have remote_autostart or remote_enable options so setting those will have no effect.
You can read more about Xdebug 3 config options here: https://xdebug.org/docs/all_settings
Related
I ran into a problem that I have to manually write a cronjob in a production environment inside Ubuntu, I would like to have a completely standalone docker project. There is a solution with creating an ubuntu container, but it looks weird, ubuntu inside ubuntu. So far, I've had to set up a cronjob outside of a container on Ubuntu itself.
Dockerfile
FROM php:8.1-fpm
RUN apt-get update && apt-get install -y \
apt-utils \
libpq-dev \
libpng-dev \
libzip-dev \
zip unzip \
git && \
docker-php-ext-install pdo_mysql && \
docker-php-ext-install bcmath && \
docker-php-ext-install gd && \
docker-php-ext-install zip && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY ./_docker/app/php.ini /usr/local/etc/php/conf.d/php.ini
# Install composer
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer \
--install-dir=/usr/local/bin
WORKDIR /var/www
docker-compose.yml
version: '3'
services:
nginx:
image: nginx:latest
volumes:
- ./:/var/www/
- ./_docker/nginx/conf.d/:/etc/nginx/conf.d/
ports:
- 8876:80
container_name: flowers_nginx
depends_on:
- flowers
flowers:
build:
context: .
dockerfile: _docker/app/Dockerfile
volumes:
- ./:/var/www/
depends_on:
- database
container_name: flowers_php
database:
image: mysql:8.0
restart: always
volumes:
- ./temp/db:/var/lib/mysql
environment:
MYSQL_DATABASE: ****
MYSQL_ROOT_PASSWORD: *****
MYSQL_USER: ****
MYSQL_PASSWORD: *****
ports:
- 8101:3306
command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
container_name: flowers_mysql
Due to lack of experience, I need a hint with the best solution, maybe use kubernetes-cronjob or redis, but I have not yet learned these technologies, I will be grateful if you help me choose the right solution and development path.
I tried to do the following inside Ubuntu itself which has docker installed and it works, but because of this I can't make a completely standalone docker project without connecting to the ubuntu job which has docker installed
crontab -e
* * * * * cd /var/www/public/flowers_shop && php artisan schedule:run >> /dev/null 2>&1
I have a container with a nginx, mailhog, redis and PHP image. All these images are on the same network.
I run Laravel on the PHP image.
I want to make use of the Job queue that laravel has, but I am struggling to run the queue in the PHP image.
I've looked at all the examples but it seems my lack of understanding of docker is causing me to not ask the right question
Below is my docker-compose.yml
version: '3'
networks:
devnet:
external: true
services:
# lightweight web-server:
nginx:
image: nginx:stable-alpine
container_name: lar-nginx
ports:
- 8080:80
- 4040:443
volumes:
- ./:/var/www
- ./run/nginx:/etc/nginx/conf.d
- ./local/certs:/etc/nginx/certs
depends_on:
- php
networks:
- devnet
# server-side scripting engine
php:
build:
context: .
dockerfile: Dockerfile
container_name: lar-php
volumes:
- ./:/var/www
ports:
- "9000:9000"
networks:
- devnet
# caching server:
redis:
image: redis:latest
container_name: lar-redis
ports:
- "6379:6379"
networks:
- devnet
# development email catch-all server & client:
mailhog:
image: mailhog/mailhog:latest
container_name: lar-mailhog
ports:
# imap port for send mail
- "1025:1025"
# www mailhog ui
- "8025:8025"
networks:
- devnet
Dockerfile
FROM php:7.4-fpm
RUN apt-get update
RUN apt-get -y install curl gnupg cron
# RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
# RUN apt-get -y install nodejs
# RUN npm install
# Install other required PHP extensions and unix utils:
RUN apt-get update && apt-get install -y libmcrypt-dev \
mariadb-client libmagickwand-dev libonig-dev \
libzip-dev libcurl4-openssl-dev redis-server \
zlib1g-dev wget git \
--no-install-recommends \
# && pecl install imagick
# && docker-php-ext-enable imagick
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install zip \
&& docker-php-ext-install xml \
&& docker-php-ext-install curl \
&& docker-php-ext-install gd \
&& docker-php-ext-install soap
# Configure PHP internal vars:
ENV PHP_MEMORY_LIMIT=256M
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install php apcu pecl package:
RUN pecl install apcu && docker-php-ext-enable apcu
# Install php redis pecl package:
RUN pecl install redis && docker-php-ext-enable redis
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql zip exif pcntl
# Permissions for Laravel
RUN chown -R www-data:www-data /var/www
RUN chmod -R 777 /var/www
COPY entrypoint.bash /usr/sbin
RUN chmod a+x /usr/sbin/entrypoint.bash
ENTRYPOINT /usr/sbin/entrypoint.bash
entrypoint.bash
#!/bin/bash
# turn on bash's job control
set -m
# Start the "main" PHP process and put it in the background
php-fpm &
# Start the helper crond process
crond
# now we bring the primary process back into the foreground
fg %1
In normal server(lamp) environment its pretty simple to work with cronjobs and queue but I dont know how to start up the queue.
php artisan queue:work in the php image returs There are no commands defined in the "queue:" namespace. Did you mean this? queue
Running it in tinker
\Queue::pushON('new', new App\Jobs\PublishingClass(array('foo'=>1,'foobar'=>783,'foobarfoo'=>33)));
show the job gets processed but I need to do it with a process running in the background
The most simple way is to call with the use of Tinker
It's Laravel command using for debugging, use it by running below command from from project root
php artisan tinker
To dispatch job on a specific queue from tinker
\Queue::pushON('rms', new App\Jobs\UpdateRMS());
first parameter - Queue name
second parameter - job name
Dispatch multiple jobs at once to a specific queue
\Queue::bulk([new App\Jobs\UpdateRMS(), new App\Jobs\UpdateRMS()], null, 'rms');
You can use this docker image, you don't need to configure the schedule, it's already implemented, with differents php expansions like redis, Rdkafka.
Follow this link:
https://hub.docker.com/r/jkaninda/laravel-php-fpm
https://github.com/jkaninda/laravel-php-fpm
I'm trying out Laravel Sail, as I've been successfully using Laradock for a few years and hoping to simplify my dev environment setup. I am on Windows 10 64, Docker Desktop 3.0 installed using WSL 2, and my Laravel app is running Laravel 8.20.1.
In my Laravel project, I've followed the Laravel Sail setup guide: I've run composer require laravel/sail --dev and php artisan sail:install, and I see the docker-compose.yml in my root directory.
But when I run ./vendor/bin/sail up I get this error:
./vendor/bin/sail: line 1: XSym: command not found
./vendor/bin/sail: line 2: 0024: command not found
./vendor/bin/sail: line 3: a81960381c7144e16cd1e768af147de3: command not found
./vendor/bin/sail: line 4: ../laravel/sail/bin/sail: No such file or directory
Update: I fixed the above through Qumber's help: removing /vendor/ and reinstalling. But now I get this error:
In GitBash I get this response:
Unsupported operating system [MINGW64_NT-10.0-19041]. Laravel Sail supports macOS, Linux, and Windows (WSL2).
If I try from Powershell now, I get:
/bin/bash: C:\Users\ssund\Source\steepdb\vendor\bin\/../laravel/sail/bin/sail: No such file or directory
-------------Requested attachments--------------------
docker-compose.yml:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
# - selenium
# selenium:
# image: 'selenium/standalone-chrome'
# volumes:
# - '/dev/shm:/dev/shm'
# networks:
# - sail
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
# memcached:
# image: 'memcached:alpine'
# ports:
# - '11211:11211'
# networks:
# - sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- 1025:1025
- 8025:8025
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
Dockerfile in \vendor\laravel\sail\runtimes\7.4:
FROM ubuntu:20.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php7.4-cli php7.4-dev \
php7.4-pgsql php7.4-sqlite3 php7.4-gd \
php7.4-curl php7.4-memcached \
php7.4-imap php7.4-mysql php7.4-mbstring \
php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap \
php7.4-intl php7.4-readline php7.4-pcov \
php7.4-msgpack php7.4-igbinary php7.4-ldap \
php7.4-redis \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_15.x | bash - \
&& apt-get install -y nodejs \
&& apt-get install -y mysql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php7.4
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/7.4/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]
Ok there were multiple things that I needed to fix here.
#Qumber helped me initially by suggesting I wipe /vendor/ and run composer install/update again. That fixed the missing sail file that wasn't getting added for some reason.
I also had some permission-related issues, possibly due to running compose in WSL and then trying to run sail in Windows/GitBash (or vice versa).
The biggest issue was my misunderstanding about Docker WSL2 integration and that the sail command should be run from within WLS (coming from Laradock, I made some incorrect assumptions). I needed to have a linux distro installed (I chose Ubuntu 20.x) AND make sure it was set as the default, via running wsl -s . You can check which is currently default with wsl -l -v. For more detailed steps about this setup see https://learn.microsoft.com/en-us/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package.
Once I fixed the above, I was able to open Windows Terminal, create an Ubuntu tab, and run ./vendor/bin/sail up and it executed.
You need to install linux under windows first. Your answer is correct. Thanks :)
If you're like me who cloned a Laravel project from GitHub where none of the application's Composer dependencies are available including Sail, you'll need to run the following commands from the project directory. The following commands use a small Docker Container containing PHP and Composer to install the application's dependencies:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
Further information can be found on the Laravel documentation.
For me, this was a permissions issue. Running as sudo worked.
Using Win10 with WSL Ubuntu 20.04 LTS.
I was facing this problem on my Mac .This issue is due to permission
Solution for MAC
1: Pull down the Apple menu and choose ‘System Preferences’
2: Choose “Security & Privacy” control panel
3: Now select the “Privacy” tab, then from the left-side menu select “Full Disk Access”
4:Click the lock icon in the lower left corner of the preference panel and authenticate with an admin level login
5: Now click the [+] plus button to add an application with full disk access
6:Navigate to the /Applications/Utilities/ folder and choose “Terminal” to grant Terminal with Full Disk Access privileges
7: Relaunch Terminal, the “Operation not permitted” error messages will be gone
After that you can install Laravel.
Solution for Windows 10
Find the sail file in the vendor folder: vendor/laravel/sail/bin/sail and change from this code:
Verify operating system is supported...
case "${UNAMEOUT}" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=mac;;
*) MACHINE="UNKNOWN"
esac
if [ "$MACHINE" == "UNKNOWN" ]; then
echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2
exit 1
fi
to this:
# Verify operating system is supported...
#case "${UNAMEOUT}" in
# Linux*) MACHINE=linux;;
# Darwin*) MACHINE=mac;;
# *) MACHINE="UNKNOWN"
#esac
#
#if [ "$MACHINE" == "UNKNOWN" ]; then
# echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2
#
# exit 1
#fi
then use GitBash to run commond
./vendor/bin/sail up
From Unsupported operating system Laravel 8 with Sail on Windows 10 (WSL2)
This may sound crazy, but I had the same issue.
I just did vendor/bin/sail up
Instead of .vendor/bin/sail up
And that worked!
I am new at docker and docker-compose and I am developing a Laravel-project on docker and docker-compose with Laradock as following a tutorial(not sure whether It is a correct way or not to refer this situation though).
I want to install the composer in this environment to be able to use the composer command.
As a matter of fact, I wanted to do seeding to put data into DB that I made by php artisan make:migrate but this error appeared.
include(/var/www/laravel_practice/vendor/composer/../../database/seeds/AdminsTableSeeder.php): failed to open stream: No such file or directory
So I googled this script to find a solution that will solve the error then I found it.
It says, "Do composer dump-autoload and try seeding again", so I followed it then this error appeared.
bash: composer: command not found
Because I have not installed composer into docker-container.
My docker's condition is like this now.
・workspace
・mysql
・apache
・php-fpm
Since I have not installed the composer, I have to install it into docker-container to solve the problem, BUT I have no idea how to install it into docker-container.
So could anyone tell me how to install composer into docker-container?
Thank you.
here is the laradock/mysql/Dockerfile and laravelProject/docker-compose.yml.
ARG MYSQL_VERSION=5.7
FROM mysql:${MYSQL_VERSION}
LABEL maintainer="Mahmoud Zalt <mahmoud#zalt.me>"
#####################################
# Set Timezone
#####################################
ARG TZ=UTC
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && chown -R mysql:root /var/lib/mysql/
COPY my.cnf /etc/mysql/conf.d/my.cnf
CMD ["mysqld"]
EXPOSE 3306
version: '2'
services:
db:
image: mysql:5.7
ports:
- "6603:3306"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
- MYSQL_DATABASE=laravelProject
- LANG=C.UTF-8
volumes:
- db:/var/lib/mysql
command: mysqld --sql-mode=NO_ENGINE_SUBSTITUTION --character-set-server=utf8 --collation-server=utf8_unicode_ci
web:
image: arbiedev/php-nginx:7.1.8
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
volumes:
db:
You can build your own image and use it in your Docker compose file.
FROM php:7.2-alpine3.8
RUN apk update
RUN apk add bash
RUN apk add curl
# INSTALL COMPOSER
RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'
# INSTALL NGINX
RUN apk add nginx
I used the PHP alpine image as my base image because it's lightweight, so you might have to install other dependencies yourself. In your docker-compose file
web:
build: path/to/your/Dockerfile/directory
image: your-image-tag
ports:
- "8080:80"
volumes:
- ./www:/var/www
- ./nginx.conf:/etc/nginx/sites-enabled/default
You could do something like this:
FROM php:8.0.2-apache
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y mariadb-client libxml2-dev
RUN apt-get autoremove -y && apt-get autoclean
RUN docker-php-ext-install mysqli pdo pdo_mysql xml
COPY --from=composer /usr/bin/composer /usr/bin/composer
the argument COPY --from= should solve your problem.
FROM php:7.3-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN alias composer='php /usr/bin/composer'
I have created a laravel project and put it in a docker container and it all seems to load fine, however at some point I get an error message saying:
There is no existing directory at "/Users/john/Documents/work/dashboard/src/storage/logs" and its not buildable: Permission denied
It is strange that Laravel is trying to write into a file or directory that is part of my local environment, instead of the docker container environment which I would expect to be something like:
/var/www/storage/logs
This is my docker-compose.yml:
version: '2'
services:
# The Web Server
web:
build:
context: ./
dockerfile: web.signup.dockerfile
working_dir: /var/www
volumes:
- ./src:/var/www
- /var/www/storage
env_file: 'src/.env'
ports:
- 80:80
volumes:
dbdata:
And this is my Dockerfile
FROM centos:latest
RUN set -ex \
&& yum install -y epel-release \
&& yum update -y mysql-client libmagickwand-dev \
&& yum install -y libmcrypt-devel \
&& yum install -y python-pip \
&& pip install --upgrade pip \
&& yum install -y zip unzip \
&& yum install -y java-1.8.0-openjdk \
&& yum clean all
RUN pip install --upgrade --ignore-installed six awscli
RUN yum install -y supervisor
RUN yum install -y php-pear php-devel
RUN pecl install imagick
# Add the Ngix
ADD nginx.repo /etc/yum.repos.d/nginx.repo
# Add the Centos PHP dependent repository
RUN rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum update -y
# Installing Nginx
RUN yum -y install nginx
# Installing PHP
RUN yum -y --enablerepo=remi,remi-php72 install php-fpm php-common php-mcrypt php-mbstring
WORKDIR /var/www
ADD vhost.prod.conf /etc/nginx/conf.d/default.conf
COPY src/. /var/www
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& php composer.phar install --no-dev --no-scripts \
&& rm composer.phar
RUN chown -R apache:apache \
/var/www/storage \
/var/www/bootstrap/cache
EXPOSE 80
EXPOSE 9000
RUN mkdir -p /run/php-fpm
COPY supervisord.conf /supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"]
Any ideas at all?
Works as designed,
you are mounting "src" from your current directory into the container.
volumes:
- ./src:/var/www
If you want to access your code inside the container you could add the files while building.
To fix your "bug",
chmod -R 777 /Users/john/Documents/work/dashboard/src/storage/logs
Would be ok a for local development environment
From my end, results are when no matter what folder permission we changed in the physical folder.
Delete everything in bootstrap/cache/* solved the issue.
In my case, I got this error when I ran out of HDD space and I cleared it
Only this helped:
rm bootstrap/cache/config.php
php artisan cache:clear
composer dump-autoload