|
| 1 | +# PHP Apache Container (Built with Ansible) |
| 2 | + |
| 3 | +[](https://travis-ci.org/geerlingguy/php-apache-container) [](https://microbadger.com/images/geerlingguy/php-apache "Get your own image badge on microbadger.com") |
| 4 | + |
| 5 | +This project is in it's early stages. _There will be bugs!_ You may be better served using the [official PHP Docker image](https://hub.docker.com/_/php/) if it meets your requirements. |
| 6 | + |
| 7 | +This project is composed of three main parts: |
| 8 | + |
| 9 | + - **Ansible project**: This project is maintained on GitHub: [geerlingguy/php-apache-container](https://github.com/geerlingguy/php-apache-container). Please file issues, support requests, etc. against this GitHub repository. |
| 10 | + - **Docker Hub Image**: If you just want to use [the `geerlingguy/php-apache` Docker image](https://hub.docker.com/r/geerlingguy/php-apache/) in your project, you can pull it from Docker Hub. |
| 11 | + - **Ansible Role**: If you need a flexible Ansible role that's compatible with both traditional servers and containerized builds, check out [`geerlingguy.php`](https://galaxy.ansible.com/geerlingguy/php/) on Ansible Galaxy. (This is the Ansible role that does the bulk of the work in managing the PHP container.) |
| 12 | + |
| 13 | +## Versions |
| 14 | + |
| 15 | +Currently maintained versions include: |
| 16 | + |
| 17 | + - `7.2`, `7.2.x`, `latest`: PHP 7.2.x |
| 18 | + - `7.1`, `7.1.x`: PHP 7.1.x |
| 19 | + - `7.0`, `7.0.x`: PHP 7.0.x |
| 20 | + - `5.6`, `5.6.x`: PHP 5.6.x |
| 21 | + |
| 22 | +## Standalone Usage |
| 23 | + |
| 24 | +If you want to use the `geerlingguy/php-apache` image from Docker Hub, you don't need to install or use this project at all. You can quickly build a PHP container locally with: |
| 25 | + |
| 26 | + docker run -d --name=php -p 80:80 geerlingguy/php-apache:latest /usr/sbin/apache2ctl -D FOREGROUND |
| 27 | + |
| 28 | +You can also wrap up that configuration in a `Dockerfile` and/or a `docker-compose.yml` file if you want to keep things simple. For example: |
| 29 | + |
| 30 | + ``` |
| 31 | + version: "3" |
| 32 | + |
| 33 | + services: |
| 34 | + php: |
| 35 | + image: geerlingguy/php-apache:latest |
| 36 | + container_name: php-apache |
| 37 | + ports: |
| 38 | + - "80:80" |
| 39 | + restart: always |
| 40 | + # See 'Custom PHP codebase' for instructions for volumes. |
| 41 | + volumes: [] |
| 42 | + command: ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] |
| 43 | + |
| 44 | +Then run: |
| 45 | + |
| 46 | + docker-compose up -d |
| 47 | + |
| 48 | +Now you should be able to access the default home page at `http://localhost/`. |
| 49 | + |
| 50 | +### Custom PHP codebase |
| 51 | + |
| 52 | +If you have a codebase inside the folder `web`, mount it as a volume like `-v ./web:/var/www/html:rw,delegated`. |
| 53 | + |
| 54 | +Or, if using a Docker Compose file: |
| 55 | + |
| 56 | + services: |
| 57 | + myapp: |
| 58 | + ... |
| 59 | + volumes: |
| 60 | + - ./web:/var/www/html:rw,delegated |
| 61 | + |
| 62 | +If you wish to build an image using this image as the base (e.g. for deploying to production), create a Dockerfile and `COPY` the webroot into place so it's part of the image. |
| 63 | + |
| 64 | +## Management with Ansible |
| 65 | + |
| 66 | +### Prerequisites |
| 67 | + |
| 68 | +Before using this project to build and maintain PHP images for Docker, you need to have the following installed: |
| 69 | + |
| 70 | + - [Docker Community Edition](https://docs.docker.com/engine/installation/) (for Mac, Windows, or Linux) |
| 71 | + - [Ansible](http://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) |
| 72 | + |
| 73 | +### Build the image |
| 74 | + |
| 75 | + ansible-playbook main.yml |
| 76 | + |
| 77 | +Once the image is built, you can run `docker images` to see the `TODO` image that was generated. |
| 78 | + |
| 79 | +### Push the image to Docker Hub |
| 80 | + |
| 81 | +Currently, the process for updating this image on Docker Hub is manual. Eventually this will be automated via Travis CI. |
| 82 | + |
| 83 | + 1. Log into Docker Hub on the command line: |
| 84 | + |
| 85 | + docker login --username=geerlingguy |
| 86 | + |
| 87 | + 1. Tag the latest version (only if this is the latest/default version): |
| 88 | + |
| 89 | + docker tag [image id] geerlingguy/php-apache:latest |
| 90 | + |
| 91 | + 1. Tag the Solr major version: |
| 92 | + |
| 93 | + docker tag [image id] geerlingguy/php-apache:7.2 # or 7.1, etc. |
| 94 | + docker tag [image id] geerlingguy/php-apache:7.2.5 # the specific version |
| 95 | + |
| 96 | + 1. Push tags to Docker Hub: |
| 97 | + |
| 98 | + docker push geerlingguy/php-apache:latest # (if this was just tagged) |
| 99 | + docker push geerlingguy/php-apache:7.2 # or 7.1, etc. |
| 100 | + docker push geerlingguy/php-apache:7.2.5 # the specific version |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +MIT / BSD |
| 105 | + |
| 106 | +## Author Information |
| 107 | + |
| 108 | +This container build was created in 2018 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). |
0 commit comments