Use phpMyAdmin with Cloud SQL on Cloud Run


This guide show how to install phpMyAdmin on Cloud Run. You can use phpMyAdmin to administer Cloud SQL over the web.

You will find this tutorial helpful if you:

  • Host applications on Cloud Run.
  • Use Cloud SQL as your database.
  • Want to use phpMyAdmin as an interface for MySQL or prefer a web interface for database administration.

Objectives

  • Learn how to deploy phpMyAdmin on Cloud Run.

Costs

This tutorial uses billable components of Google Cloud, including:

To generate a cost estimate based on your projected usage, use the Pricing Calculator. New Cloud Platform users might be eligible for a Google Cloud free trial.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Install the Google Cloud CLI.
  5. To initialize the gcloud CLI, run the following command:

    gcloud init
  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  7. Make sure that billing is enabled for your Google Cloud project.

  8. Install the Google Cloud CLI.
  9. To initialize the gcloud CLI, run the following command:

    gcloud init
  10. Create a Cloud SQL Second Generation instance with a private IP.
  11. Create a database user.

Create a service using the phpMyAdmin image

Console

  1. In the Google Cloud console, go to Cloud Run:

    Go to Cloud Run

  2. Select Create service.

    1. In the Container image URL field, enter phpmyadmin. Cloud Run pulls the image from the public Docker Hub.
    2. In the Service name field, enter phpmyadmin.
    3. Check Require authentication.
    4. Click Container(s), volumes, networking, security to set the following options:
      1. In the Port field, enter 80 for the value of the container port.
      2. In Environment variables, add PMA_HOST and set the value to be the internal IP address of the Cloud SQL instance.
    5. In Networking, select Connect to a VPC for outbound traffic and Send traffic directly to a VPC. Choose the same network as the Cloud SQL instance.

Connect to the service using Cloud Run proxy

To securely access the IAM-protected service, use the Cloud Run developer proxy.

  1. To start the proxy on the previously created service, use the following command:

    gcloud run services proxy phpmyadmin --port=8080
    

    If gcloud CLI prompts you to install the cloud-run-proxy components, then enter Y.

  2. To test the setup, enter the URL and port number (for example, http://127.0.0.1:8080/), and then with the username (admin name) and password. Since you're using the local Cloud Run developer proxy to access the service securely, you might see an error message, which can be ignored: There is a mismatch between HTTPS indicated on the server and client.

Troubleshoot

To obtain information about Cloud Run errors, access the Cloud Run logs in the Google Cloud console.

Clean up

After you finish the tutorial, you can clean up the resources that you created so that they stop using quota and incurring charges. The following sections describe how to delete or turn off these resources.

Delete the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Delete instances

To delete a Cloud SQL instance:

  1. In the Google Cloud console, go to the Instances page.

    Go to Instances

  2. Click the name of the SQL instance you that want to delete.
  3. To delete the instance, click Delete, and then follow the instructions.

What's next