Currently Browsing: PHP

Docker Compose LAMP demo project

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


version: '2'
     image: phpmyadmin/phpmyadmin
       - mysql:db
       - mysql

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

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


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:

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:

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


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

Post-Mac Mavericks install tasks

stuff I needed to do in order to restore some functionality once updating to Mavericks.

(Uses native apache/php with homebrew supplements, no MAMP or similar packages required.)

here we go:

* update .bash_profile in ~/
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

$ xcode-select --install

* You will then be asked whether you want to install Xcode or 
    the command line developer tools, with the latter being the default.

* install Homebrew:
$ ruby -e "$(curl -fsSL"

* install some utils:
$ brew install bash-completion ssh-copy-id wget

* install mysq
$ brew install mysql --enable-local-infile

# To have launchd start mysql at login:
#    $ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
# Then to load mysql now:
#   $ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# Or, if you don't want/need launchctl, you can just run:
#   $ mysql.server start
#   $ mysql_secure_installation

$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

* php myadmin:
$ brew tap homebrew/dupes
$ brew tap josegonzalez/homebrew-php
$ brew install phpmyadmin

$ sudo cp /usr/local/share/phpmyadmin/ \ 

#  no problems as of yet. was able to compile extensions with brew and link those
#  to the native Apache/PHP setup via php.ini
$ sudo cp /etc/php.ini.default /etc/php.ini
    # and merge previous php.ini
# Zend Opcache seems to be more stable than APC:
$ brew install php54-opcache
    # copy/link .so file and update php.ini

* redis:
$ brew install redis
* phpredis:
$ brew install php54-redis
    # copy/link .so file and update php.ini

* Apache
#  was generally fine, might need to change some perms, particularly if
#  putting web directories under your home folder, e.g., Dropbox.
#  this fixed that: (you could update your groups theoretically to avoid
#  setting the search (+x) permission for "other".
$ sudo chmod -R g+x Dropbox/
$ sudo chmod -R o+x Dropbox/

PHP Redis with socket connection

if you are using Redis on a single server and/or want the web server at the same location to use sockets instead of TCP, update your redis config (redis.conf) to include:

unixsocket /var/run/redis/redis.sock

(you may be able to just uncomment that line to use the default)

You will need to make sure the socket connection has the correct permissions for the apache/php service. You can set the “unixsocketperm” attribute in redis.conf and make sure the socket location is appropriate for your apache/php set-up, or you can add a line in your redis start-up script to update the permissions, something like this:

chown :apache $SOCK && chmod g+w $SOCK

I’m not sure what the best practice is here, but I needed to do one the above to get it to work.

« Previous Entries