CI for Laravel

The Build Environment

Builds are run within containers. The build container is designed to match Laravel Forge's environment as much as possible.

The build container has several versions of PHP and NodeJS available. Here is what the build container has installed:

PHP

The default PHP version used in the container is set ahead of time within the project settings. However, you are free to use commands php8.2, php8.1, php8.0, php7.4, php7.3, php7.2, or php7.1. The default PHP version only effects what version is used with command php.

The following PHP versions are available:

  • 8.2
  • 8.1
  • 8.0
  • 7.4
  • 7.3
  • 7.2
  • 7.1

For example, you can run the following commands within a build step:

php -v    # the version is set within project configuration
php8.2 -v # always php 8.2
php8.1 -v # always php 8.1
php8.0 -v # always php 8.0
php7.4 -v # always php 7.4
php7.3 -v # always php 7.3
php7.2 -v # always php 7.2
php7.1 -v # always php 7.1

For the most part, the PHP version should be set within your project settings. However, If you need to dynamically set which PHP version is the default, you can run the following within your build pipeline:

# Example:
# Set "php" command to "php8.0"
sudo update-alternatives --set php php8.0

The following modules are installed as reported by php -m:

  • bcmath
  • calendar
  • Core
  • ctype
  • curl
  • date
  • dom
  • exif
  • fileinfo
  • filter
  • ftp
  • gd
  • gettext
  • gmp
  • hash
  • iconv
  • igbinary
  • imagick
  • imap
  • intl
  • json
  • ldap
  • libxml
  • mbstring
  • memcached
  • msgpack
  • mysqli
  • mysqlnd
  • openssl
  • pcntl
  • pcre
  • PDO
  • pdo_mysql
  • pdo_pgsql
  • pdo_sqlite
  • pgsql
  • Phar
  • posix
  • readline
  • redis
  • Reflection
  • session
  • shmop
  • SimpleXML
  • soap
  • sockets
  • sodium
  • SPL
  • sqlite3
  • standard
  • sysvmsg
  • sysvsem
  • sysvshm
  • tokenizer
  • wddx
  • xdebug
  • xml
  • xmlreader
  • xmlwriter
  • xsl
  • Zend OPcache
  • zip
  • zlib

There is no global phpunit command installed. You are encouraged to use phpunit included via your project's composer.json file.

The $PATH variable is set to include ./vendor/bin, so you can reference commands such as phpunit without needing to write ./vendor/bin/phpunit.

Composer

You can run composer version 1 and 2 in your pipeline. The default composer command is version 2. The command composer1 is available as well.

# Use composer version 1
composer1 install --no-interaction --prefer-dist --optimize-autoloader

# Use composer version 2 with either of these
composer install --no-interaction --prefer-dist --optimize-autoloader
composer2 install --no-interaction --prefer-dist --optimize-autoloader

Alternatively, you can "update" the default version to another major version:

# "Update" composer to version 1
sudo composer self-update --1

composer --version # 1.x.x

# Update composer to version 2
sudo composer self-update --2

composer --version # 2.x.x

NodeJS

The NodeJS version used in the container is set ahead of time within the project settings.

No global packages are installed other than node, npm, and yarn.

The $PATH variable is set to include ./node_modules/.bin, so you can reference NodeJS commands without using a relative path.

You can dynamically set which NodeJS version is used. This is useful if the build container needs a newer minor point release, or if you need to use an older version of NodeJS.

To change node version, run the following in your build pipeline before running any node/npm commands:

# Example: Downgrade NodeJS to 14.16.0
source ~/.nvm/nvm.sh
nvm install 14.16.0
nvm use 14.16.0

# Tell other pipeline steps to
# use this version also
nvm alias default 14.16.0

Browser Testing

Browser testing is available for Dusk tests via the Chrome driver. More documentation on using Laravel Dusk available here.

Other

The aws command line utility is installed globally. This requires Python, and so python2, pip, python3, and pip3 are also installed.

The following basic utilities are available (although this is not an exhaustive list):

  • curl
  • wget
  • git
  • zip/unzip
  • tar
  • gzip/gunzip

Sudo

The sudo command is available to use, in case you need to install other utilities or change configuration.

For example, certain customers from Down Under have needed to change locale settings to get the correct currency in PHP. If you need to do something like that, you may want to run the following (or similar):

echo "en_AU.UTF-8 UTF-8" | sudo tee -a /etc/locale.gen \
    && sudo locale-gen

echo "LANG=\"en_AU.UTF-8\"" | sudo tee -a /etc/default/locale
echo "LANG=\"en_AU.UTF-8\"" >> /home/chipper/.profile
echo "LC_MONETARY=\"en_AU.UTF-8\"" >> /home/chipper/.profile

source /home/chipper/.profile