Currently Browsing: Apache

Install amqp-ext PHP extension to Apache in Docker

I wanted to add RabbitMQ support to my PHP app and prefer to use the PECL amqp package:

This extension can communicate with any AMQP spec 0-9-1 compatible server, such as RabbitMQ, OpenAMQP and Qpid, giving you the ability to create and delete exchanges and queues, as well as publish to any exchange and consume from any queue.

Using pecl install won’t install all the dependencies. There are various options to how to solve this including fetching from Git repos, however this is the one that worked for me and seemed the most straight-forward (ymmv). See below for code used in a Dockerfile with base image FROM php:7.1.14-apache which uses debian:jessie, so the native commands should work in similar Debian/Ubuntu linux distros.

RUN curl http://in.archive.ubuntu.com/ubuntu/ubuntu/pool/universe/libr/librabbitmq/librabbitmq4_0.8.0-1_amd64.deb -o librabbitmq4_0.8.0-1_amd64.deb
RUN curl http://in.archive.ubuntu.com/ubuntu/ubuntu/pool/universe/libr/librabbitmq/librabbitmq-dev_0.8.0-1_amd64.deb -o librabbitmq-dev_0.8.0-1_amd64.deb
RUN dpkg -i librabbitmq4_0.8.0-1_amd64.deb
RUN dpkg -i librabbitmq-dev_0.8.0-1_amd64.deb
RUN pecl install amqp-1.9.3 && docker-php-ext-enable amqp

Note if you do use this in a Dockerfile, you can combine some of the statements to optimize layers. You also may need to update the lib version if it’s updated or if you change the PECL version to install.

Docker Compose LAMP demo project

Project showing a basic LAMP set-up using a networked multi-container configuration.

docker-compose.yml

version: '2'
services:
  php:
     image: phpmyadmin/phpmyadmin
     links:
       - mysql:db
     depends_on:
       - mysql

  mysql:
    image: k0st/alpine-mariadb
    volumes:
      - ./data/mysql:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=mydb
      - MYSQL_USER=myuser
      - MYSQL_PASSWORD=mypass 

  nginx:
    image: nginx:stable-alpine
    ports:
      - "81:80"
    volumes:
      - ./nginx/log:/var/log/nginx
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/files:/var/www/nginx:ro
    depends_on:
      - php

nginx/nginx.conf

worker_processes  1;
events {
  worker_connections  1024;
}
http {
  sendfile  off;
  server {
    listen 80;
 
    location / {
      proxy_pass  http://php;
      proxy_set_header Host $host;
      proxy_redirect     off;
    }
  }
}

The nginx config is simplified but that should work for testing — basically all it’s doing is proxying the php app. Maps to port 81 to avoid conflicts on the host. (Note this is just a rough demo, would need to be fleshed out for any use more than that.)

Regarding linking, you can see that if you run: docker-compose exec mysql ping -c2 nginx to ping from the mysql container to the nginx container, you will succeed even though there are no links specified between these containers. Docker Compose will maintain those links in the default network for you.

If you like, you can fetch a working version from this repo and run docker-compose up, and (assuming you don’t have anything running on port 81) see results on http://localhost:81/ (or whatever your corresponding hostname/IP is).

For more info on Docker Compose networking see: https://docs.docker.com/compose/networking/

By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.

Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate – by default, any service can reach any other service at that service’s name.

PHP 7 from Docker container complete with Yii 2.0

Pretty cool, a PHP 7.0 (RC4) with Apache environment on Mac from scratch in a few minutes via Docker container:

https://gist.github.com/lgelfan/b4921393d41f345a15e9

Includes installation for minimal requirements to support Yii 2.0

Uses Vagrant + VirtualBox on Mac (or similar) or instead you can use any existing Docker host.

Yum lock version

Want to make sure a specific package (e.g., apache, php, etc.) don’t accidentally get updated via Yum, you can do:

yum install yum-versionlock
yum versionlock packagename

e.g.:

yum versionlock php-5.4*
yum versionlock list

to remove specific package:
yum versionlock delete php-5.4*

to remove ALL packages:
yum versionlock clear

Show Apache / httpd memory usage and process size

ps -ylC httpd | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Proccess Size (MB): "x/((y-1)*1024)}'

thanks S.G. Vulcan

« Previous Entries