Continuous Integration and Continuous Deployment with PHP
CircleCI works seamlessly with all the tools and package managers that
help PHP developers test and deploy their code. We can generally infer
most of your dependencies and test commands, but we also provide custom
configuration via a
circle.yml file checked into your repo’s root directory.
The examples here referring to PHP filepaths are for the Ubuntu 14.04 and newer
images. This image is not default but can be choosen in Project Settings ->
Build Environment. For Ubuntu 12.04, replace
~/.phpenv/versions in the examples.
If you don’t want to use the default, you can specify your version in
machine: php: version: 7.0.4
Please contact us if you need a different version; we’ll be happy to install it for you.
Circle has the composer, pear, and pecl package managers installed.
If we find a composer.json file, then we’ll automatically run
To install your dependencies with either
you have to include dependency commands
The following example shows how to install the MongoDB extension using
dependencies: pre: - pecl install mongo
You can also edit your PHP configuration from your
circle.yml. For example, if you have a custom configuration file checked in to your repo, then you could do:
dependencies: pre: - cp config/custom.ini /opt/circleci/php/$(phpenv global)/etc/conf.d/
phpenv global returns the PHP version that has been
specified in your
Here’s another example showing how you could adjust PHP settings in
dependencies: pre: - echo "memory_limit = 64M" > /opt/circleci/php/$(phpenv global)/etc/conf.d/memory.ini
you’ll have to specify your PHP version in your
circle.yml in order to edit PHP’s configuration files.
We have pre-installed more than a dozen databases and queues, including PostgreSQL and MySQL. If needed, you have the option of manually setting up your test database.
Using the Apache Webserver
Apache2 is already installed on CircleCI containers but it needs to be configured to host your PHP application.
To enable your site check a file containing your site configuration into your
repository and copy it to
Then enable the site with
a2ensite and restart Apache.
An example configuration that sets up Apache to serve the PHP site from
Listen 8080 <VirtualHost *:8080> LoadModule php5_module /opt/circleci/php/PHP_VERSION/libexec/apache2/libphp5.so DocumentRoot /home/ubuntu/MY-PROJECT/server-root ServerName host.example.com <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> </VirtualHost>
MY-SITE in with the name of your site configuration
PHP_VERSION with the version of PHP you configured
Then enable your site and restart Apache by adding the following to your
dependencies: post: - cp ~/MY-PROJECT/MY-SITE /etc/apache2/sites-available - a2ensite MY-SITE - sudo service apache2 restart
Circle always runs your tests on a fresh machine. If we find a
phpunit.xml file in your repo, then we’ll run
phpunit for you. You can add custom test commands to the test section of your
test: override: - ./my_testing_script.sh
If you want CircleCI to show a test summary of your build see Metadata collection in custom test steps for PHPUnit.
Xdebug is installed for all versions of PHP, and is enabled by default on our 14.04 build image.
During the dependencies stage of PHP builds our inference runs
composer install if required. In the build output you may see:
You are running composer with xdebug enabled. This has a major impact on runtime performance.
Since this is a CI environment and many of your dependencies will be cached, the performance hit is not major and you can safely ignore the warning.
If you would like to completely disable Xdebug on 14.04 you can add the following to your
dependencies: pre: - rm /opt/circleci/php/$(phpenv global)/etc/conf.d/xdebug.ini
Circle offers first-class support for deployment.
When a build is green, Circle will deploy your project as directed
circle.yml file. We can deploy to PaaS providers as well as to
physical servers under your control.
Troubleshooting for PHP
If you run into problems, check out our PHP troubleshooting write-ups about these issues:
If you are still having trouble, please contact us and we will be happy to help.