I'm having problems connecting to my linked mysql container from my php 7.0.1-apache container.
PHP container Dockerfile:
FROM php:7.0.1-apache
# Initialize html and php.ini
COPY src/ /var/www/html/
COPY config/php.ini /usr/local/etc/php/
# Update modules.
RUN apt-get update
docker-compose.yml:
web:
build: .
ports:
- "80:80"
links:
- "db"
volumes:
- "./src/:/var/www/html/"
db:
image: "mysql"
ports:
- "3306:3306"
environment:
- "MYSQL_ROOT_PASSWORD=somepword"
index.php:
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "somepword";
$db = "test_db";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Error log:
PHP Fatal error: Uncaught Error: Class 'mysqli' not found in /var/www/html/index.php:8\nStack trace:\n#0 {main}\n thrown in /var/www/html/index.php on line 8
I'm not sure where I'm going wrong, basically it looks like mysql isn't configured correctly in my PHP container. Any suggestions?