Docker Tutorial to run any version of Phoenix on any version of PHP

Open to all! Ask other shopowners for help.
Post Reply
User avatar
zipurman
Builder
Posts: 540
Joined: Tue Oct 13, 2020 5:20 pm
Phoenix Version: v
Has thanked: 93 times
Been thanked: 162 times

Docker Tutorial to run any version of Phoenix on any version of PHP

Post by zipurman »

So, if anyone wants to run any version of Phoenix on any version of PHP with very little work on their local machine, here is how I do it. I have been doing this for a while and it is awesome and saves so much time for me. I used to setup a VM or a live server to test these things, but that can take a lot of work.

Ok. So DOCKER is a solution that creates an instance/environment based on some simple configs and runs isolated from your desktop environment, but runs on top of it.

Here are the steps to give this a quick try using Phoenix 1.0.8.0 with PHP 7.3 as an example:
  • Create an Account, Download and Install Docker Software from:
    https://www.docker.com/pricing/ (Most of you can use the Personal version)
  • Create a folder on your computer wherever you want: /path/to/folder/Docker-Phoenix-1-0-8-0/
  • In that folder create the following files (NO NEED TO CHANGE ANY SETTINGS):
    • /path/to/folder/Docker-Phoenix-1-0-8-0/docker-compose.yml

      Code: Select all

      version: '3.8'
      
      services:
        apache1080:
          build:
            context: ./
            dockerfile: php.Dockerfile
          image: arm64v8/php:7.3-apache-buster
          restart: always
          ports:
            - "1080:80"
          volumes:
            - ./:/var/www/html
          depends_on:
            - db1080
          links:
            - db1080
        db1080:
          image: arm64v8/mariadb:latest
          environment:
            MARIADB_ROOT_PASSWORD: phoenix
            MYSQL_ROOT_PASSWORD: phoenix
            MYSQL_DATABASE: phoenix1080
            MYSQL_USER: phoenix
            MYSQL_PASSWORD: phoenix
          ports:
            - "3306:3306"
          volumes:
            - db1080_data:/var/lib/mysql
      volumes:
        db1080_data:
      
    • /path/to/folder/Docker-Phoenix-1-0-8-0/php.Dockerfile

      Code: Select all

      FROM arm64v8/php:7.3-apache-buster
      
      RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
      RUN apt-get update
      RUN apt-get install libzip-dev -y
      RUN apt-get install zip -y
      RUN apt-get install vim -y
      RUN apt-get install sendmail -y
      
      RUN docker-php-ext-install pdo pdo_mysql
      RUN docker-php-ext-install zip
      RUN docker-php-ext-install mysqli
      RUN docker-php-ext-enable mysqli
      RUN docker-php-ext-enable zip
      
    • /path/to/folder/Docker-Phoenix-1-0-8-0/php.ini

      Code: Select all

      ini_set('error_log', 'php://stdout');
      display_errors = On
      log_errors = On
      
    • /path/to/folder/Docker-Phoenix-1-0-8-0/*unzipped phoenix files from download for version 1.0.8.0 so that the main files of the install (index.php, install/, images/, etc) are all in this folder
  • Open your Terminal program for your OS and navigate to /path/to/folder/Docker-Phoenix-1-0-8-0/
  • To start the container run the command:

    Code: Select all

    docker-compose build
    docker-compose up -d
    
  • If above command does not work, you may need to do the following in the Docker Desktop:
    (Docker --> Settings --> Advanced --> change from user to system)
  • You should now be able to go to the following URL. I have set the port to 1080 to reflect the version of Phoenix:
  • http://localhost:1080/
  • When installing use the following settings for the Phoenix Installer:
    • Database Server: db1080
    • Database User: phoenix
    • Database Pass: phoenix
    • Database: phoenix1080
    • Name the Store: Docker Phoenix 1.0.8.0
    • Leave the admin folder named admin
    • I set the admin user/pass to admin/admin in these, only because they are just for testing but that is up to you.
  • Once installed your should be able to access your store and admin:
  • You can tail the logs from the container using the following command in Terminal from the /path/to/folder/Docker-Phoenix-1-0-8-0/ folder:

    Code: Select all

    docker-compose logs -f
  • You can restart the container using:

    Code: Select all

    docker-compose restart
  • To restart/rebuild the container after making changes to docker php.Dockerfile or docker-compose.yml:

    Code: Select all

    docker-compose down
    docker-compose build
    docker-compose up -d
    
  • To stop the container:

    Code: Select all

    docker-compose down
You can run as many containers with as many versions of Phoenix and PHP as you want. Just simply stop the container when you don't need it. Then you can just start it again when you want to test something.

If you want to change the PHP version, you would just edit the image in the docker-compose.yml file and php.Dockerfile mo match and then run the commands above to restart/rebuild.

You can get a list of available images on https://hub.docker.com/search?q=php8 . This can require a bit of learning.

If you guys/gals want to try this out using the above and then provide feedback. I could share a list of zip downloads somewhere on the site that had php.Dockerfile or docker-compose.yml files for various versions of Phoenix and configurations of PHP/MySQL/etc. Some of these took time to work through as different versions of PHP require different versions of images and settings.

Let me know if this is of interest, or not. I'd be glad to help if users find this workable. For me, I use it frequently and I would not want to code without it as I can quickly test code in any environment.

Cool side note. This is not limited to PHP,MySQL,Phoenix ... you can run any image from Docker Hub this way and there are an unlimited supply of images ;)

Hope this helps someone.

Cheers

Zip
zipurman
-----------

Tags:


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply