Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

hexhoc/php-dev-environment

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-dev-environment

This is simple docker build for deploying php development environment

The build consists of the following components:

  1. NGINX
  2. PHP (with xdebug and error report)
  3. MySql

Installation:

  1. Go to the root of this project folder
  2. Type in the terminal -> docker-compose up

Setting Up a Modern PHP Development Environment:

1. NGINX

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.

2. PHP

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

3. MySql

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.

How to set up debugging in IDE

PHP STORM

  1. Setting -> PHP. Set php CLI interpreter over docker container.
  2. Path mapping is set automatically, check it.
  3. Setting -> PHP -> Servers. Set localhost server
  4. Settings -> Build, Execution, Deployment -> Docker. Set up docker container

VS CODE

  1. 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
     }
    

How to set up laravel

  1. Attach exec /bin/bash for php container
  2. Open /var/www/sites/ folder
  3. Download lavaravel - composer create-project laravel/laravel example-app
  4. 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
  5. Install laravel plugin from setting
  6. Configure database. For host-db we are use inner ip of mysql container (usually like 172.16.0.3)
  7. profit

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.