Rescuing archival WordPress 3.4 websites and databases from the early 2010s presents an immediate runtime compatibility barrier: WordPress 3.4 relies on the deprecated procedural mysql_* extension (mysql_connect, mysql_query) that was permanently removed in PHP 7.0. Furthermore, modern Linux distributions ship with PHP 7 or PHP 8 in their default package repositories and use OpenSSL 1.1+ or 3.0 headers that break legacy PHP 5 source trees.
To boot a WordPress 3.4 installation long enough to upgrade core files to WordPress 3.7 and run a clean WXR XML content export, we can compile PHP 5.6.40 from source against Ubuntu 16.04 (Xenial) development headers with Apache's apxs2 module builder, mysqlnd, and WP-CLI.
Why Compile PHP 5.6.40 Against Ubuntu 16.04?
Ubuntu 16.04 LTS was the transition release that moved default apt packages to PHP 7.0, but it still retained OpenSSL 1.0.2g and libmysqlclient-dev 5.7 in its official repositories. Because PHP 5.6.40 requires OpenSSL 1.0.x APIs to compile --with-openssl without custom C patch sets, Ubuntu 16.04 provides the exact shared library headers needed for a clean multi-core source build.
Step 1: Compiling PHP 5.6.40 & Apache libphp5.so
The build specification below installs the required C compiler toolchain and development headers, downloads the final php-5.6.40.tar.gz source archive, compiles both the CLI binary and the Apache 2 shared module (--with-apxs2=/usr/bin/apxs) with legacy --with-mysql, --with-mysqli=mysqlnd, and --with-pdo-mysql support, and switches Apache to the non-threaded mpm_prefork worker model:
FROM ubuntu:16.04
ENV DEBIAN_FRONTEND=noninteractive
ENV PHP_VERSION=5.6.40
# Install C build toolchain, Apache2 apxs, and library headers
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
apache2 \
apache2-dev \
libxml2-dev \
libcurl4-openssl-dev \
libssl-dev \
libmysqlclient-dev \
libreadline-dev \
libzip-dev \
libbz2-dev \
libjpeg-dev \
libpng-dev \
libxpm-dev \
libfreetype6-dev \
libmcrypt-dev \
libicu-dev \
zlib1g-dev \
libxslt-dev \
libsodium-dev \
libmagickwand-dev \
libpcre3-dev \
curl \
wget \
re2c \
bison \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Fetch and extract the official PHP 5.6.40 source release
RUN wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz && \
tar -xzf php-${PHP_VERSION}.tar.gz && \
rm php-${PHP_VERSION}.tar.gz
WORKDIR /php-${PHP_VERSION}
# Configure and compile PHP 5.6 with legacy mysql, mysqli, and pdo_mysql
RUN ./configure \
--prefix=/usr/local/php5.6 \
--with-apxs2=/usr/bin/apxs \
--enable-maintainer-zts \
--with-mysql \
--with-mysqli=mysqlnd \
--with-pdo-mysql \
--enable-mbstring \
--enable-calendar \
--enable-ctype \
--with-curl \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--enable-ftp \
--with-gd \
--with-gettext \
--with-iconv \
--with-libdir=/usr/lib/x86_64-linux-gnu \
--enable-json \
--with-libxml-dir=/usr \
--with-openssl \
--enable-pcntl \
--with-pcre-dir=/usr \
--enable-pdo \
--enable-phar \
--enable-posix \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-tokenizer \
--enable-xml \
--enable-xmlreader \
--enable-xmlwriter \
--with-xsl \
--enable-opcache \
--enable-zip \
--with-zlib && \
make -j$(nproc) && \
make install
# Symlink the PHP CLI binary into standard PATH
RUN ln -sf /usr/local/php5.6/bin/php /usr/local/bin/php && \
ln -sf /usr/local/php5.6/bin/php /bin/php
# Enable Apache mod_rewrite and MPM Prefork
RUN a2dismod mpm_event mpm_worker && \
a2enmod mpm_prefork rewrite
# Register the compiled PHP5 handler and .htaccess overrides in apache2.conf
RUN echo "AddType application/x-httpd-php .php" >> /etc/apache2/apache2.conf && \
echo "DirectoryIndex index.php index.html" >> /etc/apache2/apache2.conf && \
echo "<Directory /var/www/html>" >> /etc/apache2/apache2.conf && \
echo " AllowOverride All" >> /etc/apache2/apache2.conf && \
echo "</Directory>" >> /etc/apache2/apache2.conf
EXPOSE 80
CMD ["apachectl", "-D", "FOREGROUND"]
Step 2: Layering WP-CLI for Automated Database & WXR Exports
Once the base php56:latest image is built, layering WP-CLI (`wp-cli.phar`) provides command-line automation to inspect plugin states, update site URLs, and export WordPress Extended RSS (WXR) XML dumps without fighting broken legacy admin dashboards:
FROM php56:latest
ENV PATH="/usr/local/bin:/usr/local/php5.6/bin:$PATH"
# Download and verify the WP-CLI Phar archive
RUN curl -fsSLO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
php wp-cli.phar --info && \
chmod +x wp-cli.phar && \
mv wp-cli.phar /usr/local/bin/wp
WORKDIR /var/www/html
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]
Step 3: Orchestrating MySQL 5.7 & Exporting WordPress 3.4 Content
Legacy WordPress 3.4 schemas use zero-date defaults (`0000-00-00 00:00:00` in `wp_posts.post_date_gmt`) that are rejected by strict SQL modes in MySQL 8.0. Pairing our PHP 5.6.40 runtime with MySQL 5.7 allows the archival SQL dump (`init.sql`) to import cleanly:
version: '3.7'
services:
mysql:
image: mysql/mysql-server:5.7.37
environment:
MYSQL_DATABASE: webdesign
MYSQL_USER: wp_legacy
MYSQL_PASSWORD: wp_legacy_password
MYSQL_ROOT_PASSWORD: root_recovery_password
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- "3307:3306"
legacy-php:
depends_on:
- mysql
image: php5.6-apache-wpcli
volumes:
- .:/var/www/html
ports:
- "8088:80"
Upgrading Core from 3.4 to 3.7 for Clean WXR XML Export
With the database online, overlaying the WordPress 3.4 core files with WordPress 3.7 triggers the internal schema migration seamlessly and enables full WXR XML export via WP-CLI (`wp export --dir=/var/www/html/exports --allow-root`), allowing all historical posts, slugs, and timestamps to be migrated into a modern SSR platform.
