Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
php: circleci/php@1.1.0
Use php
elements in your existing workflows and jobs.
Example showing how to install Composer then installing packages for a project.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
jobs:
install_composer_packages:
executor: php/default
steps:
- checkout
- php/install-composer:
install-version: 1.10.16
- php/install-packages
orbs:
php: circleci/php@x.y
version: 2.1
workflows:
install:
jobs:
- install_composer_packages
Example showing how to install a specific PHP version (7.3). 7.4 is installed by default.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
jobs:
install_php:
docker:
- image: cimg/base:edge
steps:
- checkout
- php/install-php:
version: '7.3'
orbs:
php: circleci/php@x.y
version: 2.1
workflows:
install:
jobs:
- install_php
Run composer test on your application in a more opinionated manner.
1
2
3
4
5
6
7
orbs:
php: circleci/php@x.y
version: 2.1
workflows:
test:
jobs:
- php/test
Simple drop-in job to test your PHP application automatically.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
app-dir | Path to the directory containing your composer.json file. Not needed if composer.json lives in the root. | No | ~/project | string |
setup | Provide any optional steps you would like to run prior to installing the composer packages. This is a good place to install global packages. | No | [] | steps |
test-command | The name of the script within your composer.json which will run your tests. | No | test | string |
version | The `cimg/php` Docker image version tag. | No | '7.4' | string |
Install Composer
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
install-dir | By default, composer will be installed at "/usr/local/bin/composer", use this to override the install directory.
| No | /usr/local/bin | string |
install-version | By default, composer will install the latest composer version, use this to override the installed version.
| No | '' | string |
Install your composer packages with automated caching and best practices applied.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
app-dir | Path to the directory containing your composer.json file. Not needed if composer.json lives in the root. | No | ~/project | string |
cache-files-dir | Absolute path to the file cache folder. This should be inline with "composer global config cache-files-dir --absolute". | No | /home/circleci/.composer/cache/files | string |
cache-key | If this file is updated a new cache bucket will be created. Recommended to use composer.lock. Use composer.json when composer.lock is absent. | No | composer.lock | string |
cache-version | Change the default cache version if you need to clear the cache for any reason. | No | v1 | string |
install-flags | By default, packages will be installed with "composer install --no-interaction --prefer-dist", use this to override the standard install flags.
| No | '--no-interaction --prefer-dist' | string |
vendor-dir | Relative path to the vendor folder. Relative to "app-dir". This should be inline with "composer config vendor-dir". | No | vendor | string |
with-cache | Enable automatic caching of your dependencies for increased speed. | No | true | boolean |
Install PHP into your Ubuntu or Debian based image.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
version | The PHP version. | No | '7.4' | string |
The official CircleCI CIMG PHP Docker image.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
tag | The `cimg/php` Docker image version tag. | No | '7.4' | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
commands:
install-composer:
description: Install Composer
parameters:
install-dir:
default: /usr/local/bin
description: |
By default, composer will be installed at "/usr/local/bin/composer", use this to override the install directory.
type: string
install-version:
default: ""
description: |
By default, composer will install the latest composer version, use this to override the installed version.
type: string
steps:
- run:
command: |
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --filename=composer --install-dir=<<parameters.install-dir>> <<#parameters.install-version>>--version=<<parameters.install-version>><</parameters.install-version>>
name: Install Composer
install-packages:
description: |
Install your composer packages with automated caching and best practices applied.
parameters:
app-dir:
default: ~/project
description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root.
type: string
cache-files-dir:
default: /home/circleci/.composer/cache/files
description: Absolute path to the file cache folder. This should be inline with "composer global config cache-files-dir --absolute".
type: string
cache-key:
default: composer.lock
description: If this file is updated a new cache bucket will be created. Recommended to use composer.lock. Use composer.json when composer.lock is absent.
type: string
cache-version:
default: v1
description: Change the default cache version if you need to clear the cache for any reason.
type: string
install-flags:
default: --no-interaction --prefer-dist
description: |
By default, packages will be installed with "composer install --no-interaction --prefer-dist", use this to override the standard install flags.
type: string
vendor-dir:
default: vendor
description: Relative path to the vendor folder. Relative to "app-dir". This should be inline with "composer config vendor-dir".
type: string
with-cache:
default: true
description: Enable automatic caching of your dependencies for increased speed.
type: boolean
steps:
- when:
condition: << parameters.with-cache >>
steps:
- restore_cache:
keys:
- composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }}
- run:
command: |
if [ ! -f "composer.json" ] && [ ! -f "composer.lock" ]; then
echo
echo "---"
echo "Unable to find your composer.json and composer.lock files. Did you forget to set the app-dir parameter?"
echo "---"
echo
echo "Current directory: $(pwd)"
echo
echo
echo "List directory: "
echo
ls
exit 1
fi
name: Verify composer.json and/or composer.lock exist
working_directory: <<parameters.app-dir>>
- run:
command: composer install <<parameters.install-flags>>
name: Installing Composer Packages
working_directory: <<parameters.app-dir>>
- when:
condition: << parameters.with-cache >>
steps:
- save_cache:
key: composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }}
paths:
- <<parameters.app-dir>>/<<parameters.vendor-dir>>
- <<parameters.cache-files-dir>>
install-php:
description: Install PHP into your Ubuntu or Debian based image.
parameters:
version:
default: "7.4"
description: The PHP version.
type: string
steps:
- detect/init
- run:
command: |
sudo apt update && sudo apt install -y software-properties-common
if [[ $OSD_ID == "ubuntu" ]]; then
sudo add-apt-repository -yu ppa:ondrej/php
elif [[ $OSD_ID == "debian" ]]; then
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo add-apt-repository "deb https://packages.sury.org/php/ $(lsb_release -cs) main"
else
echo "OS not supported."
fi
sudo apt-get update
sudo apt-get install -y php<< parameters.version >>
name: Install PHP
description: |
Common CircleCI tasks for the PHP programming language.
display:
source_url: https://github.com/circleci-public/php-orb
examples:
install_composer_packages:
description: |
Example showing how to install Composer then installing packages for a project.
usage:
jobs:
install_composer_packages:
executor: php/default
steps:
- checkout
- php/install-composer:
install-version: 1.10.16
- php/install-packages
orbs:
php: circleci/php@x.y
version: 2.1
workflows:
install:
jobs:
- install_composer_packages
install_php_version:
description: |
Example showing how to install a specific PHP version (7.3). 7.4 is installed by default.
usage:
jobs:
install_php:
docker:
- image: cimg/base:edge
steps:
- checkout
- php/install-php:
version: "7.3"
orbs:
php: circleci/php@x.y
version: 2.1
workflows:
install:
jobs:
- install_php
test_application:
description: |
Run composer test on your application in a more opinionated manner.
usage:
orbs:
php: circleci/php@x.y
version: 2.1
workflows:
test:
jobs:
- php/test
executors:
default:
description: The official CircleCI CIMG PHP Docker image.
docker:
- image: cimg/php:<< parameters.tag >>
parameters:
tag:
default: "7.4"
description: The `cimg/php` Docker image version tag.
type: string
jobs:
test:
description: |
Simple drop-in job to test your PHP application automatically.
executor:
name: default
tag: << parameters.version >>
parameters:
app-dir:
default: ~/project
description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root.
type: string
setup:
default: []
description: Provide any optional steps you would like to run prior to installing the composer packages. This is a good place to install global packages.
type: steps
test-command:
default: test
description: The name of the script within your composer.json which will run your tests.
type: string
version:
default: "7.4"
description: The `cimg/php` Docker image version tag.
type: string
steps:
- checkout
- steps: << parameters.setup >>
- install-packages:
app-dir: <<parameters.app-dir>>
- run:
command: composer <<parameters.test-command>>
name: Run Tests
working_directory: <<parameters.app-dir>>
orbs:
detect: circleci/os-detect@0.1
version: 2.1