diff --git a/.gitignore b/.gitignore index 28b085f..00571d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea /logs /data -.env \ No newline at end of file +.env diff --git a/README.md b/README.md index 91710d6..b466c9f 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ It's like Laravel Homestead but for Docker instead of Vagrant. - [Change the PHP-FPM Version](#Change-the-PHP-FPM-Version) - [Change the PHP-CLI Version](#Change-the-PHP-CLI-Version) - [Install xDebug](#Install-xDebug) + - [Start/Stop xDebug](#Controll-xDebug) + - [Production](#Production) + - [Setup Laravel and Docker on Digital Ocean](#Digital-Ocean) - [Misc](#Misc) - [Use custom Domain](#Use-custom-Domain) - [Enable Global Composer Build Install](#Enable-Global-Composer-Build-Install) @@ -290,7 +293,7 @@ If you need a special support. Contact me, more details in the [Help & Questions -### [Docker] + @@ -472,7 +475,6 @@ docker logs {container-name}
-### [Laravel] @@ -701,7 +703,6 @@ More details about this [here](https://github.com/jenssegers/laravel-mongodb#ins
-### [PHP] @@ -833,10 +834,51 @@ It should be like this: 2 - Re-build the containers `docker-compose build workspace php-fpm` +For information on how to configure xDebug with your IDE and work it out, check this [Repository](https://github.com/LarryEitel/laravel-laradock-phpstorm). + + +
+ +### Start/Stop xDebug: + +By installing xDebug, you are enabling it to run on startup by default. + +To controll the behavior of xDebug (in the `php-fpm` Container), you can run the following commands from the LaraDock root folder: + +- Stop xDebug from running by default: `./xdebugPhpFpm stop`. +- Start xDebug by default: `./xdebugPhpFpm start`. +- See the status: `./xdebugPhpFpm status`. + + + + + +
+ + + + + +
+ +### Setup Laravel and Docker on Digital Ocean + +####[Full Giude Here](https://github.com/LaraDock/laradock/blob/master/_guides/digital_ocean.md) + + + + + + + + +
-### [Misc] + + +
@@ -960,6 +1002,8 @@ Make sure the ports for the services that you are trying to run (80, 3306, etc.) + +
### Upgrading LaraDock @@ -987,7 +1031,7 @@ Moving from Docker Toolbox (VirtualBox) to Docker Native (for Mac/Windows). Requ This little project was built by one man who has a full time job and many responsibilities, so if you like this project and you find that it needs a bug fix or support for new software or upgrade any container, or anything else.. Do not hesitate to contribute, you are more than welcome :) -#### Read our [Contribution Guidelines](https://github.com/LaraDock/laradock/blob/master/CONTRIBUTING.md) +#### Read our [Contribution Guidelines](https://github.com/LaraDock/laradock/blob/master/_guides/contributing.md) ## Help & Questions @@ -1006,6 +1050,8 @@ For special help with Docker and/or Laravel, you can schedule a live call with t **Main Contributors:** +- [MidasCodeBreaker](https://github.com/midascodebreaker) +- [Larry Eitel (LarryEitel)](https://github.com/LarryEitel) - [Suteepat (tianissimo)](https://github.com/tianissimo) - [David (davidavz)](https://github.com/davidavz) - [Lialosiu](https://github.com/lialosiu) diff --git a/CONTRIBUTING.md b/_guides/contributing.md similarity index 82% rename from CONTRIBUTING.md rename to _guides/contributing.md index 9e1cedb..b6cb9d4 100644 --- a/CONTRIBUTING.md +++ b/_guides/contributing.md @@ -1,5 +1,3 @@ - - # Contributing to LaraDock Your contribution is more than welcome. Let's keep LaraDock amazing. @@ -54,9 +52,21 @@ Help us to maximize the effort we can spend fixing issues and adding new features, by not reporting duplicate issues. +### Before Submitting a Pull Request (PR) -### Submitting a Pull Request (PR) -Before you submit your pull request consider the following guidelines: +Always Test everything and make sure its working: + +- Pull the latest updates (or fork of you don’t have permission) +- Before editing anything: + - Test building the container (docker-compose build --no-cache container-name) build with no cache first. + - Test running the container with some other containers in real app and see of everything is working fine. +- Now edit the container (edit section by section and test rebuilding the container after every edited section) + - Testing building the container (docker-compose build container-name) with no errors. + - Test it in real App. + + +### Submitting a PR +Consider the following guidelines: * Search [GitHub](https://github.com/LaraDock/laradock/pulls) for an open or closed Pull Request that relates to your submission. You don't want to duplicate effort. @@ -93,7 +103,7 @@ git push origin my-fix-branch -f -### After your pull request is merged +### After your PR is merged After your pull request is merged, you can safely delete your branch and pull the changes from the main (upstream) repository: @@ -127,4 +137,4 @@ from the main (upstream) repository:
-### Happy Coding :) \ No newline at end of file +### Happy Coding :) diff --git a/_guides/digital_ocean.md b/_guides/digital_ocean.md new file mode 100644 index 0000000..3f47e52 --- /dev/null +++ b/_guides/digital_ocean.md @@ -0,0 +1,214 @@ +#### Install Docker +``` +Login Digital Ocean +Add Droplet +1 Click Install docker +Choose Droplet +reset ROOT password +check email +``` + +#### SSH to your Server + +``` +ssh root@ipaddress +``` +you will be prompt of that password. +type the password you receive in your email + +then it will ask to you to change a new password +just change it to the custom root password you want + +After SSH +you can check that docker command is working by typing + +``` +$root@midascode:~# docker +``` + +#### Set Up Your Laravel Project + +``` +$root@midascode:~# apt-get install git +$root@midascode:~# git clone https://github.com/laravel/laravel +$root@midascode:~# cd laravel +$root@midascode:~/laravel# git checkout develop +$root@midascode:~/laravel/ git submodule add https://github.com/LaraDock/laradock.git +$root@midascode:~/laravel/ cd laradock +``` + +#### Install docker-compose command + +``` +$root@midascode:~/laravel/laradock# curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose +$root@midascode:~/chmod +x /usr/local/bin/docker-compose +``` + +#### Create Your LaraDock Containers + +``` +$root@midascode:~/laravel/laradock# docker-compose up -d nginx mysql +``` + +#### Go to Your Workspace + +``` +docker-compose exec workspace bash +``` + +#### Install laravel Dependencies, Add .env , generate Key and give proper permission certain folder + +``` +$ root@0e77851d27d3:/var/www/laravel# composer install +$ root@0e77851d27d3:/var/www/laravel# cp .env.example .env +$ root@0e77851d27d3:/var/www/laravel# php artisan key:generate +$ root@0e77851d27d3:/var/www/laravel# exit +$root@midascode:~/laravel/laradock# cd .. +$root@midascode:~/laravel# sudo chmod -R 777 storage bootstrap/cache +``` + +you can then view your laravel site at your ipaddress +for example +``` +192.168.1.1 +``` + +You will see there Laravel Default Welcome Page + +but if you need to view on your custom domain name +which you would. + +#### Using Your Own Domain Name +login to your DNS provider +Godaddy, Namecheap what ever... +And Point the Custom Domain Name Server to + +``` +ns1.digitalocean.com +ns2.digitalocean.com +ns3.digitalocean.com +``` +In Your Digital Ocean Account go to +``` +https://cloud.digitalocean.com/networking/domains +``` +add your domain name and choose the server ip you provision earlier + +#### Serve Site With NGINX (HTTP ONLY) +Go back to command line +``` +$root@midascode:~/laravel/laradock# cd nginx +$root@midascode:~/laravel/laradock/nginx# vim laravel.conf +``` +remove default_server +``` + + listen 80 default_server; + listen [::]:80 default_server ipv6only=on; + +``` + and add server_name (your custom domain) +``` + listen 80; + listen [::]:80 ipv6only=on; + server_name yourdomain.com; +``` + +#### Rebuild Your Nginx +``` +$root@midascode:~/laravel/laradock/nginx# docker-compose down +$root@midascode:~/laravel/laradock/nginx# docker-compose build nginx +``` + +#### Re Run Your Containers MYSQL and NGINX +``` +$root@midascode:~/laravel/laradock/nginx# docker-compose up -d nginx mysql +``` + +###### View Your Site with HTTP ONLY (http://yourdomain.com) + +#### Run Site on SSL with Let's Encrypt Certificate + +###### Note: You need to Use Caddy here Instead of Nginx + +###### To go Caddy Folders and Edit CaddyFile + +``` +$root@midascode:~/laravel/laradock# cd caddy +$root@midascode:~/laravel/laradock/caddy# vim Caddyfile +``` + +Remove 0.0.0.0:80 + +``` +0.0.0.0:80 +root /var/www/laravel/public +``` +and replace with your https://yourdomain.com + +``` +https://yourdomain.com +root /var/www/laravel/public +``` +uncomment tls + +``` +#tls self-signed +``` +and replace self-signed with your email address + +``` +tls midascodebreaker@gmai.com +``` +This is needed Prior to Creating Let's Encypt + +#### Run Your Caddy Container without the -d flag and Generate SSL with Let's Encrypt + +``` +$root@midascode:~/laravel/laradock/caddy# docker-compose up caddy +``` + +you will be prompt here to enter your email... you may enter it or not +``` +Attaching to laradock_mysql_1, laradock_caddy_1 +caddy_1 | Activating privacy features... +caddy_1 | Your sites will be served over HTTPS automatically using Let's Encrypt. +caddy_1 | By continuing, you agree to the Let's Encrypt Subscriber Agreement at: +caddy_1 | https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf +caddy_1 | Activating privacy features... done. +caddy_1 | https://yourdomain.com +caddy_1 | http://yourdomain.com +``` + +After it finish Press Ctrl + C to exit ... + +#### Stop All Containers and ReRun Caddy and Other Containers on Background + +``` +$root@midascode:~/laravel/laradock/caddy# docker-compose down +$root@midascode:~/laravel/laradock/caddy# docker-compose up -d mysql caddy +``` +View your Site in the Browser Securely Using HTTPS (https://yourdomain.com) + +##### Note that Certificate will be Automatically Renew By Caddy + +>References: +> +- [https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04) +- [https://www.digitalocean.com/products/one-click-apps/docker/](https://www.digitalocean.com/products/one-click-apps/docker/) +- [https://docs.docker.com/engine/installation/linux/ubuntulinux/](https://docs.docker.com/engine/installation/linux/ubuntulinux/) +- [https://docs.docker.com/compose/install/](https://docs.docker.com/compose/install/) +- [https://caddyserver.com/docs/automatic-https](https://caddyserver.com/docs/automatic-https) +- [https://caddyserver.com/docs/tls](https://caddyserver.com/docs/tls) +- [https://caddyserver.com/docs/caddyfile](https://caddyserver.com/docs/caddyfile) + + + + + + + + + + + diff --git a/docker-compose.yml b/docker-compose.yml index a231318..1c89a00 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,14 +8,18 @@ services: build: context: ./workspace args: - - INSTALL_MONGO=false - INSTALL_XDEBUG=false + - INSTALL_MONGO=false - INSTALL_NODE=false + - INSTALL_DRUSH=false - COMPOSER_GLOBAL_INSTALL=false - PUID=1000 - PGID=1000 volumes_from: - volumes_source + extra_hosts: + # IMPORTANT: Replace with your Docker Host IP (will be appended to /etc/hosts) + - "dockerhost:10.0.75.1" tty: true ### PHP-FPM Container ####################################### @@ -24,9 +28,11 @@ services: build: context: ./php-fpm args: - - INSTALL_MONGO=false - INSTALL_XDEBUG=false + - INSTALL_MONGO=false - INSTALL_ZIP_ARCHIVE=false + - INSTALL_MEMCACHED=false + - INSTALL_OPCACHE=false dockerfile: Dockerfile-70 volumes_from: - volumes_source @@ -34,6 +40,12 @@ services: - "9000" links: - workspace + extra_hosts: + # IMPORTANT: Replace with your Docker Host IP (will be appended to /etc/hosts) + - "dockerhost:10.0.75.1" + environment: + # IMPORTANT: Set the Remote Interpreter entry matching name to `laravel` + - PHP_IDE_CONFIG="serverName=laravel" ### Nginx Server Container ################################## @@ -202,6 +214,9 @@ services: build: ./volumes/application volumes: - ../:/var/www/laravel + # Demonstration of how to mount multiple sites + # - ../../site_a/:/var/www/site_a + # - ../../site_b/:/var/www/site_b ### Databases Data Container ################################ diff --git a/nginx/Dockerfile b/nginx/Dockerfile index f9bfc1b..2aece34 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -3,7 +3,7 @@ FROM nginx:alpine MAINTAINER Mahmoud Zalt ADD nginx.conf /etc/nginx/ -ADD laravel.conf /etc/nginx/conf.d/laravel.conf +COPY sites/*.conf /etc/nginx/sites-available/ ARG PHP_UPSTREAM=php-fpm diff --git a/nginx/nginx.conf b/nginx/nginx.conf index cc7fa68..3daeb99 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -24,5 +24,6 @@ http { gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-available/*; open_file_cache max=100; } diff --git a/nginx/sites/framework-examples/drupal_8.conf b/nginx/sites/framework-examples/drupal_8.conf new file mode 100644 index 0000000..fea0690 --- /dev/null +++ b/nginx/sites/framework-examples/drupal_8.conf @@ -0,0 +1,57 @@ +server { + listen 80; + listen [::]:80; + + #domain name + server_name drupal8.dev; + + #file document root. This has to match one of the volumes in docer-composer.yml + root /var/www/drupal8; + + # This is the full path to your index file + index index.php index.html index.htm; + + ## serve imagecache files directly or redirect to drupal if they do not exist. + location ~* files/styles { + access_log off; + expires 30d; + try_files $uri @drupal; + } + + ## serve imagecache files directly or redirect to drupal if they do not exist. + location ~* ^.+.(xsl|xml)$ { + access_log off; + expires 1d; + try_files $uri @drupal; + } + + ## Images and static content is treated different + location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { + access_log off; + expires 30d; + } + + location / { + index index.php; + # This is cool because no php is touched for static content + try_files $uri $uri/ @rewrite; + expires max; + } + + location @drupal { + rewrite ^/(.*)$ /index.php?q=$1 last; + } + + location @rewrite { + # Some modules enforce no slash (/) at the end of the URL + # Else this rewrite block wouldn't be needed (GlobalRedirect) + rewrite ^/(.*)$ /index.php?q=$1; + } + + location ~ .php$ { + fastcgi_pass php-upstream; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} diff --git a/nginx/laravel.conf b/nginx/sites/laravel.conf similarity index 95% rename from nginx/laravel.conf rename to nginx/sites/laravel.conf index 432c2a7..a40a7f1 100644 --- a/nginx/laravel.conf +++ b/nginx/sites/laravel.conf @@ -1,7 +1,9 @@ server { + listen 80 default_server; listen [::]:80 default_server ipv6only=on; + server_name laravel; root /var/www/laravel/public; index index.php index.html index.htm; diff --git a/nginx/sites/site_a.conf b/nginx/sites/site_a.conf new file mode 100644 index 0000000..6bd3269 --- /dev/null +++ b/nginx/sites/site_a.conf @@ -0,0 +1,28 @@ +server { + + listen 80; + listen [::]:80; + + server_name site_a; + root /var/www/site_a/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri /index.php =404; + fastcgi_pass php-upstream; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } +} + + + diff --git a/nginx/sites/site_b.conf b/nginx/sites/site_b.conf new file mode 100644 index 0000000..e1539cd --- /dev/null +++ b/nginx/sites/site_b.conf @@ -0,0 +1,28 @@ +server { + + listen 80; + listen [::]:80; + + server_name site_b; + root /var/www/site_b/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri /index.php =404; + fastcgi_pass php-upstream; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + location ~ /\.ht { + deny all; + } +} + + + diff --git a/php-fpm/Dockerfile-56 b/php-fpm/Dockerfile-56 index fd88170..60a67a2 100644 --- a/php-fpm/Dockerfile-56 +++ b/php-fpm/Dockerfile-56 @@ -10,7 +10,7 @@ # https://hub.docker.com/r/laradock/php-fpm/tags/ # -FROM laradock/php-fpm:5.6--1.1 +FROM laradock/php-fpm:5.6--1.2 MAINTAINER Mahmoud Zalt @@ -32,10 +32,8 @@ MAINTAINER Mahmoud Zalt # # Optional Software's will only be installed if you set them to `true` # in the `docker-compose.yml` before the build. -# -# - INSTALL_XDEBUG= false -# - INSTALL_MONGO= false -# - INSTALL_ZIP_ARCHIVE= false +# Example: +# - INSTALL_ZIP_ARCHIVE=true # ##################################### @@ -45,11 +43,14 @@ MAINTAINER Mahmoud Zalt ARG INSTALL_XDEBUG=true ENV INSTALL_XDEBUG ${INSTALL_XDEBUG} RUN if [ ${INSTALL_XDEBUG} = true ]; then \ - # Install the xdebug extention + # Install the xdebug extension pecl install xdebug && \ docker-php-ext-enable xdebug \ ;fi +# Copy xdebug configration for remote debugging +COPY ./xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini + ##################################### # MongoDB: ##################################### @@ -57,8 +58,9 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \ ARG INSTALL_MONGO=true ENV INSTALL_MONGO ${INSTALL_MONGO} RUN if [ ${INSTALL_MONGO} = true ]; then \ - # Install the mongodb extention - pecl install mongodb \ + # Install the mongodb extension + pecl install mongodb && \ + docker-php-ext-enable mongodb \ ;fi ##################################### @@ -68,10 +70,32 @@ RUN if [ ${INSTALL_MONGO} = true ]; then \ ARG INSTALL_ZIP_ARCHIVE=true ENV INSTALL_ZIP_ARCHIVE ${INSTALL_ZIP_ARCHIVE} RUN if [ ${INSTALL_ZIP_ARCHIVE} = true ]; then \ - # Install the zip extention - pecl install zip \ + # Install the zip extension + pecl install zip && \ + docker-php-ext-enable zip \ ;fi +##################################### +# PHP Memcached: +##################################### + +ARG INSTALL_MEMCACHED=true +ENV INSTALL_MEMCACHED ${INSTALL_MEMCACHED} +RUN if [ ${INSTALL_MEMCACHED} = true ]; then \ + # Install the php memcached extension + pecl install memcached && \ + docker-php-ext-enable memcached \ +;fi + +##################################### +# Opcache: +##################################### +ARG INSTALL_OPCACHE=true +ENV INSTALL_OPCACHE ${INSTALL_OPCACHE} +RUN if [ ${INSTALL_OPCACHE} = true ]; then \ + docker-php-ext-install opcache && \ + docker-php-ext-enable opcache \ +;fi # #-------------------------------------------------------------------------- diff --git a/php-fpm/Dockerfile-70 b/php-fpm/Dockerfile-70 index ed28119..fe41277 100644 --- a/php-fpm/Dockerfile-70 +++ b/php-fpm/Dockerfile-70 @@ -10,7 +10,7 @@ # https://hub.docker.com/r/laradock/php-fpm/tags/ # -FROM laradock/php-fpm:7.0--1.1 +FROM laradock/php-fpm:7.0--1.2 MAINTAINER Mahmoud Zalt @@ -32,10 +32,8 @@ MAINTAINER Mahmoud Zalt # # Optional Software's will only be installed if you set them to `true` # in the `docker-compose.yml` before the build. -# -# - INSTALL_XDEBUG= false -# - INSTALL_MONGO= false -# - INSTALL_ZIP_ARCHIVE= false +# Example: +# - INSTALL_ZIP_ARCHIVE=true # ##################################### @@ -45,11 +43,14 @@ MAINTAINER Mahmoud Zalt ARG INSTALL_XDEBUG=true ENV INSTALL_XDEBUG ${INSTALL_XDEBUG} RUN if [ ${INSTALL_XDEBUG} = true ]; then \ - # Install the xdebug extention + # Install the xdebug extension pecl install xdebug && \ docker-php-ext-enable xdebug \ ;fi +# Copy xdebug configration for remote debugging +COPY ./xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini + ##################################### # MongoDB: ##################################### @@ -57,8 +58,9 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \ ARG INSTALL_MONGO=true ENV INSTALL_MONGO ${INSTALL_MONGO} RUN if [ ${INSTALL_MONGO} = true ]; then \ - # Install the mongodb extention - pecl install mongodb \ + # Install the mongodb extension + pecl install mongodb && \ + docker-php-ext-enable mongodb \ ;fi ##################################### @@ -68,10 +70,45 @@ RUN if [ ${INSTALL_MONGO} = true ]; then \ ARG INSTALL_ZIP_ARCHIVE=true ENV INSTALL_ZIP_ARCHIVE ${INSTALL_ZIP_ARCHIVE} RUN if [ ${INSTALL_ZIP_ARCHIVE} = true ]; then \ - # Install the zip extention - pecl install zip \ + # Install the zip extension + pecl install zip && \ + docker-php-ext-enable zip \ ;fi +##################################### +# PHP Memcached: +##################################### + +ARG INSTALL_MEMCACHED=true +ENV INSTALL_MEMCACHED ${INSTALL_MEMCACHED} +RUN if [ ${INSTALL_MEMCACHED} = true ]; then \ + # Install the php memcached extension + curl -L -o /tmp/memcached.tar.gz "https://github.com/php-memcached-dev/php-memcached/archive/php7.tar.gz" \ + && mkdir -p memcached \ + && tar -C memcached -zxvf /tmp/memcached.tar.gz --strip 1 \ + && ( \ + cd memcached \ + && phpize \ + && ./configure \ + && make -j$(nproc) \ + && make install \ + ) \ + && rm -r memcached \ + && rm /tmp/memcached.tar.gz \ + && docker-php-ext-enable memcached \ +;fi + +##################################### +# Opcache: +##################################### +ARG INSTALL_OPCACHE=true +ENV INSTALL_OPCACHE ${INSTALL_OPCACHE} +RUN if [ ${INSTALL_OPCACHE} = true ]; then \ + docker-php-ext-install opcache && \ + docker-php-ext-enable opcache \ +;fi + + # #-------------------------------------------------------------------------- diff --git a/php-fpm/laravel.ini b/php-fpm/laravel.ini index dea3703..486a2ca 100644 --- a/php-fpm/laravel.ini +++ b/php-fpm/laravel.ini @@ -1,8 +1,6 @@ date.timezone=UTC display_errors=Off log_errors=On -extension=mongodb.so -extension=zip.so ; Maximum amount of memory a script may consume (128MB) ; http://php.net/memory-limit diff --git a/php-fpm/xdebug.ini b/php-fpm/xdebug.ini new file mode 100644 index 0000000..06eef4a --- /dev/null +++ b/php-fpm/xdebug.ini @@ -0,0 +1,12 @@ +; NOTE: The actual debug.so extention is NOT SET HERE but rather (/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini) + +xdebug.remote_autostart=1 +xdebug.remote_enable=1 +xdebug.remote_connect_back=1 +xdebug.cli_color=1 +xdebug.remote_handler=dbgp +xdebug.remote_mode=req + +xdebug.remote_port=9000 +xdebug.remote_host=dockerhost +xdebug.idekey=PHPSTORM diff --git a/workspace/Dockerfile b/workspace/Dockerfile index f414f34..e869bfa 100644 --- a/workspace/Dockerfile +++ b/workspace/Dockerfile @@ -37,6 +37,7 @@ MAINTAINER Mahmoud Zalt # - INSTALL_MONGO= false # - COMPOSER_GLOBAL_INSTALL= false # - INSTALL_NODE= false +# - INSTALL_DRUSH= false # ##################################### @@ -52,6 +53,8 @@ RUN if [ ${INSTALL_XDEBUG} = true ]; then \ sed -i 's/^/;/g' /etc/php/7.0/cli/conf.d/20-xdebug.ini && \ echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/laravel/vendor/bin/phpunit'" >> ~/.bashrc \ ;fi +# ADD for REMOTE debugging +COPY ./xdebug.ini /etc/php/7.0/cli/conf.d/xdebug.ini ##################################### # MongoDB: @@ -95,6 +98,22 @@ RUN if [ ${COMPOSER_GLOBAL_INSTALL} = true ]; then \ composer global install \ ;fi +##################################### +# Drush: +##################################### +USER root +ENV DRUSH_VERSION 8.1.2 +ARG INSTALL_DRUSH=true +ENV INSTALL_DRUSH ${INSTALL_DRUSH} +RUN if [ ${INSTALL_DRUSH} = true ]; then \ + # Install Drush 8 with the phar file. + curl -fsSL -o /usr/local/bin/drush https://github.com/drush-ops/drush/releases/download/$DRUSH_VERSION/drush.phar | bash && \ + chmod +x /usr/local/bin/drush && \ + drush core-status \ +;fi + +USER laradock + ##################################### # Node / NVM: ##################################### diff --git a/workspace/xdebug.ini b/workspace/xdebug.ini new file mode 100644 index 0000000..06eef4a --- /dev/null +++ b/workspace/xdebug.ini @@ -0,0 +1,12 @@ +; NOTE: The actual debug.so extention is NOT SET HERE but rather (/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini) + +xdebug.remote_autostart=1 +xdebug.remote_enable=1 +xdebug.remote_connect_back=1 +xdebug.cli_color=1 +xdebug.remote_handler=dbgp +xdebug.remote_mode=req + +xdebug.remote_port=9000 +xdebug.remote_host=dockerhost +xdebug.idekey=PHPSTORM diff --git a/xdebugPhpFpm b/xdebugPhpFpm new file mode 100644 index 0000000..1a343ce --- /dev/null +++ b/xdebugPhpFpm @@ -0,0 +1,91 @@ +#! /bin/bash + +# NOTE: At the moment, this has only been confirmed to work with PHP 7 + + +# Grab full name of php-fpm container +PHP_FPM_CONTAINER=$(docker-compose ps | grep php-fpm | cut -d" " -f 1) + +xdebug_status () +{ + echo 'xDebug status' + + # If running on Windows, need to prepend with winpty :( + if [[ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]]; then + winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v' + + else + docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v' + fi + +} + +xdebug_start () +{ + echo 'Start xDebug' + + # And uncomment line with xdebug extension, thus enabling it + ON_CMD="sed -i 's/^;zend_extension=/zend_extension=/g' \ + /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini" + + + # If running on Windows, need to prepend with winpty :( + if [[ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]]; then + winpty docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}" + docker restart $PHP_FPM_CONTAINER + winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v' + + else + docker exec -it $PHP_FPM_CONTAINER bash -c "${ON_CMD}" + docker restart $PHP_FPM_CONTAINER + docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v' + fi + +} + +xdebug_stop () +{ + echo 'Stop xDebug' + + # Comment out xdebug extension line + OFF_CMD="sed -i 's/^zend_extension=/;zend_extension=/g' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini" + + + # If running on Windows, need to prepend with winpty :( + if [[ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]]; then + # This is the equivalent of: + # winpty docker exec -it laradock_php-fpm_1 bash -c 'bla bla bla' + # Thanks to @michaelarnauts at https://github.com/docker/compose/issues/593 + winpty docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}" + docker restart $PHP_FPM_CONTAINER + #docker-compose restart php-fpm + winpty docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v' + + else + docker exec -it $PHP_FPM_CONTAINER bash -c "${OFF_CMD}" + # docker-compose restart php-fpm + docker restart $PHP_FPM_CONTAINER + docker exec -it $PHP_FPM_CONTAINER bash -c 'php -v' + fi +} + + +case $@ in + stop|STOP) + xdebug_stop + ;; + start|START) + xdebug_start + ;; + status|STATUS) + xdebug_status + ;; + *) + echo "xDebug [Stop | Start | Status] in the ${PHP_FPM_CONTAINER} container." + echo "xDebug must have already been installed." + echo "Usage:" + echo " ./xdebugPhpFpm stop|start|status" + +esac + +exit 1