Environments


Devilbox - 图1

Overview

The Devilbox The Devilbox is a modern and highly customisable dockerized PHP stack supporting full LAMP and MEAN and running on all major platforms. The main goal is to easily switch and combine any version required for local development. It supports an unlimited number of projects for which vhosts, SSL certificates and DNS records are created automatically. Reverse proxies per project are supported to ensure listening server such as NodeJS can also be reached. Email catch-all and popular development tools will be at your service as well. Configuration is not necessary, as everything is already pre-setup.

Furthermore, the Devilbox provides an identical and reproducible development environment for different host operating systems.

This example will use phalcon to install Phalcon from within the Devilbox PHP container. After completing the steps listed below, you will have a working Phalcon setup ready to be served via http and https.

Configuration

The following configuration will be used:

Project namemy-phalcon
VirtualHost directory/shared/httpd/my-phalcon
Databasen.a.
TLD_SUFFIXloc
Project URLhttp://my-phalcon.loc, https://my-phalcon.loc
  • Inside the Devilbox PHP container, projects are always in /shared/httpd/.
  • On your host operating system, projects are by default in ./data/www/ inside the Devilbox git directory. This path can be changed via HOST_PATH_HTTPD_DATADIR.

Setup

Your environment will be ready in six simple steps:

  • Enter the PHP container
  • Create a new VirtualHost directory
  • Install Phalcon
  • Symlink webroot directory
  • Setup DNS record
  • Visit http://my-phalcon.loc in your browser
  • (Nginx) Create custom vhost config file

Enter the PHP container

All the work will be performed inside the PHP container since it offers all the necessary tools. Navigate to the Devilbox git directory and execute ./shell.sh (or shell.bat on Windows) to enter the running PHP container.

  1. host> ./shell.sh

Create new vhost directory

The vhost directory defines the name under which your project will be available. (<vhost dir>.TLD_SUFFIX will be the final URL ).

  1. [email protected] in /shared/httpd $ mkdir my-phalcon

Install Phalcon

Navigate into your newly created vhost directory and install Phalcon with phalcon cli.

  1. [email protected] in /shared/httpd $ cd my-phalcon
  2. [email protected] in /shared/httpd/my-phalcon $ phalcon project phalconphp

The directory structure looks like this after the installation:

  1. [email protected] in /shared/httpd/my-phalcon $ tree -L 1
  2. .
  3. └── phalconphp
  4. 1 directory, 0 files

Symlinking the actual webroot directory to htdocs is important. The web server expects every project’s document root to be in <vhost dir>/htdocs/. This is the path where it will serve the files. This is also the path where the entry point of your application (usually index.php) needs to reside.

Some frameworks however, store files and content in nested directories of unknown levels. It is therefore impossible to set this as a pre-set for the environment. You will therefore have to manually set a symlink back to the expected path that your framework requires.

  1. [email protected] in /shared/httpd/my-phalcon $ ln -s phalconphp/public/ htdocs

The directory structure looks like this after the installation:

  1. [email protected] in /shared/httpd/my-phalcon $ tree -L 1
  2. .
  3. ├── phalconphp
  4. └── htdocs -> phalconphp/public
  5. 2 directories, 0 files

As you can see in the above listing, the htdocs folder that is required by the web server is now pointing to the entry point of your framework.

When using Docker Toolbox, you need to explicitly allow the usage of symlinks.

DNS record

If you have Auto DNS configured already, you can skip this section, because DNS entries will be available automatically by the bundled DNS server.

If you do not have Auto DNS configured, you will need to add the following line to your host operating system /etc/hosts file (or C:\Windows\System32\drivers\etc on Windows):

  1. 127.0.0.1 my-phalcon.loc

Open your browser

Open your browser and navigate to http://my-phalcon.loc or https://my-phalcon.loc

Create custom vhost config file (Nginx Only)

By default routes will not work if using Nginx. To fix this, you will need to create a custom vhost configuration.

In your project folder, you will need to create a folder called .devilbox unless you changed HTTPD_TEMPLATE_DIR in your .env

Copy the default nginx config from ./cfg/vhost-gen/nginx.yml-example-vhost to ./data/www/my-project/.devilbox/nginx.yml

Carefully edit the nginx.yml file and change:

try_files $uri $uri/ /index.php$is_args$args;

to

try_files $uri $uri/ /index.php?_url=$uri&$args;

and

location ~ .php?$ {

to

location ~ [^/].php(/|$) {

Save the file as nginx.yml and ensure not to use any tabs in the file or devilbox will not use the custom configuration. You can use yamllint nginx.yml whilst inside the Devilbox shell to check the file before restarting devilbox.

References