Enabling PHP-FPM and HTTP/2 on Apache2

Something I’ve wanting to do a long time but never got around to: enabling HTTP/2 on my Apache webserver. HTTP/2 has been around for over 8 years now. It is supposed to be faster and cooler, and by now almost every browser out there supports it.

In my case it also meant switching setups for Apache and PHP. Apache’s http2-module doesn’t run on mpm_prefork; but mpm_prefork is required by Apache’s PHP module. (MPM: multiprocessing module, the way Apache receives and processes requests. Prefork is one MPM type, event and worker are others.) So I needed to switch from mpm_prefork to mpm_event and from mod_php to PHP-FPM.

Thanks to the handy commands a2enmod and a2dismod commands changing the setup is quite easy.

First install PHP-FPM:

sudo apt install php7.4-fpm

(yes I know that is a very old PHP version …)

Then disable and enable modules:

sudo a2dismod php7.4 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi http2

Make sure to also enable the setenvif module if you hadn’t already done that. I ran sudo a2enconf php7.4-fpm as well, not sure whether that is required though.

Finally, restart Apache:

sudo service apache2 restart

I tried this first on a Debian server running on Windows WSL, and it worked perfectly well. I was slightly worried that “the new Apache” might run as a different user, but that turned out not be the case (saving me from chown-ing many, many files). Then, on the server you’re looking at I backed-up the /etc/apache2 folder and ran the same commands. This time restarting Apache threw an error:

Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

None of the suggestions provided anything useful, so I had to quickly roll back the changes.

sudo a2dismod mpm_event proxy_fcgi http2
sudo a2enmod php7.4 mpm_prefork
sudo service apache2 restart

Time to scan the logs. There was nothing in Apache’s own error.log, but fortunately syslog came to the rescue:

Syntax error on line 8 of /etc/apache2/sites-enabled/some-site.conf:
Invalid command 'php_admin_value', perhaps misspelled or defined by a module not included in the server configuration.

Turns out that php_admin_value, php_value and php_flag are only recognized by mod_php, not by PHP-FPM. I was using some of them for setting things like upload_max_filesize and post_max_size, in vhosts and in .htaccess. But PHP-FPM does support .user.ini-files. So I created a bunch of such files and put them in the web roots of the affected sites. For a smooth transition I put the old vhost/htaccess commands in conditional blocks, like this:

<IfModule mod_php7.c>
    php_value post_max_size 9M
    php_value upload_max_filesize 8M

Disable and enable the modules again:

sudo a2dismod php7.4 mpm_prefork
sudo a2enmod mpm_event proxy_fcgi http2

This time I tested the new config with sudo apachectl -t. “Syntax OK”! So, fingers crossed:

sudo service apache2 restart


Restoring Notepad++ in the right-click context menu “New” menu

It seems that everytime Windows is updated, the option to create a new plain text file with Notepad++ gets removed from the context menu in Explorer. Easy fix:

  • find an existing .txt-file in Explorer
  • right-click -> Open with -> Choose different app
  • from the list, select Notepad++ and press Always

That’s it! ymmv.

Gimp EZ Perspective

Posting this handy Gimp plugin here, just in case it drops off the Internet. It was licensed under CC0 by the original author.

Download ez-perspective.py here.

Installation: copy the Python script into your plugins folder (location can be found under Preferences > Folders > Plugins) and restart Gimp. There should now be a new menu item under Filters > Distort.

Description, taken from the file:

EZ Perspective

A Gimp plug-in to easily change the perspective in an image, just like it says on the tin.

Particularly useful for correcting photographs, but can also be used to add a Dutch angle to any image.

Provides 3 parameters to change up/down (tilt, pitch), left/right (swing, yaw), and rotation (twist, roll).

Please use:

  • after correcting lens distortion (barrel distortion, vignetting, lateral chromatic aberration), as these depend on the lens, on the shot as taken

  • before cropping, as this changes the shape of the image, and will likely warrant cropping afterwards

Set-Cookie in .htaccess kills PHP session

Just spent too much time on finding out why sessions didn’t work on a particular site. To be precise: the PHP session cookie was not sent.

Turned out that there was a line in the site’s .htaccess that also set a temporary cookie:

<FilesMatch "\.php$">
Header set Set-Cookie "myCookie=1; path=/;"

All was fine when I changed set into add:

<FilesMatch "\.php$">
Header add Set-Cookie "myCookie=1; path=/;"


Use Twitter from the command line on Ubuntu bash for Windows

I read this (“Using Twitter From the Command Line Is Actually Really Fun“) and I wanted it too. Not in an ordinary Linux box but in the Ubuntu bash on Windows 10. Turned out that I needed to add a graphical browser to be able to log into Twitter and authenticate the Rainbow Stream app.

It isn’t hard to do, but I thought I’d write it down anyway.

Assuming that bash is already installed, run these commands. There will be lots of notices and messages…

  1. sudo apt-get install python3-pip (skip this if you already have pip; it is only required for the third step)
  2. sudo apt-get install libsqlite3-dev libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev
  3. sudo pip3 install rainbowstream
  4. sudo apt-get install firefox (or any other web browser)
  5. in Windows, install an X server. I followed this article and installed the Xming X Server for Windows.
  6. back in bash: export DISPLAY=:0
  7. firefox & (should open FF in an X window)

Hit enter to return to the prompt.

Now run rainbowstream and authenticate the app in the browser. Enter the pin Twitter returns into rainbowstream and it should be up and running.

Xcode – localize iOS project strings

Writing this down as I usually forget how to localize text in MyProject-Info.plist.

  • Left hand column, select Resources folder

  • Right click > New file… > Resource, Strings File

  • Save file as InfoPlist.strings

  • Open the file in the editor, enter strings to localize, like

    NSLocationWhenInUseUsageDescription = “Show your location on the map”;

  • Save file

  • In right hand column, click Localize button (makes the file localizable)

  • Now go to the project’s Localizations settings (under Project > Info)

  • Click Add language and select InfoPlist.strings

  • In the left hand column, there now are two entries under InfoPlist.strings. Edit as you please.

Works in Xcode 7 and 8.

Mysterious ‘headers already sent’ while handling php://input stream

A script that handled a php://input stream exited rather unexpectedly when it called session_start(). I had ‘track_errors’ enabled, so there was a message in $php_errormsg saying that headers had already been sent. But there was no file name or line number.

Continue reading Mysterious ‘headers already sent’ while handling php://input stream

Studio without Server

I’ve been using Zend Studio for many years now and think that it is a great IDE for building sites with PHP and JavaScript. IIRC I started with ZS 5; until this week I used version 9. I also ran a free Zend Server package, including Apache 2.2 and PHP 5.4. All this on an ordinary Windows 7 machine.

As my production web server now runs on Apache 2.4 and PHP 5.6, an upgrade on the dev machine seemed appropriate. Also, Zend recently launched Studio 13, with support for PHP 5.6 and even PHP 7. I decided to upgrade everything at once.

Continue reading Studio without Server