But first, a slight digression.
A little about the architecture of the PHP CNBs. The previous PHP buildpack has been decomposed into a set of five PHP CNBs, two of which are optional. There are php-cnb, php-composer-cnb, httpd-cnb, nginx-cnb and php-web-cnb.Here's a rough description of each:
- php-cnb provides PHP binaries, that's it.
- php-composer-cnb provides all the functionality related to Composer. It installs and runs Composer.
- httpd-cnb provides Apache Web Server. It is optional.
- nginx-cnb provides Nginx Web Server. It is optional.
- php-web-cnb ties everything together. It generates the configuration for PHP, PHP-FPM, HTTPD and Nginx. It also contains the logic to generate start commands for various types of PHP apps. It can run PHP cli scripts, PHP's bundled web server, PHP-FPM plus HTTPD and PHP-FPM plus Nginx.
On to the show.
If you want to get started there's a little setup that you need to perform.First, `git clone` these repos and optionally check out a release branch.
- https://github.com/cloudfoundry/php-cnb
- https://github.com/cloudfoundry/php-composer-cnb
- https://github.com/cloudfoundry/httpd-cnb
- https://github.com/cloudfoundry/nginx-cnb
- https://github.com/cloudfoundry/php-web-cnb
Third, install Docker if you don't have it already. Make sure it's running too.
Fourth, package up each buildpack that you'd like to use. In each folder that you cloned, you can run `./scripts/package.sh` and it will build the CNB (this requires Golang to be installed). Note the path at which the packaged CNB can be found. You'll need to pass this to the pack cli so it can find the buildpacks. To do that, run `export BUILDPACKS='--buildpack /path/to/buildpack1
If you'd like to build them all at once, you can run the following command from the directory where you cloned all of the repos:
for buildpack in ./php-cnb ./php-composer-cnb ./httpd-cnb ./nginx-cnb ./php-web-cnb; do pushd "$buildpack" && ./scripts/package.sh && popd; done | grep "Creating package in" | awk '{printf "--buildpack %s ", $5}'
This will run the package script for each CNB & then print out a list of the locations for each package. Simply copy the output, then run `export BUILDPACKS='
At this point, you're all set to build some images. To do this, you run `pack build
As `pack build` runs, you'll see each build pack run. If there are any errors the buildpack will fail and tell you what happened. If it succeeds, you'll end up with a docker image that you can run using the command `docker run`. For example, if you have a web app, you can `docker run -it -e PORT=8080 -p 8080:8080
Time for a full example.
Let's say you want to run PHP MyAdmin. The following is a demo of how you could do that. For simplicity sake, it spins up a Percona DB as well. That allows you to have something to connect to within PHP MyAdmin. If you already have a MySQL DB, you can skip that part and point `htdocs/config.inc.php` to your existing server (you could also skip the docker network bits, that just makes it easy to connect to the deployed Percona DB).Download and run the Gist below. This will set everything up for you.
Here are the highlights:
- Line #10 runs Percona
- Lines #15 - #21 download PHP MyAdmin & configure `htdocs/config.inc.php`. If you want to adjust PHP MyAdmin's config, you can do so at this point.
- Lines #24 - #36 adds a php.ini snippet that enables the PHP extensions needed by PHP MyAdmin
- Line #45 runs `pack build`
- Line #48 runs the image that we build with Docker.
Last notes:
- If you want to adjust the PHP MyAdmin config. Run `docker stop php-myadmin`. Edit `htdocs/config.inc.php` then run lines #45 & #48 again.
- If you want to clean up & remove everything run `docker stop php-myadmin test-db` followed by `docker system prune --volumes`. The latter will clean up a bunch of things for you, be careful when running that if you are running other things with Docker.