This is simple docker build for deploying php development environment
The build consists of the following components:
- NGINX
- PHP (with xdebug and error report)
- MySql
- Go to the root of this project folder
- Type in the terminal -> docker-compose up
Setting Up a Modern PHP Development Environment:
Create folders structure for logs, config and sites. and mount volumes in this folders. Place file with config for virtual host in "./config/nginx/" folder
We could just serve files from the /sites (which is /var/www in container) directory, but it’s good practice to keep most PHP files out of the publicly accessible directory. As PHP scripts will need to load files using ../, we’ll put our public directory one level down.
There’s a new service, php, which is using the image php:fpm-latest. For NGINX, you’ll need to use an fpm (FastCGI Process Manager) package.
Because PHP will need to access your .php files from the /var/www directory, you’ll need to mount the volume in the PHP image in the same way you did for the NGINX image. PHP doesn’t need access to the nginx.conf configuration file, so there’s no need to give it access to it.
The app folder is now accessible on the host machine, and in the nginx and php containers.
XDEBUG. We can config php.ini (/usr/local/etc/php/php.ini) or we can create separate file xdebug.ini and place it on "/usr/local/etc/php/conf.d/" folder
This time there’s an environment block, which is used to pass some variables to the container when it’s created. These are used to configure the database with the following options. Set your own values for the following variables:
MYSQL_ROOT_PASSWORD: the root password for the database. You can use this to log in as root and manage the database.
MYSQL_USER and MYSQL_PASSWORD: the name and password for a MySQL user that gets created with limited permissions. You’ll want to use this from your PHP scripts.
MYSQL_DATABASE: the name of a schema, which is automatically created, that the user defined above has access to.
The example above creates a database called tutorial, which can be access using the user tutorial and password secret.
- Setting -> PHP. Set php CLI interpreter over docker container.
- Path mapping is set automatically, check it.
- Setting -> PHP -> Servers. Set localhost server
- Settings -> Build, Execution, Deployment -> Docker. Set up docker container
-
Set up launch.json with this configuration:
{ "name": "Xdebug", "type": "php", "request": "launch", "port": 9003, "pathMappings": { "/var/www/": "E:/docker/php-dev-environment/sites/" }, "log": true }
- Attach exec /bin/bash for php container
- Open /var/www/sites/ folder
- Download lavaravel - composer create-project laravel/laravel example-app
- cd ./example-app and use command - php artisan serve --host 0.0.0.0 or set up virtual host to /var/www/sites/laravel/public
- Install laravel plugin from setting
- Configure database. For host-db we are use inner ip of mysql container (usually like 172.16.0.3)
- profit