• xmapp
  • RUN Docker using XAMPP

Here is a PHP code snippet that constructs and executes the given Docker run command using PHP's shell_exec function. It assumes that the $contname variable is defined in PHP.

<?php

// Define the container name
$contname = 'navidrome_container'; // You can change this value dynamically

// Build the command
$command = <<<EOD
docker run -d \\
   --name {$contname} \\
   --restart=unless-stopped \\
   --user $(id -u):$(id -g) \\
   -v /opt/navidrome/{$contname}/music:/music \\
   -v /opt/navidrome/{$contname}/data:/data \\
   -e ND_LOGLEVEL=info \\
   deluan/navidrome:latest
EOD;

// Execute the command
$output = shell_exec($command);

// Output the result
echo "<pre>$output</pre>";
?>

⚠️ Important Notes:

  1. Permissions: Make sure the PHP script is run by a user who has permission to execute Docker commands (e.g., part of the docker group).
  2. Security: Never pass unsanitized user input directly into shell commands — that opens up shell injection vulnerabilities.
  3. Web server context: If you're running this via a web browser and Apache/Nginx, ensure the web server user (e.g., www-data) can access Docker.

Let me know if you'd like to parameterize it more or run it in the background safely!

To access your Docker container running at port 4533 through XAMPP's Apache server on port 80 using a proxy, you'll need to:

  1. Enable required Apache modules.
  2. Modify httpd-vhosts.conf to define the virtual host and proxy configuration.
  3. (Optional) Modify httpd-ssl.conf if you want to serve via HTTPS.
  4. Restart Apache via XAMPP.
  5. Use PHP to automate the editing of httpd-vhosts.conf.

✅ Final Goal:

Access Docker container (running at localhost:4533) via:

http://localhost/navidrome

✅ Step-by-Step Instructions


✅ Step 1: Enable Apache proxy modules in XAMPP

Edit httpd.conf (usually in C:\xampp\apache\conf\httpd.conf) and make sure these lines are uncommented:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule rewrite_module modules/mod_rewrite.so

✅ Step 2: Update httpd-vhosts.conf

Edit C:\xampp\apache\conf\extra\httpd-vhosts.conf and add this VirtualHost configuration:

<VirtualHost *:80>
    ServerName localhost

    # Proxy path for navidrome
    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    <Proxy *>
        Require all granted
    </Proxy>

    # Proxy /navidrome path to the container's port
    ProxyPass "/navidrome" "http://localhost:4533"
    ProxyPassReverse "/navidrome" "http://localhost:4533"

    # Optional: redirect root if needed
    # RedirectMatch ^/$ /navidrome/
</VirtualHost>

✅ Step 3: Restart Apache from XAMPP Control Panel

After editing, restart Apache to apply changes.


✅ Step 4: Write PHP Code to Automate Step 2

This PHP code appends the required virtual host config to httpd-vhosts.conf.

<?php

$vhostFile = 'C:/xampp/apache/conf/extra/httpd-vhosts.conf';

// Define the configuration block
$proxyConfig = <<<EOD

# Auto-generated VirtualHost for Navidrome Docker Proxy
<VirtualHost *:80>
    ServerName localhost

    ProxyRequests Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    <Proxy *>
        Require all granted
    </Proxy>

    ProxyPass "/navidrome" "http://localhost:4533"
    ProxyPassReverse "/navidrome" "http://localhost:4533"
</VirtualHost>

EOD;

// Append to the vhosts file
if (file_put_contents($vhostFile, $proxyConfig, FILE_APPEND | LOCK_EX)) {
    echo "Proxy configuration successfully added to httpd-vhosts.conf.\n";
    echo "Please restart Apache from XAMPP to apply changes.";
} else {
    echo "Failed to write proxy config. Please check file permissions.";
}
?>

✅ Step 5: Access via Browser

After restarting Apache, open:

http://localhost/navidrome

This should reverse-proxy to your Docker container running Navidrome at localhost:4533.


🔒 (Optional) Step 6: Update httpd-ssl.conf for HTTPS

If you want to enable https://localhost/navidrome, let me know and I’ll give you a secured config using httpd-ssl.conf.


Would you like a button in your PHP app that automatically writes the config and restarts Apache as well (if running on Windows)?