Skip to content

Tag: php

Containerize old PHP/Laravel application with Apache and SSL

Recently I migrated my websites and some applications from 7 years old server to a new server. Then I just realize some PHP application is not working on the latest PHP 7.4, thus I have to create a simple docker container to run the app.

Specifically, it’s Invoice Ninja v3.4.1.
This application was running on my server for more than 5 years.
Because I’m too lazy to upgrade to the latest version manually, so I think letting it run in a container with a specific PHP version will be good enough for me.

Following is my Dockerfile:

# use any php version as u need
FROM php:7.0.33-apache

# install any php extension as u need
RUN docker-php-ext-install pdo_mysql mysql

# install ssl-cert for generate self-signed cert
RUN apt-get update && apt-get install -y ssl-cert

# enable apache2 mod
RUN a2enmod rewrite
RUN a2enmod ssl

# simple virtualhost definition
RUN echo '\n\
<VirtualHost *:443>\n\
  <Directory /srv>\n\
    Options Indexes FollowSymLinks\n\
    AllowOverride All\n\
    Require all granted\n\
  </Directory>\n\
  DocumentRoot /srv/public \n\
  SSLEngine on \n\
  SSLCertificateFile  /etc/ssl/certs/ssl-cert-snakeoil.pem \n\
  SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key \n\
</VirtualHost>\n'\
> /etc/apache2/sites-available/000-default.conf

WORKDIR /srv

CMD ["apache2-foreground"]

With this Dockerfile:
1. install PHP extension to run the applications.
2. it has a self-signed certificate to enable simple SSL.
3. it allows us to mount any kind of PHP application and use it immediately.

To run the application with this Dockerfile:
1. Put the Dockerfile in your application root directory.

2. Build the image:
docker build -t YOUR-APPLICATION-IMAGE:custom .

3. Run the container with the image and mount the application directory to container’s /srv:
docker run --rm --name CONTAINER_NAME -v /path/to/your/application YOUR-APPLICATION-IMAGE:custom

That’s all~
With this trick, you should be able to run any web applications that require PHP version less than 7.4

Leave a Comment

Install PHP Xdebug on M1 Macbook Pro

Installing Xdebug on M1 MacBook Pro can be very tricky due to the CPU architecture changed.

This post will show how I install it on my machine:

  1. Make sure you install ur PHP through brew. For me, I have PHP v7.4.15 and perl v5.30.2 installed
  2. Install Xdebug with perl:
    arch -arm64 sudo pecl uninstall xdebug
  3. Locate the Xdebug path in your system. For me, it’s installed on /opt/homebrew/Cellar/[email protected]/7.4.15_1/pecl/20190902/xdebug.so
  4. Make sure xdebug.so is loaded correctly in php.ini. You can check the following block.
zend_extension="/opt/homebrew/Cellar/[email protected]/7.4.15_1/pecl/20190902/xdebug.so"
xdebug.mode=debug
xdebug.client_host=localhost
xdebug.client_port=9000

DONE~
You may start using Xdebug to debug ur PHP application. =)

1 Comment