Overview

Phalcon Compose is a community driven boilerplate development environment for Phalcon projects that runs on Docker. Its purpose is to make it easier to bootstrap Phalcon applications and run them on development or production environments.

Dependencies

To run this stack on your machine, you need at least:

Services

Services included are:

Service nameDescription
mongoMongoDB server container.
postgresPostgreSQL server container.
mysqlMySQL database container.
phpmyadminA web interface for MySQL and MariaDB.
memcachedMemcached server container.
queueBeanstalk queue container.
aerospikeAerospike – the reliable, high performance, distributed database optimized for flash and RAM.
redisRedis database container.
appPHP 7, Apache 2 and Composer container.
elasticsearchElasticsearch is a powerful open source search and analytics engine that makes data easy to search.

Installation

Using Composer, you can create a new project as follows:

  1. composer create-project phalcon/compose --prefer-dist <folder name>

Your output should be similar to this:

  1. Example
  2. Installing phalcon/compose (version)
  3. - Installing phalcon/compose (version)
  4. Loading from cache
  5. Created project in folderName
  6. > php -r "copy('variables.env.example', 'variables.env');"
  7. Loading composer repositories with package information
  8. Updating dependencies (including require-dev)
  9. Nothing to install or update
  10. Generating autoload files

With Git

Another way to initialize your project is with Git.

  1. git clone [email protected]:phalcon/phalcon-compose.git
Make sure that you copy variables.env.example to variables.env and adjust the settings in that file

Add your Phalcon Application into application folder.

Configuration

Add phalcon.local (or your preferred host name) in your /etc/hosts file as follows:

  1. 127.0.0.1 www.phalcon.local phalcon.local

Usage

You can now build, create, start, and attach to containers to the environment for your application. To build the containers use following command inside the project root:

  1. docker-compose build

To start the application and run the containers in the background, use following command inside project root:

  1. # You can use here your prefered project name with "-p my-app" parameter
  2. $ docker-compose up -d

Now setup your project in the app container using the Phalcon Developer Tools

Replace project in with the name of your project/directory (shown in the output of docker-compose up -d)

$ docker exec -t <project_app_1> phalcon project application simple

Now you can now launch your application in your browser visiting http://phalcon.local (or the host name you chose above).

Set up

If your application uses a file cache or writes logs to files, you can set up your cache and log folders as follows:

DirectoryPath
Cache/project/cache
Logs/project/log

Logs

For most containers you can access the logs using the docker logs <container_name> command in your host machine.

Environment variables

You can pass multiple environment variables from an external file to a service’s containers by editing the variables.env file.

Web environment

| Environment variable | Description | Default ||————————|—————————————————-|—————–|| WEB_DOCUMENT_ROOT | Document root for webserver (inside the container).| /project/public || WEB_DOCUMENT_INDEX | Index document. | index.php || WEB_ALIAS_DOMAIN | Domain aliases. | *.vm || WEB_PHP_SOCKET | PHP-FPM socket address. | 127.0.0.1:9000 || APPLICATION_ENV | Application environment. | development || APPLICATION_CACHE | Application cache dir (inside the container). | /project/cache || APPLICATION_LOGS | Application logs dir (inside the container). | /project/logs |

phpMyAdmin variables

| Environment variable | Description | Default ||————————|————————————————————————————————————–|———|| PMA_ARBITRARY | When set to 1 connection to the server will be allowed. | 1 || PMA_HOST | Define address/host name of the MySQL server. | mysql || PMA_HOSTS | Define comma separated list of address/host names of the MySQL servers. Used only if PMA_HOST is empty. | || PMA_PORT | Define port of the MySQL server. | 3306 || PMA_VERBOSE | Define verbose name of the MySQL server. | || PMA_VERBOSES | Define comma separated list of verbose names of the MySQL servers. Used only if PMA_VERBOSE is empty. | || PMA_USER | Define username to use for config authentication method. | phalcon || PMA_PASSWORD | Define password to use for config authentication method. | secret || PMA_ABSOLUTE_URI | The fully-qualified path (e.g. https://pma.example.net/) where the reverse proxy makes phpMyAdmin available. | |

See also

Xdebug Remote debugger (PhpStorm)

For debugging purposes you can setup Xdebug by passing required parameters (see variables.env).

Environment variableDescriptionDefault
XDEBUG_REMOTE_HOSTphp.ini value for xdebug.remote_host (your host IP).
XDEBUG_REMOTE_PORTphp.ini value for xdebug.remote_port.9000
XDEBUG_REMOTE_AUTOSTARTphp.ini value for xdebug.remote_autostart.Off
XDEBUG_REMOTE_CONNECT_BACKphp.ini value for xdebug.remote_connect_back.Off

_NOTE_You can find your local IP address as follows:

  1. # Linux/MacOS
  2. ifconfig en1 | grep inet | awk '{print $2}' | sed 's/addr://' | grep .
  3. # Windows
  4. ipconfig

Troubleshooting

Startup or linking errors

If you got any startup issues you can try to rebuild app container. There will be no loss of data., it is a safe reset:

  1. docker-compose stop
  2. docker-compose rm --force app
  3. docker-compose build --no-cache app
  4. docker-compose up -d

Full reset

To reset all containers, delete all data (mysql, elasticsearch, etc.) but not your project files in application folder:

  1. docker-compose stop
  2. docker-compose rm --force
  3. docker-compose build --no-cache
  4. docker-compose up -d

Updating dependencies

Sometimes the base images (for example phalconphp/php-apache:ubuntu-16.04) are updated. Phalcon Compose depends on these images. You will therefore need to update them and it is always a good thing to do so to ensure that you have the latest functionality available. The dependent containers to these images will need to be updated and rebuilt:

  1. docker pull mongo:3.4
  2. docker pull postgres:9.5-alpine
  3. docker pull mysql:5.7
  4. docker pull phpmyadmin/phpmyadmin:4.6
  5. docker pull memcached:1.4-alpine
  6. docker pull phalconphp/beanstalkd:1.10
  7. docker pull aerospike:latest
  8. docker pull redis:3.4-alpine
  9. docker pull elasticsearch:5.2-alpine
  10. docker pull phalconphp/php-apache:ubuntu-16.04

Linux/MacOS users can use make to perform the task:

  1. make pull

Then you have to reset all containers, delete all data, rebuild services and restart application.

Linux/MacOS users can use make to perform the task:

  1. make reset