{"id":16179128,"url":"https://github.com/jonashackt/slim-php-docker-heroku-mariadb","last_synced_at":"2025-08-01T02:10:05.807Z","repository":{"id":37023632,"uuid":"225399431","full_name":"jonashackt/slim-php-docker-heroku-mariadb","owner":"jonashackt","description":"Example project showing how to run a Slim framework based PHP app in Docker locally \u0026 on Heroku incl. connection to MariaDB","archived":false,"fork":false,"pushed_at":"2025-02-25T06:44:42.000Z","size":1661,"stargazers_count":1,"open_issues_count":9,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T13:46:51.422Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonashackt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-02T14:53:55.000Z","updated_at":"2024-09-30T08:26:06.000Z","dependencies_parsed_at":"2022-09-23T19:00:24.804Z","dependency_job_id":"6157b9f8-4d53-4239-a244-db35a5005782","html_url":"https://github.com/jonashackt/slim-php-docker-heroku-mariadb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fslim-php-docker-heroku-mariadb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fslim-php-docker-heroku-mariadb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fslim-php-docker-heroku-mariadb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fslim-php-docker-heroku-mariadb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonashackt","download_url":"https://codeload.github.com/jonashackt/slim-php-docker-heroku-mariadb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243958082,"owners_count":20374791,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T05:25:32.369Z","updated_at":"2025-03-19T01:30:54.169Z","avatar_url":"https://github.com/jonashackt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slim-php-docker-heroku-mariadb\n[![Build Status](https://travis-ci.org/jonashackt/slim-php-docker-heroku-mariadb.svg?branch=master)](https://travis-ci.org/jonashackt/slim-php-docker-heroku-mariadb)\n[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/jonashackt/slim-php-docker-heroku-mariadb/blob/master/LICENSE)\n[![renovateenabled](https://img.shields.io/badge/renovate-enabled-yellow)](https://renovatebot.com)\n[![Deployed on Heroku](https://img.shields.io/badge/heroku-deployed-blueviolet.svg?logo=heroku\u0026)](https://slim-php-docker-heroku-mariadb.herokuapp.com)\n\nExample project showing how to run a Slim framework based PHP app in Docker locally \u0026amp; on Heroku incl. connection to MariaDB\n\n\n# Prerequisites\n\nInstall the PHP dependency management solution [composer](https://getcomposer.org/):\n\n```\nbrew install composer\n```\n\nInstall a PHP interpreter (see https://de.wikipedia.org/wiki/PHP#Funktionsweise). As PHP uses an interpreter, that is triggered by a webserver (see LAMP stack), it could be tedious to install the myriad of tools on your local machine. Also alternatives like [XAMPP](https://en.wikipedia.org/wiki/XAMPP) seem quite dusty.\n\nSo why not use Docker as the interpreter/webserver runtime? As you may already noticed, a [docker-compose.yml](docker-compose.yml) is present in the root of the project. Start it with \n\n```\ndocker-compose up -d\n```\n\nIf you have IntelliJ and want to run PHP Unit tests, install the [PHP Docker](https://plugins.jetbrains.com/plugin/8595-php-docker/) plugin.\nThen be sure to [configure a remote PHP interpreter according to the docs](https://www.jetbrains.com/help/idea/configuring-remote-interpreters.html). Therefore head over to Preferences/Languages \u0026 Frameworks / PHP:\n\n![php-interpreter-preferences](screenshots/php-interpreter-preferences.png)\n\nand configure your Docker Environment and finally the concrete Docker-Compose image:\n\n![php-interpreter-preferences-docker-compose](screenshots/php-interpreter-preferences-docker-compose.png)\n\n# PHP without a clue - how to start\n\nI have to admit, I've never done PHP before. But my students have to, so I need to know what they are talking about. Let's choose a decent PHP webframework like [Slim](https://github.com/slimphp/Slim), which look really nice and easy to start with!\n\nLet's start with PHP and Slim by creating a new app with the help of a skeleton:\n\n```bash\nphp composer.phar create-project slim/slim-skeleton slim-php-docker-heroku-mariadb\n```\n\nNow slim skeleton prepares everything for us: TravisCI config, Docker Compose file, coveralls configuration, composer files, phpunit configuration, tests and application code... Wow!\n\nTo run the application in development, you can run these commands \n\n```bash\ncomposer start\n\n# Or you can use `docker-compose`:\ndocker-compose up -d\n```\n\nAfter that, open `http://localhost:8080` in your browser:\n\n![first-localhost-run](screenshots/first-localhost-run.png)\n\nRun the test suite locally:\n\n```bash\ncomposer test\n```\n\n# Run PHP build with composer on TravisCI\n\nThis one is simple, since the Slim skeleton generates us most of the Travis config already. Just activate the build settings on Travis for this project at [https://travis-ci.org/](https://travis-ci.org/) and have a look into the [.travis.yml] (.travis.yml):\n\n```yaml\nlanguage: php\n\ndist: trusty\n\nmatrix:\n  include:\n  - php: 7.1\n  - php: 7.2\n  - php: 7.3\n  - php: nightly\n\n  allow_failures:\n  - php: nightly\n\nbefore_script:\n- composer require php-coveralls/php-coveralls:^2.1.0\n- composer install -n\n\nscript:\n- vendor/bin/phpunit --coverage-clover clover.xml\n\nafter_success:\n- vendor/bin/php-coveralls --coverage_clover=clover.xml -v\n```\n\nThis will create 3 parallel Travis builds - where all of them install all dependencies with composer and run the phpunit tests. Also a converalls report will be created.\n\n\n# Run Slim PHP on Heroku\n\nHaving a look at https://devcenter.heroku.com/articles/deploying-php, this should be also simple!\n\nFirst add a [Profile](Procfile):\n\n```\nweb: vendor/bin/heroku-php-apache2 public/\n```\n\nHere we can choose from 2 possible webservers: `heroku-php-apache2` or `heroku-php-nginx`.\n\nSince Slim serves the HTML/CSS/JavaScript from the `public` directory, we need to [set it as a document root](https://devcenter.heroku.com/articles/deploying-php#configuring-the-document-root).\n\nNow assuming you already created your Heroku account and installed `heroku CLI` (e.g. via `brew install heroku`), let's create a Heroku PHP app (if you want to specify a name, `heroku create` is not enough):\n\n```\nheroku apps:create slim-php-docker-heroku-mariadb\n```\n\nWith that a Heroku app is already created:\n\n![heroku-app-created](screenshots/heroku-app-created.png)\n\nNow to create a working deploy pipeline, we simply need to connect our Heroku app to our GitHub repository like this:\n\n![heroku-connect-to-github](screenshots/heroku-connect-to-github.png)\n\nand also configure `Automatic Deploys` with the `Wait for CI to pass before deploy` checkbox enabled, so that Heroku will automatically deploy our Slim PHP app every time, we push to our GitHub repository - and all Travis build succeeded.\n\nWith that our app should already be running on Heroku - just have a look at https://slim-php-docker-heroku-mariadb.herokuapp.com/: \n\n![heroku-deployed-app](screenshots/heroku-deployed-app.png)\n\n\n# Add Docker Compose MariaDB\n\nAs we already know, we could also start our Slim PHP application via `docker-compose up -d`, which is configured through the [docker-compose.yml](docker-compose.yml):\n\n```yaml\nversion: '3.7'\n\nservices:\n    slim:\n        image: php:7-alpine\n        working_dir: /var/www\n        command: php -S 0.0.0.0:8080 -t public\n        environment: \n            - DB_HOSTNAME=mariadb\n            - DB_DATABASE=slim_php\n            - DB_USERNAME=slim\n            - DB_PASSWORD=changeme\n        depends_on:\n            - mariadb\n        ports:\n            - 8080:8080\n        networks:\n            - slim-php-network\n        volumes:\n            - .:/var/www\n            - logs:/var/www/logs\n    \n    mariadb:\n        image: mariadb:10.4.10-bionic\n        environment:\n            MYSQL_ROOT_PASSWORD: changeme\n            MYSQL_DATABASE: slim_php\n            MYSQL_USER: slim\n            MYSQL_PASSWORD: changeme\n        ports:\n            - \"3306:3306\"\n        networks:\n            - slim-php-network\n        restart: on-failure\n        volumes:\n            - ./mariadb:/var/lib/mysql\n            # All scripts in docker-entrypoint-initdb.d/ are automatically\n            # executed during container startup\n            - ./database/db.sql:/docker-entrypoint-initdb.d/db.sql\n\nnetworks:\n    slim-php-network:\n\nvolumes:\n    logs:\n        driver: local\n```\n\nAs database data will be placed inside the current directories's `/mariadb`, make sure to add `/mariadb` to your `.gitignore`. \n\nNow get yourself an [Database client like one of those](https://stackoverflow.com/a/34153/4964553), for me I took DBVisualizer and installed it with `brew cask install dbvisualizer`. Then use the credentials from the `docker-compose.yml` and connect your DB client to our Dockerized MariaDB:\n\n![dbvisualizer-connect-to-docker-mariadb](screenshots/dbvisualizer-connect-to-docker-mariadb.png)\n\nIf you want to have a look into our freshly created database `slim_php` and the table `students`, just do it:\n\n![dbvisualizer-show-table-data](screenshots/dbvisualizer-show-table-data.png)\n\n\n# Use the Dockerized MariaDB from Slim PHP\n\ntbd\n\n\n# Add Heroku MariaDB\n\ntbd\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fslim-php-docker-heroku-mariadb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonashackt%2Fslim-php-docker-heroku-mariadb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fslim-php-docker-heroku-mariadb/lists"}