├── LICENSE └── readme.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Cyber-Duck 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # PHP-FPM Docker image for Laravel 2 | 3 | Docker image for a php-fpm container crafted to run Laravel based applications. 4 | 5 | ## Specifications: 6 | 7 | * PHP 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1 / 7.0 / 5.6 / 5.4 8 | * OpenSSL PHP Extension 9 | * PDO PHP Extension 10 | * SOAP PHP Extension 11 | * Mbstring PHP Extension 12 | * Tokenizer PHP Extension 13 | * XML PHP Extension 14 | * PCNTL PHP Extension 15 | * ZIP PHP Extension 16 | * GD PHP Extension 17 | * BCMath PHP Extension 18 | * GMP PHP Extension 19 | * Intl PHP Extension 20 | * Imagick PHP Extension 21 | * Memcached 22 | * Composer 23 | * Laravel Cron Job for the [task scheduling](https://laravel.com/docs/11.x/scheduling) setup 24 | * PHP ini values for Laravel (see [`laravel.ini`](laravel.ini)) 25 | * xDebug (PHPStorm friendly, see [`xdebug.ini`](xdebug.ini)) 26 | * `t` alias created to run unit tests `vendor/bin/phpunit` with `docker-compose exec [service_name] t` 27 | * `d` alias created to run Laravel Dusk browser tests `artisan dusk` with `docker-compose exec [service_name] d` 28 | * `art` alias created to run the Laravel `artisan` command 29 | * `fresh` alias created to migrate the database fresh and seed the seeders `artisan migrate:fresh --seed` 30 | 31 | ## Tags available: 32 | 33 | When calling the image you want to use within your `docker-compose.yml` file, 34 | you can specify a tag for the image. Tags are used for various versions of a 35 | given Docker image. 36 | 37 | * [`8.4`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/8.4) 38 | * [`8.3`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/8.3) 39 | * [`8.2`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/8.2) 40 | * [`8.1`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/8.1) 41 | * [`8.0`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/8.0) 42 | * [`7.4`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/7.4) 43 | * [`7.3`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/7.3) 44 | * [`7.2`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/7.2) 45 | * [`7.1`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/7.1) 46 | * [`7.0`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/7.0) 47 | * [`5.6`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/5.6) 48 | * [`5.4`](https://github.com/Cyber-Duck/php-fpm-laravel/tree/5.4) 49 | 50 | **Note:** the `master` branch is not used for generating images, used for documentation instead. Only tags/branches are. 51 | 52 | ## docker-compose usage: 53 | 54 | ```yml 55 | version: '2' 56 | services: 57 | php-fpm: 58 | image: cyberduck/php-fpm-laravel(:) 59 | volumes: 60 | - ./:/var/www/ 61 | - ~/.ssh:/root/.ssh # can be useful for composer if you use private CVS 62 | networks: 63 | - my_net #if you're using networks between containers 64 | ``` 65 | 66 | ## Xdebug usage: 67 | 68 | All images > PHP 8.1 are configured to support xDebug 3. 69 | 70 | The image comes with Xdebug installed but by default it is disabled. Xdebug can be enabled using an environmental 71 | variable. This can either be done using the .env file, passing the envs using docker or passing the envs using 72 | docker-compose. 73 | 74 | ### Using .env file 75 | 76 | Add the following to the env file and then start/restart the container. 77 | 78 | ```text 79 | XDEBUG=true 80 | PHP_IDE_CONFIG="serverName=phpstorm-server" # This is required for PhpStorm only for path mappings 81 | REMOTE_HOST="" # If not set the default is 'host.docker.internal' which will work on OSX and windows 82 | ``` 83 | 84 | ### Using docker 85 | 86 | Pass the required variables with the run command using the -e option. 87 | 88 | ```bash 89 | docker run -d \ 90 | -e XDEBUG=true \ 91 | -e PHP_IDE_CONFIG="serverName=phpstorm-server" \ #This is required for PhpStorm only for path mappings 92 | -e REMOTE_HOST="" \ # If not set the default is 'host.docker.internal' which will work on OSX and windows 93 | -v /root/of/project:/var/www \ 94 | -v ~/.ssh:/root/.ssh \ 95 | cyberduck/php-fpm-laravel(:) 96 | ``` 97 | 98 | ### Using docker-compose 99 | 100 | Pass the variables in the environment section of the service using this image. 101 | 102 | ```yml 103 | version: '2' 104 | services: 105 | php-fpm: 106 | image: cyberduck/php-fpm-laravel(:) 107 | environment: 108 | XDEBUG: true 109 | PHP_IDE_CONFIG: "serverName=phpstorm-server" #This is required for PhpStorm only for path mappings 110 | REMOTE_HOST: "" # If not set the default is 'host.docker.internal' which will work on OSX and windows 111 | volumes: 112 | - ./:/var/www/ 113 | - ~/.ssh:/root/.ssh # can be useful for composer if you use private CVS 114 | networks: 115 | - my_net #if you're using networks between containers 116 | ``` 117 | 118 | ### PhpStorm configuration 119 | 120 | For xdebug to work with PhpStorm you will need to create a server. This can be done by going to **Preferences > 121 | Languages & Frameworks > PHP > Servers** and then follow the steps below. 122 | 123 | 1, Click the `+` symbol. 124 | 125 | 2, Create a name for the server. This will be the value of serverName in the PHP_IDE_CONFIG variable e.g 126 | `PHP_IDE_CONFIG="serverName="`. 127 | 128 | 3, Set Host to `http://localhost` or if using a virtual host then use that instead e.g `http://myapp.localhost`. 129 | 130 | 4, Set the port to the port that is being used on the host machine e.g `80`. 131 | 132 | 5, Set the debugger to Xdebug. 133 | 134 | 6, Check the `Use path mappings` checkbox. 135 | 136 | 7, Under the project files section find the root of the project and on the right hand side fill out its location inside 137 | the container e.g `/var/www`. 138 | 139 | 8, Click apply and close preferences. 140 | 141 | 9, Start listening for incoming connections by going to **Run > Start listening for PHP debug connections** 142 | 143 | 10, Xdebug can now be tested by adding a breakpoint or selecting **Run > Break at first line in PHP scripts** and 144 | refreshing the browser. 145 | 146 | ### Visual studio code configuration 147 | 148 | For Xdebug to work in Visual Studio Code a launch.json will need to be added to .vscode folder in the route of the 149 | project. Please see below for an example of a launch.json file 150 | 151 | ```json 152 | { 153 | "version": "0.2.0", 154 | "configurations": [ 155 | { 156 | "name": "Listen for XDebug", 157 | "type": "php", 158 | "request": "launch", 159 | "port": 9000, 160 | "pathMappings": { 161 | "/var/www": "${workspaceFolder}" 162 | } 163 | } 164 | ] 165 | } 166 | ``` 167 | 168 | Once this has been added then you can navigate to the debug section. On the left hand side under the **BREAKPOINTS** 169 | section uncheck the `Everything` checkbox. Now from the dropdown menu at the top select `listen for Xdebug` then press 170 | the play button. 171 | 172 | Xdebug can now be tested by adding a breakpoint and refreshing the browser. 173 | --------------------------------------------------------------------------------