How to install timezonedb on LSPHP 8.3 with Ubuntu 24 using Docker

#1
I was poking around performance and was advised that timezonedb is missing. Installing it requires lsphp-dev which comes with additional dependencies, which you might not want on a production server. At least I didn't.

It was a nightmare to find an easy solution without installing additional dependencies, as there is no ready to use package. My solution is to use a temporary docker install and openlitespeed image, compile timezonedb, copy it over to the host and then remove docker. Sounds complicated but it's actually straightforward.

Install docker:

Code:
curl -fsSL https://get.docker.com | sudo sh

Pull the docker image:

Code:
docker pull litespeedtech/openlitespeed

Run the container with the -d flag to keep it running in the background:

Code:
docker run -d -v $(pwd):/src --name my-litespeed litespeedtech/openlitespeed tail -f /dev/null

Inside the Docker container, update the package list and install PHP 8.3 along with its development tools:

Code:
apt update
apt install -y lsphp83 lsphp83-dev

Ensure that PHP 8.3 is active:

Code:
php -v

Download and extract the timezonedb extension:

Code:
cd /src
wget https://pecl.php.net/get/timezonedb -O timezonedb.tgz
tar -xzf timezonedb.tgz
cd timezonedb-2024.2/

Run the following commands to compile the extension:

Code:
export PATH=/usr/local/lsws/lsphp83/bin:$PATH
phpize
./configure --with-php-config=/usr/local/lsws/lsphp83/bin/php-config
make
make install

Exit the docker container:

Code:
exit

Copy the timezonedb.so file from the container to your host server:

Code:
docker cp $(docker ps -lq):/usr/local/lsws/lsphp83/lib/php/20230831/timezonedb.so ./

Note, in my example the version date is from 20230831.

On your host system, move the file to the correct PHP extension directory:

Code:
sudo mv timezonedb.so /usr/local/lsws/lsphp83/lib/php/20230831/
sudo chmod 644 /usr/local/lsws/lsphp83/lib/php/20230831/timezonedb.so

Create the configuration file and enable the extension:

Code:
echo "extension=timezonedb.so" | sudo tee /usr/local/lsws/lsphp83/etc/php/8.3/mods-available/timezonedb.ini

Restart OpenLiteSpeed to apply the changes:

Code:
pkill lsphp
systemctl restart lsws

Check that the timezonedb extension is loaded:

Code:
/usr/local/lsws/lsphp83/bin/php -m | grep timezonedb

If you no longer need docker, you can remove it to free up resources:

Code:
sudo apt remove --purge docker-ce docker-ce-cli containerd.io -y
sudo rm -rf /var/lib/docker /etc/docker
1731919083191.png

This was my solution. Please advise on any improvements or if you notice anything wrong.

Kind Regards
 
Last edited:
Top