Force PHP version during GitHub Actions job

Published under Devops.

The packages that come pre-installed on a GitHub Actions job are controlled by the virtual environment you choose to use. Recently, GitHub updated the set of default packages on their virtual environments, including the default PHP version from 7.4 to 8.0. This caused havoc with some of my GitHub Action builds, which aren't yet ready to use PHP 8.

To use a previous version of PHP with your GitHub Actions build, you can use the Setup PHP Action:

The above example will install and setup PHP 7.4 as the default for the rest of the job.

If you are curious to know what packages come pre-installed with GitHub Action's virtual environments, you can check them out on the actions/virtual-environments repository.

Thanks for reading!

Did you find this post useful? Let me know on Twitter! If you found an issue with the content, submit a pull request!

Subscribe to my newsletter to know when I publish more content in the future.

❤️ Likes: 2
📣 Retweets: 4
💬 Replies: 0
🙊 Mentions: 0