Composer in a Docker Image

This will be a short post and this one is mostly for me so I can easily find this information in the future when I need it again. 🙂

Recently I was containerizing some PHP websites that use Composer. If you are not familiar with Composer but you are working with PHP, you will run across it at some point. Composer is a dependency package manager for PHP. Composer manages (install/update) any required libraries and dependencies needed for your PHP site.

To use Composer you must first declare the libraries and dependencies in a composer.json file in your site directory and then you would run Composer and it will do its magic. For more information on Composer visit: https://getcomposer.org/doc/00-intro.md

Back to my task, I needed to install Composer in the containers I was building and run it to install all the dependencies. I needed these actions in the Dockerfile so it would all happen during the container build. After some research on Composer I was able to pull something together. Here is the syntax that I ended up putting in the Dockerfile:

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Set working directory for composer (Contains the composer.json file)
WORKDIR /var/www/html/sitename

# Run Composer
RUN composer install

Note: I placed the above code at the end of the Dockerfile ensuring Apache, PHP etc was all in place first.

Thanks for reading and happy Containerizing!

Read more

How to find PHP.ini location

One day I was working on a new Drupal site for client. This was on a new server and I had no clue where anything was. I needed to find out what PHP version was running. I could not find this in Plesk for some reason. On Geeklog they had an article with a cool way to track down your PHP version and other information about PHP on a server.

 

Read more

Setup a catch all domain

I needed to setup a catch all for one of my clients domains. This is what I needed to happen:

If user typed in an incorrect sub domain for mydomain.com that did not exist I needed it
to redirect them to www.mydomain.com. 

For example: if they type in notreal.mydomain.com it will send the user
to www.mydomain.com.

Here is what I did to accomplish this: 

Read more