-1

I'm using Docker Compose to build my first Docker machine. I want setup Docker to have PHP-FPM 7, Nginx and MySQL (Using MariaDB).

Here is my docker-compose.yml

version: '2'
services:
nginx:
image: nginx:latest
ports:
  - "80:80"
volumes:
  - ./nginx/site.conf:/etc/nginx/conf.d/default.conf
  - ./logs/nginx-error.log:/var/log/nginx/error.log
  - ./logs/nginx-access.log:/var/log/nginx/access.log
  - ./public:/usr/share/nginx/html
links:
  - phpfpm

phpfpm:
image: php:7-fpm
volumes:
  - ./public:/usr/share/nginx/html
  - ./logs/log.conf:/usr/local/etc/php-fpm.d/zz-log.conf

mariadb:
image: mariadb
environment:
  MYSQL_ROOT_PASSWORD: admin
  MYSQL_DATABASE: admin
  MYSQL_USER: admin
  MYSQL_PASSWORD: admin
volumes:
 - ./database:/var/lib/mysql

Docker starts up correctly but when I try using mysql_connect to connect to the database in index.php I get the error:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /usr/share/nginx/html/index.php:7 Stack trace: #0 {main} thrown in /usr/share/nginx/html/index.php on line 7

Here is my index.php

<?php
 $username = "admin";
 $password = "admin";
 $hostname = "localhost";

 //connection to the database
 $dbhandle = mysql_connect($hostname, $username, $password)
   or die("Unable to connect to MySQL");
 echo "Connected to MySQL<br>";
 ?>

How can I set up PHP-FPM to use MySQL?

Thanks a lot

James Johnson
  • 311
  • 6
  • 16

1 Answers1

12

Every time you use the mysql_ database extension in new code, a Kitten is strangled somewhere in the world, it is deprecated and has been for years and is gone forever in PHP7.

You will have to install a PHP5.6 version OR better refactor your code to use MYSQLI or PDO

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149