skip to Main Content

I have the following docker compose file:

version: "3.9"

services:
  php:
    image: phpimage
    ports:
      - 80:80
  phpmyadmin:
    image: phpmyadminimage
    ports:
      - "8080:80"
    environment:
      - PMA_HOST=mysql
  mysql:
    image: mysqlimage
    command: mysqld --sql_mode="NO_ENGINE_SUBSTITUTION"

And everything works fine. The one thing that annoys me though is that when I access phpmyadmin through the browser, I need to go to http://localhost:8080.

Is there anyway I can set up an apache rule, so that instead of the above I can simply enter http://localhost/phpmyadmin?

I’ve been messing about with redirects and reverse proxies but not got anything to work yet

Update:- I’ve been trying stuff like this:

<VirtualHost *:80>
  ServerName localhost/phpmyadmin
  ProxyPass / http://phpmyadmin
  ProxyPassReverse / http://phpmyadmin
</VirtualHost>

3

Answers


  1. LocalHost is a default "link" that is configured on your computer that points directly to your own ip 127.0.0.1, and can be configured within your computer’s Hosts file.
    Remembering that every new link you add to point to your machine’s ip will no longer access the internet.

    Follow link to help you.
    https://www.hostinger.com/tutorials/how-to-edit-hosts-file

    Login or Signup to reply.
  2. You have to setup the docker network correctly. See How to reach docker containers by name instead of IP address?

    As already mentioned you have to use the correct hostname based on your docker compose configuration.

    Login or Signup to reply.
  3. The way to do it right is using a Reverse Proxy. As you’ve mentioned in the original question, you’re already trying that but the configuration is wrong.

    ServerName is the hostname where you’ll receiving requests, not a path. So you’ll be listening for requests on the host localhost.

    ProxyPass tells to map a path to an URL, so if you want the path phpmyadmin to return what is hosted on http://localhost:8080, you have to enter the path on the left and the URL on the right. The same with ProxyPassReverse.

    <VirtualHost *:80>
      ServerName localhost
      ProxyPass /phpmyadmin http://localhost:8080
      ProxyPassReverse /phpmyadmin http://localhost:8080
    </VirtualHost>
    

    I’m not sure about ProxyPassReverse (if you need it or not), but try that config and see if it works.

    In case it works and you can access PhpMyAdmin but when you click any link the URL changes to localhost:8080, you’ll need to check if you can configure the URL on PhpMyAdmin config file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search