Git Product home page Git Product logo

php-apache-container's Introduction

PHP Apache Container (Built with Ansible)

CI Docker pulls

This project is composed of three main parts:

  • Ansible project: This project is maintained on GitHub: geerlingguy/php-apache-container. Please file issues, support requests, etc. against this GitHub repository.
  • Docker Hub Image: If you just want to use the geerlingguy/php-apache Docker image in your project, you can pull it from Docker Hub.
  • Ansible Role: If you need a flexible Ansible role that's compatible with both traditional servers and containerized builds, check out geerlingguy.php on Ansible Galaxy. (This is the Ansible role that does the bulk of the work in managing the PHP container.)

Versions

Currently maintained versions include:

  • 8.1, 8.1.x, latest: PHP 8.1.x
  • 7.4, 7.4.x: PHP 7.4.x
  • 7.3, 7.3.x: PHP 7.3.x
  • 7.2, 7.2.x: PHP 7.2.x
  • 7.1, 7.1.x: PHP 7.1.x

Standalone Usage

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:

docker run -d --name=php-apache -p 80:80 geerlingguy/php-apache:latest /usr/sbin/apache2ctl -D FOREGROUND

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:

version: "3"

services:
  php-apache:
    image: geerlingguy/php-apache:latest
    container_name: php-apache
    ports:
      - "80:80"
    restart: always
    # See 'Custom PHP codebase' for instructions for volumes.
    volumes: []

Then run:

docker-compose up -d

Now you should be able to access the default home page at http://localhost/.

Custom PHP codebase

If you have a codebase inside the folder web, mount it as a volume like -v ./web:/var/www/html:rw,delegated.

Or, if using a Docker Compose file:

services:
  myapp:
    ...
    volumes:
      - ./web:/var/www/html:rw,delegated

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.

If you want to run multiple webroots, or need to further customize the Apache VirtualHost definitions, you can mount a config file over the existing one in the container, e.g.:

services:
  myapp:
    ...
    volumes:
      - ./web:/var/www/html:rw,delegated
      - ./virtualhosts.conf:/etc/apache2/sites-enabled/vhosts.conf:rw

Similarly, you can mount a PHP config file to the path /etc/php/8.1/apache2/php.ini (substitute whatever PHP version you're currently using in that path).

Management with Ansible

Prerequisites

Before using this project to build and maintain PHP images for Docker, you need to have the following installed:

Build the image

First, install Ansible role requirements:

ansible-galaxy install -r requirements.yml

Then, make sure Docker is running, and run the playbook to build the container:

ansible-playbook --extra-vars="@vars/8.1.yml" main.yml

(Substitute whatever supported PHP version you desire in the vars path) Once the image is built, you can run docker images to see the php-apache image that was generated.

Note: If you get an error like Failed to import docker, run pip install docker.

Push the image to Docker Hub

See the .github/workflows/build.yml file in this repository for how it pushes all the tagged images automatically on any commit to the master branch.

License

MIT / BSD

Author Information

This container build was created in 2018 by Jeff Geerling, author of Ansible for DevOps.

php-apache-container's People

Contributors

geerlingguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php-apache-container's Issues

Also push 'exact version' tags to Docker Hub

in #2, I started pushing builds like 7.2, 7.2.x, and latest to Docker Hub... but it would be nice if I could also tag the latest release, e.g. 7.2.10, and release that tag to Docker Hub. That way I can lock in specific PHP versions in my downstream infrastructure.

Support all maintained major PHP versions

The geerlingguy.php-versions role already does this... but basically, add a vars file for each major version, 7.2, 7.1, 7.0, and 5.6, and then push up images for each.

Automatically push specific version tags via Travis CI

I don't want to have to manually push specific PHP version tags (e.g. 5.6.32 or 7.3.1), so I need to write a tiny bit of extra automation in the .travis.yml file which:

  1. Runs the built image:
docker run --rm image/name:latest ...
  1. Gets the PHP version like:
# This seems simplest:
php_version=$(php -r "echo PHP_VERSION;")

# Or this also works...
php_version=$(php -r 'echo phpversion();')
  1. Tags the image with that version and pushes that tag too.

Automatically push new builds to Docker Hub via Travis CI

Need to see what's required to do this... basically need to store a token or secret in Travis CI, then also build each major version (right now it just builds the default—but see #1 for support for all PHP versions), and on master branch commits, push everything to Docker Hub.

Enabling SSL without certs on the build machine.

Good Day,
I am using this playbook to create a docker container and I am using the other geerlingguy roles that it pulls in. (-apache, -php for example) and I am struggling with ssl certs. I want to enable SSL in my container but I am using a docker build machine and the certificates are not on this machine. Even if they were I am not sure how to expose them to the playbook so that the apache config file test is successful.

Thank you.

Builds failing due to Ansible 2.6.0 docker library changes

See:

Specifically, getting the error with the docker-py library:

TASK [Create the Docker container.] ********************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: create_host_config() got an unexpected keyword argument 'init'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_7JqCjU/ansible_module_docker_container.py\", line 2081, in <module>\n    main()\n  File \"/tmp/ansible_7JqCjU/ansible_module_docker_container.py\", line 2076, in main\n    cm = ContainerManager(client)\n  File \"/tmp/ansible_7JqCjU/ansible_module_docker_container.py\", line 1703, in __init__\n    self.present(state)\n  File \"/tmp/ansible_7JqCjU/ansible_module_docker_container.py\", line 1723, in present\n    new_container = self.container_create(self.parameters.image, self.parameters.create_parameters)\n  File \"/tmp/ansible_7JqCjU/ansible_module_docker_container.py\", line 825, in create_parameters\n    host_config=self._host_config(),\n  File \"/tmp/ansible_7JqCjU/ansible_module_docker_container.py\", line 931, in _host_config\n    return self.client.create_host_config(**params)\n  File \"/home/travis/virtualenv/python2.7.14/lib/python2.7/site-packages/docker/api/container.py\", line 157, in create_host_config\n    return utils.create_host_config(*args, **kwargs)\nTypeError: create_host_config() got an unexpected keyword argument 'init'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}

Failed build: https://travis-ci.org/geerlingguy/php-apache-container/jobs/401114860#L560-L562

CI builds failing

TASK [Make the latest version of the base image available locally.] ************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on fv-az129-444's Python /opt/hostedtoolcache/Python/3.9.5/x64/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named 'six'"}

It seems the problem could be related to the latest Docker pip release (5.0.0) requiring at least Python 3.6. But could be something else. A number of my container image build CI jobs started failing...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.