Deploy local build with Deployer7


Deployer is a great tool to deploy your PHP Project.

Deployer executes a set of commands on the target server to build your project and enable the newly built version. A typical deployment process with Deployer involves SSHing into the target machine, where it performs a Git checkout of the project, installs dependencies via Composer, runs build commands, and possibly triggers some database migrations. When everything is successful, it will symlink the webroot to the new release.

On some servers, however, there are limitations that make this process unfeasible. For instance, you can’t install Composer, Git isn’t available, the CLI PHP version is different and can’t be changed, or certain asset-building processes aren’t possible because Node.js isn’t installed. This is often the case with shared hosting.

Continue reading “Deploy local build with Deployer7”

Testing PDF creation with headless chrome and PHP

I had the task the other day to use a headless chrome to generate PDF files from websites in a PHP app.

The plan was to use chrome-php with a headless chrome to generate the PDF.

Usually you would install chrome/chromium on a linux server via apt and just run chrome from the PATH with chrome.
Since i was on shared hosting i was not sure if this was possible since i was not allowed to run apt commands.
So i tried to use Puppeteer which ships a headless chrome executable and use just this directly.
I installed Puppeteer with npm locally and uploaded the chrome executable to the shared hosting.
Puppeteer will place the headless chrome in the .cache dir in your home directory, f.e.:

~/.cache/puppeteer/chrome/linux-113.0.5672.63/chrome-linux64/chrome

Upload:

scp -r ~/.cache/puppeteer/chrome/linux-113.0.5672.63/chrome-linux64 me@sharedhosting:/usr/home/test

Continue reading “Testing PDF creation with headless chrome and PHP”

Import data into MySql with docker-compose

Having a docker-compose setup which involves a Database like Mysql or MariaDB, then at some point you might want to import data into those Databases.

There are several ways to import the data in your docker-compose setup.

  1. Using a volume for import data
  2. Using mysql client from commandline with docker-compose exec
  3. Using phpmyadmin in docker-compose setup
  4. Using a mysql GUI client on the host and connect to the DB in the Docker container

So let’s see how we can do this:

Continue reading “Import data into MySql with docker-compose”

Symfony deprecation log channel

Are you annoyed of too many deprecation warnings in you logs of your symfony app?
Probably yes because it is really a lot of noise.
However deprecation logs are still useful to ensure future compatibility of your app.

So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with this monolog config:

monolog:
    channels:
        - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it existsCode language: PHP (php)

This is added already in the recipe and ships when installing symfony.

Ok, but the handler for this deprecation channel is not configured, so you have to do this yourself.
How? Add this to your monolog config:

Continue reading “Symfony deprecation log channel”

Disable SilverStripe deprecation warnings in PHP8.1

Since SilverStripe 4.10 is not yet fully ready for PHP8.1 you wil receive quite some deprecation warnings in dev mode when you are brave and run it nonetheless on PHP8.1.

Deprecated: SilverStripe\Config\Collections\MemoryConfigCollection implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /var/www/html/vendor/silverstripe/config/src/Collections/MemoryConfigCollection.php on line 13

Unfortunatly we can’t control the error_reporting from SilverStripe since it is set in the kernel of the framework.
So we are forced to hack the Kernel which is rather unfortunate.

In the SilverStripe Slack channel someone proposed to use composer-patch which will apply a patch to a given vendor dependency during composer install.
This is quite cool because you don’t need to fork the dependency and take care of getting upstream changes.

So i went this path down and it looks like in this gist:
https://gist.github.com/ivoba/d8c4379236149a8c42e1922ae98a93e3

Continue reading “Disable SilverStripe deprecation warnings in PHP8.1”

Filter a csv file with nodejs streams

So we have a CSV file with a member list and we want to filter all empty emails.

FirstName,LastName,Email
Max,Mustermann,max@mustermann.de
Maxi,Hasnoemail,

With nodejs streams this is almost a one liner.

We will use the csv package from the CSV project which has some sophisticated packages to parse and transform csv data with nodejs streams.

npm install csv

We will further use node as ESM (ECMAScript modules) to be shiningly modern and so lets create a file: index.mjs
Note the .mjs extension, which will tell node to interprete this as ESM. (Since nodejs v12.20.0 && v14.13.0)

We import the packages and create the filesystem streams to read the file, then built a pipeline with the streams and the single steps to process the data and write the results into a new file.
Ok let’s go:

Continue reading “Filter a csv file with nodejs streams”