Run Wordpress with docker-compose without using the wordpress image - php

I would like to upgrade a very old wordpress installation. I would like to reproduce the live enviroment locally. For this, I would build my PHP, MySQL via docker compose. However, I have a problem with this. Normally you would take the ready wordpress images for this. But in my case I can't do that because the WP version is not supported in the docker hub or elsewhere. For this reason I would build my docker-compose with the following images: php7.0, apache and MySql. However, I am wondering how to include the PHP modules that wordpress needs in my yaml file. Is there a template I can follow? And is the way I choose here the right one or is there an alternative way?

Docker images are made out of layers. You can take a PHP image from Docker Hub and add onto it. In fact, the official Wordpress image uses the official PHP image as a base.
Create a new Dockerfile.
You can pick a PHP 7 variant as the starting base:
FROM php:7.0-apache
For some extensions, like GD Library (used for making thumbnails) you need to install some dependencies. This image is based on Debian Linux, so you use:
RUN apt-get -y update && apt-get -y install libfreetype6-dev libjpeg62-turbo-dev libpng-dev unzip
Next, you want some PHP extensions like the aforementioned GD Library and MYSQLi. In the official PHP image, there's a utility (see "How to install more PHP extensions") that makes it very simple:
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install mysqli gd exif zip
Now you can build your image:
docker build -t mycustomphpimage:latest .
And run it:
docker run mycustomphpimage:latest
Building the image automatically with CI/CD in Gitlab/Github and deploying custom images to a repository to pull on a server is out of scope for this answer.
You could just build the image on the server itself when deploying. If you don't want to do that, you can also build the image locally and use docker export & docker import.
The Wordpress image for Wordpress installs some extensions, the most critical of these are gd, exif (images), zip (unpacking plugins), mysqli (database). Try to find out what your current production server has installed & add those to the Dockerfile—many will "just work" with docker-php-ext-install and some might be ignorable.
It might also be possible to use an old version of the Wordpress 5.0 image or to use it as a base (FROM wordpress:5-php7.0-apache).
You mentioned that you'd like to do this to upgrade an old install, so the following is not applicable to you, but for the sake of anyone that finds this answer in the future: just because you can run old PHP / Wordpress versions, please don't do that in production and try to upgrade as soon as you can.

Related

How to build a php extensions from tgz file using make?

Background
I use a RedHat machine without root access, no access to the yum packet manager and no Docker support. This is the policy unfortunately at my work.
I have configured Apache and PHP using a tar file in a folder. Also done same for MongoDB, now I try to configure the PHP drivers for MongoDB according to these instructions:
https://docs.mongodb.com/drivers/php/
However I get stuck on the first bullet:
sudo pecl install mongodb
Problem
Do I need PECL? Can the extension be downloaded manually, and added to PHP?
I have tried to download the mongodb extension manually from:
https://pecl.php.net/package/mongodb
How to compile it mongodb.so? I tried to run pecl on a machine where I have root access then I saw it downloaded the mongodb-1.10.0.tgz and run make (in output when installing).
When I unpack the tgz file manually, I am not able to run make. How to use the makefile.frag? How to run make?
Here is a link on how to build mongodb.so:
https://www.php.net/manual/en/mongodb.installation.manual.php
git clone https://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
git submodule update --init
phpize
./configure
make all
sudo make install
You can also unpack the mongodb-1.10.0.tgz file with:
tar -xvf mongodb-1.10.0.tgz
phpize
make all
sudo make install

How can I add helper scripts docker-php-ext-configure, docker-php-ext-install in my docker image

I got detail about some helper scripts but I do not know how to add the support of these scripts in docker file. When I try to use the scripts
Scripts like: docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.
I am getting errors like: /bin/sh: 1: docker-php-ext-configure: not found
I am using
FROM debian:stretch
for build docker container in my docker file.
Same helper scripts are working perfectly fine inn different images like:
FROM php:7.1-apache
FROM php:7.2-apache
If we build Docker file with these images.
php:7.X-apache image is already pre-built with all those scripts included as can be seen here: https://github.com/docker-library/php/tree/master/7.2/stretch/apache
If you need PHP 7.1 image/files you can try to search repository for last version of 7.1 image before it was deprecated.
All of those scripts can be found in this repo:
https://github.com/docker-library/php
Just RUN the scripts within your project directory via Dockerfile, or COPY over to the /usr/bin folder then RUN as you would any other bin script. Just keep in mind those scripts assume an Alpine-esque directory structure so if you're using something like Debian/Ubuntu it may not work out of the box.

PHP installation appears to be missing the MySQL extension which is required by WordPress?

I am currently updating our docker image in Azure.From this image appsvcorg/alpine-php-mysql:0.3 to this leonzhang77/alpine-php-mysql:0.31.
After pasting and save it on container,restart app, when I browse my site (linux.rapidvisa.com , Wordpress 4.9.7,PHP7) that error appeared.MySQL also cannot connect to var/run/mysqld/mysqld.sock.
I tried to fix it. I can see on my phpinfo.php that MySQL/MySQLi is not there or not running.
I am new in this Docker and Azure environment although I managed to enter into SSH and do some tweaking but no luck.
I tried to type sudo apt-get install blah..but command not found.Whenever I typed major commands always -ash: command not found. Can somebody advise me what to do?
i dont know what the exact problem is with your docker construct but your second one is the alpine distribution.
in alpine linux there is an other package manager system.
you have to use apk.
like: apk update or apk add htop

How to force new wordpress docker image?

How do I force docker-compose to update an image?
Given the recent exploits of php (e.g. MS-ISAC ADVISORY NUMBER: 2018-101), I want to update my docker-compose wordpress.
I tried:
docker-compose down && docker-compose build --pull && docker-compose up -d
When I check the version of php though, it lists 7.2.9 rather than 7.2.10
I check it by:
docker exec -it wordpress_wordpress_1 /bin/bash
php -v
I believe that it should list 7.2.10 because when i go to wordpress on docker hub and follow the link for latest, I see that it lists php:7.2-apache, and when I check php on docker hub for 7.2-apache, the Dockerfile lists 7.2.10 (see: L116)
It depends on whether the wordpress image available in docker hub was rebuilt since php was updated.
Your best bet is to rebuild the wordpress image yourself, instead of pulling it from wordpress using wordpress' dockerfile.
Instead of using latest, use the latest tag released. That would force compose to use that version of the image. Or you could also use the --no-cache flag when running docker-compose build to download the image again.
It turns out that even though the changes were merged, dockerhub was still showing that the most recent update was before the merge. (so dockerhub wasn't up to date yet)
https://github.com/docker-library/php#see-a-change-merged-here-that-doesnt-show-up-on-docker-hub-yet

How to compile recent PHP with old MySQL libraries from source?

I have PHP 5.4.26 (FreeBSD); I am trying to use the old MySQL libraries.
Saw this command:
./configure --with-mysql=/path/to/mysql_config
Where do I put this command; it says that it is a compile time decision?
Note you'll need root privileges to do this. Download the source code from php.net. unzip it to a folder.
On a command line in the unzip folder:
./configure --with-mysql=/path/to/mysql_config
make
make test
make install
That will replace your current installation. Note that you will need to carefully research the configure options you want so you don't lose any functionality you currently have.
Just to be complete, here is a tutorial for FreeBSD for using the old libraries and the new ones. Since they are separate.
Using “new” PHP with “old” MySQL passwords
Just in case that page disappears here are the steps for FreeBSD:
# pkg_delete php5-mysql
# cd /usr/ports/databases/php5-mysql
# make config (uncheck support for mysqlnd)
# make install clean

Categories