I was searching for a long time to test on Travis my symfony application using postgis extension.

I read the Travis documentation to enabled Postgis and my .travis.yml was this one:

# Project language (I use php)
language: php

# To start postgresql
  - postgresql

  # aliased to a recent 7.0.x version
  - 7.1
  # aliased to a nightly version
  - nightly

# Matrix to test in every php version
  # Fast finish allows to set the build as "finished" even if the "allow_failures" matrix elements are not finished yet.
  fast_finish: true
    - php: nightly

# Define an environment variable
  - SYMFONY_VERSION="3.3.*" DB=postgresql

# Update composer
  - composer self-update

  # Testing to reinstall it
  - sudo apt-get install postgresql-9.6-postgis-2.3 postgis -y -q
  # Parameters are copied
  - cp app/config/parameters.yml.travis app/config/parameters.yml
  # Database creation
  - psql -c 'create database symfony;' -U postgres
  # Postgis extension creation
  - psql -U postgres -c "create extension postgis" -d symfony
  # - psql -c 'CREATE EXTENSION postgis_topology;' -U postgres -d symfony
  # excution de composer
  - composer install
  # Database migration to current version
  - php bin/console doctrine:migrations:migrate  --no-interaction
  # loading data for phpunit and codecept tests
  - php bin/console doctrine:fixtures:load --fixtures ./src/AppBundle/DataFixtures -n --env=test

  # Tests de versions
  - psql --version
  - psql -d symfony -c 'SELECT PostGIS_version();' -U postgres
  # Phpunit 
  - if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then travis_wait 40 php vendor/phpunit/phpunit/phpunit --coverage-clover build/logs/clover.xml; fi
  - if [ "$TRAVIS_PHP_VERSION" != "7.1" ]; then php vendor/phpunit/phpunit/phpunit; fi

But an error occured when creating postgis extension. Error occured on this line:

$ psql -U postgres -c "create extension postgis" -d symfony

ERROR: could not access file "$libdir/postgis-2.3": No such file or directory Error postgis


I search the web and I found Error to create postgis extension which is similar.

It seems that there is more than one Postgis version on Travis dockers and Postgis don't know which version to install. The Travis documentation is clearly incomplete. After 20 or more tries on Travis, I found the solution! I share it here.

To resolv this kind of problem on Travis environment, you should:

  • Declare which version of PostgreSQL you would like to use.
  • Allow the sudo command
  • Reinstall the corresponding Postgis package

So I added on my travis file these lines:

# Just after declaring "services postgresql", specify the version
  postgresql: "9.6"

# Allow the sudo command
sudo: true

# On the first line after `before_script`...
  # ... I install the good version (PgSQL 9.6 Postgis 2.3)
  - sudo apt-get install postgresql-9.6-postgis-2.3 postgis -y -q

Here is a link to the failing job

Here is a link to the successful job

Postgis extension is successfully installed


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.