Skip to content

getJv/php-webserver

Repository files navigation

Getjv PHP-WEBSERVER Image for MacOs users (to linux check the linux branch)

This is my personal PHP webserver Image. Here is all most cool and essential php tool I use in regular projects

First usage - Video presentation

Feel free to visit the usage presentation in my channel

First usage

  1. Checkout the template project: git clone https://github.com/getJv/php-webserver.git
  2. Go to project root folder: cd php-webserver
  3. chose the branch to mac-users git checkout mac-system
  4. Build the Image: docker build -t getjv/php-fpm --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) ..
  5. Turn the containers on: docker compose up -d
  6. Access the http://localhost

Adding new projects to webserver

  1. Create or add your project into workspace folder aka: workspace/myNewProject2/
  2. inside /config/nginx create a new config file with you project name. aka config/myNewProject2.conf (tip: copy and paste from the default example)
  3. now edit the content of your new config file to map your needs like the server_name and the root folder of your project
    # config/myNewProject2.conf
    
    #others configs[...]
    server_name my-new-project-2.test
    
    root var/www/html/myNewProject2/public
    #others configs[...]

    info: Projects like Laravel or Symfony have their root (documentRoot) in their public folder

Set a custom local DNS for each project

  1. For each .conf file into your config/nginx/ will exist a server_name entry and each of those should have a match into your system /etc/hosts file
  2. So every time you add a new project to your server ensure you update that file, run: sudo nano /etc/hosts add your new entry (aka. 127.0.0.1 my-new-project-2.test) and save. This is exemple how it should like:
    # /etc/hosts
    #others configs[...]
    
    127.0.0.1       my-new-project-2.test
    127.0.0.1       localhost
    255.255.255.255 broadcasthost
  3. now access http://my-new-project-2.test and your browser will load the proper project

Set X-Debug int VS Code

  1. First, do all steps from First use Section
  2. The original Dockerfile image already have all xdebug config out of the box.
  3. (vscode users only) Felix xdebug extention: https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
  4. Install the xdebug extension in your browse: https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc
  5. (vscode users only) Now in the VSCODE Replace the original launch.json with the following:
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Listen for XDebug",
          "type": "php",
          "request": "launch",
          "hostname": "0.0.0.0",
          "port": 9003,
          "log": true,
          "pathMappings": {
            "/var/www/html": "${workspaceFolder}/workspace"
          },
          "ignore": ["**/vendor/**/*.php"],
          "xdebugSettings": {
            "max_children": 10000,
            "max_data": 10000,
            "show_hidden": 1
          }
        }
      ]
    }
  6. Add your break points and be happy!

Useful commands

  • Access as dev user: docker exec -it --user dev php sh
  • Help to find the host/docker ip for xdebug: netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
  • Xdebug.log: docker exec php tail -f /tmp/xdebug.log
  • Bundle shortcut for Dockerfile tests: docker compose down && docker rmi getjv/php-fpm && docker build -t getjv/php-fpm --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) . && docker compose up -d

Source links:

License

The source code for the site is licensed under the MIT license, which you can find in the MIT-LICENSE.txt file.

All graphical assets are licensed under the Creative Commons Attribution 3.0 Unported License.

About

My simple nginx and fpm docker image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published