phpmyadmin / docker

Docker container for phpMyAdmin
https://hub.docker.com/_/phpmyadmin
GNU General Public License v3.0
675 stars 455 forks source link

How to get Upload Dir ($cfg['UploadDir']) working using volume to import SQL files ? #312

Closed CedricGoby closed 4 years ago

CedricGoby commented 4 years ago

Hi,

I'm testing phpmyadmin/docker and I'm trying to use this phpmyadmin feature : https://docs.phpmyadmin.net/en/latest/config.html#cfg_UploadDir

The name of the directory where SQL files have been uploaded by other means than phpMyAdmin (for example, ftp). Those files are available under a drop-down box when you click the database or table name, then the Import tab.

I tried this using docker-compose :

But if I open phpmyadmin and go to the import tab I can't see no drop-down box...

drop-down-import-phpmyadmin-docker

Before launching docker-compose and create the container we can have a look into the host file system :

ls -l /home/bob/pma
drwxr-xr-x 2 bob bob 4096 Nov  4 18:14 config

There is only one directory (config), this is where the custom phpmyadmin config is stored.

Then I launch docker-compose and after a few seconds the container is up and running.

Let's have a look into the host again :

ls -l /home/bob/pma/
drwxr-xr-x 2 bob bob 4096 Nov  4 18:14 config
drwxr-xr-x 2 root    root    4096 Nov  4 18:07 ftp

As you can see, the container has created the "ftp" directory as expected.

Then I copy a sql file (short.sql) into the host into "/home/bob/pma/ftp" We can see the file from the host :

ls /home/bob/pma/ftp/
short.sql

Now let's go into the container :

docker exec -it bob-pma /bin/bash

The sql file is in the container too

root@be964bd91b57: ls -l ftp
-rw-r--r-- 1 root root 899 Nov  4 18:07 short.sql

So this sql file should be available from import tab in phpmyadmin, but it's not the case.

Could you please help me ?

Here is my docker-compose file :

version: '3.1'

services:
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    build: .
    container_name: bob-pma
    links:
      - db
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      PMA_ABSOLUTE_URI: https://domain.tld/
      UPLOAD_LIMIT: 3000000000
    volumes: 
      - /home/bob/pma/config/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
      - /home/bob/pma/ftp:/var/www/html/ftp
    restart: always
    ports:
      - 8081:80

The Dockerfile :

RUN mkdir /var/www/html/ftp

The custom phpmyadmin custom file :

cat /home/bob/pma/config/config.user.inc.php 
$cfg['ExecTimeLimit'] = 0;
$cfg['UploadDir'] = '/var/www/html/ftp';

Regards

williamdes commented 4 years ago

Bonjour @CedricGoby

I think it could be permissions related or maybe just that you are missing <?php at the start of your config.user.inc.php file. Let me know what works for you

By the way we have an official docker image so you can use image: phpmyadmin

ibennetch commented 4 years ago

I've looked at this a couple of different ways but can't recreate your problem — provided that I add a <?php to the start of your config.user.inc.php file. Could you confirm whether that line exists?

CedricGoby commented 4 years ago

Hi guys, thank you very much, you're right, the <?php was missing at the start of config.user.inc.php file... Everything works fine now. And thanks for the tip about official docker image. Have a nice day.

kevinpagnat commented 3 years ago

Hi everyone,

It seems that I have exactly the same problem as @CedricGoby but for me, I don't miss the <?php tag at the start of the file and I put a ?>at the end also. Here is my configuration :

Unfortunately, the option to use this SQL file is missing :( Do you have any suggestion for me ?

What's weird if that I tested that solution under Windows and it works well. I just change the path to the folder to be able to use it on the GENTOO but no luck.

Thanks for any advice on this.

williamdes commented 3 years ago

Hi @kevinpagnat Could you paste here some configuration ?

kevinpagnat commented 3 years ago

Hi again,

I just thought about someting this morning and I think I found a start of answer. When I put a do chmod 777 on the config.user.inc.php, then the option to import the SQL file is finally here ! But when I select the file and click Execute, I have a message saying 'Erreur lors du déplacement du fichier envoyé.'

I think it is again a permission error.

Here are my config files:

config.user.inc.php

<?php

$cfg['UploadDir'] = '/etc/phpmyadmin/upload';
$cfg['SaveDir'] = '/etc/phpmyadmin/save';

?>

docker-compose.yml

version: '3.8'
services:
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:5.0.4
    container_name: phpmyadmin
    volumes:
        - ./_param/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php
        - ./_upload:/etc/phpmyadmin/upload
        - ./_save:/etc/phpmyadmin/save
    restart: always
    environment:
       PMA_HOSTS: db-projectplatform, db-eyetracking, db-planneo
    ports:
      - "8000:80"
    networks:
      backend:
        aliases:
          - phpmyadmin

networks:
   backend:
      name: backend-network

Thanks for your help !

kevinpagnat commented 3 years ago

Okay ! Come back with good news. After doing chmod 777 on the 'upload' folder, it works now !

Is that something normal ? Maybe I will need to implement this in a Dockerfile.

williamdes commented 3 years ago

:fr:

You can switch to the phpmyadmin docker image (https://hub.docker.com/_/phpmyadmin) ;)

Is that something normal ? Maybe I will need to implement this in a Dockerfile.

I think this is normal, your users permissions and the container ones are not always the same and that can create such issues

Is everything alright now?

kevinpagnat commented 3 years ago

Yes, perfectly fine now. Thanks for your time.