Category Archives: behat

Environment variables not set when apache2 starts on Travis-CI

I'm trying to setup the integration tests of a php project on Travis-CI. Integration tests use Behat as behavior-driven framework.

I set database connection informations as environment variables into the repository settings on Travi-CI and I can see them exported during the execution:

Setting environment variables from repository settings
$ export DB_USERNAME=travis
$ export DB_PASSWORD=[secure]
$ export DB_HOSTNAME=
$ export DB_PORT=3306
$ export DB_NAME=oraproject_test

but I'm not able to get these values using getenv() into my php code because they are undefined in apache.

I tried adding PassEnv to the VirtualHost definition but I get this warning when apache starts:

[warn] PassEnv variable DB_HOSTNAME was undefined
[warn] PassEnv variable DB_PORT was undefined
[warn] PassEnv variable DB_NAME was undefined
[warn] PassEnv variable DB_USERNAME was undefined
[warn] PassEnv variable DB_PASSWORD was undefined

I configured Apache + PHP as suggested into Travis-CI documentation ( and this is my travis.yml

language: php

  - 5.5
  - 5.4

  - APPLICATION_ENV=acceptance

    - ora.local

  - composer self-update

  - sudo apt-get install apache2 libapache2-mod-fastcgi
  # enable php-fpm
  - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
  - sudo a2enmod rewrite actions fastcgi alias
  - echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
  - sudo cp -f build/travis-ci-apache /etc/apache2/sites-available/default
  - sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/default
  - sudo service apache2 restart
  # Set the GitHub OAuth token to make use of the 5000 per hour rate limit
  - "mkdir -p ~/.composer"
  - cp .travis.composer.config.json ~/.composer/config.json
  - composer install -d src --dev
  - mysql -e 'create database oraproject_test;'
  - src/vendor/bin/doctrine-module orm:schema-tool:create
  - mysql ${DB_NAME} < tests/sql/init.sql


- phpunit --configuration tests/phpunit.xml
- cd tests
- ../src/vendor/bin/behat

How can I tell Apache to "read" the environment variables and let them available to php application?

Thanks a lot