Search code examples
phpmysqldockerhttp-status-code-500

Docker-compose (CakePHP 2x and MySQL) throws PHP Fatal error


Whilst attempting to run docker-compose this error is found in the var/log/apache2/error.log:

PHP Fatal error:  Uncaught exception 'CacheException' with message 'Cache engine "_cake_core_" is not properly configured. Ensure required extensions are installed, and credentials/permissions are correct' in /var/www/html/lib/Cake/Cache/Cache.php:186\nStack trace:\n#0 /var/www/html/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_')\n#1 /var/www/html/app/Config/core.php(381): Cache::config('_cake_core_', Array)\n#2 /var/www/html/lib/Cake/Core/Configure.php(72): include('/var/www/html...')\n#3 /var/www/html/lib/Cake/bootstrap.php(431): Configure::bootstrap(true)\n#4 /var/www/html/app/webroot/index.php(95): include('/var/www/html...')\n#5 {main}\n  thrown in /var/www/html/lib/Cake/Cache/Cache.php on line 186

Both the containers run when docker-compose is run, but in the web browser at localhost:4001 no page can be seen a http error 500 is thrown

Here is the docker-compose.yml file

version: "3"

services:
  cakephp:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/html/
    ports:
      - 4001:80
    environment:
      DB_DEFAULT_HOST: db
      DB_DEFAULT_LOGIN: root
      DB_DEFAULT_PASSWORD: password
      DB_DEFAULT_DATABASE: database
    depends_on:
      - db

  db:
    image: mysql:5.6
    ports:
      - 4000:3306
    volumes:
      - db-data:/var/lib/mysql
    environment:
      DATABASE_APP_SCHEMA: database
      MYSQL_ROOT_PASSWORD: password
      DATABASE_PASSWORD: password
      DATABASE_USERNAME: root

volumes:
  db-data:
    external: false

I am running on a Ubuntu 18.04 Desktop machine.

The MySQL database is running.


Solution

  • In the container, navigate to var/www/html/app/ and run the following command on your \tmp folder: chmod -R 777 tmp/.

    The reason for the error I described above was due to the \tmp file not being writable.