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”

Class “Psr\Log\Test\TestLogger” not found

The psr/log package used to have not only the Interface for PSR-3 Logger, but also actual implementations of the interface like the TestLogger.
The TestLogger could be used as mock for any PSR-3 Logger in your test cases.

However from v3 the TestLogger was removed, so that the psr/log package would focus solely on the Interface.

If you used the TestLogger in your project and you or some of your dependencies upgraded psr/log to >= v3 you most likely saw this error:

Class "Psr\Log\Test\TestLogger" not found

Continue reading “Class “Psr\Log\Test\TestLogger” not found”

EU/VAT – Mehrwertsteuer Madness

Calculating European VAT Rates with PHP – the easy way.

Disclaimer: No legal advice, just a little experience report.

If you sell digital things (services, digital goods etc.) to EU countries, you might have to calculate the VAT at the rate of the customer’s country (and even pay it there afterwards).
The latter is even the more inconvenient part, but at least the first part can be done quite easily with good old PHP.

Continue reading “EU/VAT – Mehrwertsteuer Madness”

Persistente Objekte in PHP und redirects

Achtung Falle!
Benutzt man persistente Objekte in PHP, die ungefähr so aufgebaut sind, wie hier beschrieben.

class User
{
public function __construct(){}

// save object to session variable
public function __destruct()
{
   $_SESSION['user'] = serialize($this);
} 
// factory method
public static function factory()
{
   session_start();
   if(isset($_SESSION['user']) === TRUE)
   {
      return unserialize($_SESSION['user']);
   }
   return new User();
} 
}

Continue reading “Persistente Objekte in PHP und redirects”

Grouping & Sorting in MongoDB

Will man mit PHP und MongoDB soetwas wie “SQL Aggregate Functions” umsetzen muss man sich etwas verbiegen.

MongoDb hat zwar eine group() function, die in etwa SQLs GROUP BY entspricht, allerdings kann man dies nicht kombinieren mit SORT oder LIMIT bzw den sort() und limit() Funktionen, da diese keinen Cursor zurückgibt sondern direkt ein Array.

Will man also sortieren und limitieren muss man sich des Map / Reduce features von MongoDB bedienen.

Continue reading “Grouping & Sorting in MongoDB”