PHP + Apache + Selenium: ApachePHP does not get environment vars

Hi there,

after spending quite some time trying to get my selenium tests running on circleCI I am stuck at a point where I do not know any further:
I have some environment variables which store the credentials for the database. The PHPUnit tests have these _ENV variables and succeed. When starting the selenium tests and opening a page on localhost on selenium, my PHP framework displays an error message that it could not connect to the Database. The reason for this is that the _ENV database credentials seem not to be available for PHP “inside” Apache.

Is there a way that Apache Webserver uses these environment variables as well? See my config.yml below.

Best regards

# PHP CircleCI 2.0 configuration file
# Check for more details
version: 2
      # specify the version you desire here
      - image: circleci/php:7.2-apache-browsers
          DB_STRING:                  mysql:host=;dbname=eoo_test
          DB_USER:                    root
          DB_PASSWORD:                test
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at
      - image: circleci/mysql:5.7.24
          MYSQL_ROOT_PASSWORD: test
          MYSQL_DATABASE: eoo_test

    working_directory: ~/repo

      - checkout
      #install php extensions needed
      - run: sudo apt install -y libpng-dev
      - run: sudo docker-php-ext-install gd
      - run: sudo apt install -y mysql-client
      - run: sudo docker-php-ext-install pdo_mysql
      - run: sudo docker-php-ext-enable pdo_mysql

      #config apache
      - run: sudo chmod 777 /etc/apache2/sites-enabled
      - run: sudo cp /home/circleci/repo/.circleci/example.conf /etc/apache2/sites-available/eoo.conf
      - run: sudo a2ensite eoo
      - run: sudo service apache2 restart
      - run: mkdir test-reports
      - run:
          name: Download Selenium
          command: curl -O
      - run:
          name: Start Selenium
          command: java -jar selenium-server-standalone-3.5.3.jar -log stdout
          Xvfb: 7055
          background: true

      #install composer dependecies
      - run: composer install -n --prefer-dist
      # run tests!
      - run:
          name: Run Unit tests
          command: vendor/bin/phpunit

It looks like you are wanting to show a YAML document. In Markdown, there are two ways of doing that so the indentation is preserved. The easiest way is to use two sets of triple backticks, on their own line, like so:

YAML here

Would you edit your post? The first part appears to not be formatted.

youre absolutely right, formatted it

The first thing to check is to get an SSH session onto your post-fail build server, and do a set to ensure the variables are there.

If that is OK, then you may need to expose them in Apache with the correct Apache directive. Try PassEnv. This is a security feature to ensure that only system variables you want to make available are exposed.


thanks a lot for that quick answer The additional _ENV vars in gerneral are there, only Apache is lacking them. I var_dumped(_ENV) and in selenium echoed the content of the tag to get that output, only 8 or 9 Apache internal environment vars were set.
So i will look into PassEnv.

If there is some pre-existing image for PHP + Selenium, I could use that as well, I just started CircleCi and am not fixed to a certain image yet.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.