GitHub CI Workflow for PHP applications

Mattias Geniar has shared his GitHub Workflow to make GitHub do the CI work for PHP applications: on: push name: Run phpunit testsuite jobs: phpunit: runs-on: ubuntu-latest container: image: mattiasgeniar/php73 steps: – uses: actions/[email protected] with: fetch-depth: 1 – name: Install composer dependencies run: | composer install –prefer-dist –no-scripts -q -o; – name: Prepare Laravel Application […]

Working with symlinked packages in PHP

When developing a PHP library/package, you most likely also have a project on disk that consumes said library. Take a WordPress plugin for example: to test it, you need a WordPress installation — both are linked but separate projects. To speed up development you can tell Composer to use the local version of the package, […]

Overriding the PHP version to use when installing Composer dependencies

If you have a (legacy) PHP project running on a legacy server (running PHP 5.4.27 for example), but are locally developing with a more modern PHP version (PHP 7.4 for example), you might end up installing dependencies that are not compatible with the PHP version on the server. To bypass this, you can tell Composer, […]

Run prettier or php-cs-fixer with GitHub Actions

Stefan Zweifel shares his GitHub Actions Workflows to run prettier and php-cs-fixer on his repos: Over the past few weeks I’ve added a handful of workflows to my projects. One workflow is really like, is to run prettier and php-cs-fixer to automatically format my code and commit the fixed files back to the repository. Here’s […]

Easily find and remove old and heavy node_modules/vendor folders with npkill

When working in web, you can be left with several lost node_modules (JS) and vendor (PHP) folders spread across your filesystem, unnecessarily taking up space. To find these, I use the following command: # List all node_modules (from current directory down) and their size $ find . -name ‘node_modules’ -type d -prune -print | xargs […]

Connect to Remote MySQL Server with SSL Certificates from PHP: Fixing the error "Terminated due to signal: ABORT TRAP (6)"

Photo by Clem Onojeghuo on Unsplash To connect to a MySQL Server that requires SSL from PHP with PDO, you can use this piece of code: try { $db = new PDO('mysql:host=DB_HOST;dbname=DB_NAME', $user, $pass, [ PDO::MYSQL_ATTR_SSL_KEY => 'path/to/client_private_key', PDO::MYSQL_ATTR_SSL_CERT => 'path/to/client_cert', PDO::MYSQL_ATTR_SSL_CA => 'path/to/server_ca_cert', ]); } catch (PDOException $e) { print "Error!: " . $e->getMessage() […]

spatie/test-time – A PHP package to control the flow of time

Freek has created spatie/test-time, a package to easily freeze/rewind/advance time in PHP. Imagine you’re building that your app can notify your user, but you don’t want to send more than one notification in a timeframe of five seconds. How are you going to test the time aspect? Do you have to create a test that […]

PHP Insights – Analyze the Code Quality of your PHP Projects

PHP Insights is a Static Analysis Tool for your PHP code. It contains built-in checks for making code reliable, loosely coupled, simple, and clean. Works out-of-the-box with the current set of popular frameworks. # First, install: composer require nunomaduro/phpinsights –dev # Then, use it: ./vendor/bin/phpinsights PHP Insights →