This guide show how to install [phpMyAdmin](https://docs.phpmyadmin.net/en/latest/intro.html) on Cloud Run. You can use phpMyAdmin to administer Cloud SQL over the web.

<br />

You will find this tutorial helpful if you:

- Host applications on Cloud Run.
- Use [Cloud SQL](https://docs.cloud.google.com/sql/docs.md.txt) 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:

- [Cloud Run](https://cloud.google.com/run/pricing)
- [Cloud SQL](https://cloud.google.com/sql/pricing)

To generate a cost estimate based on your projected usage, use the [Pricing Calculator](https://cloud.google.com/products/calculator).
New Cloud Platform users might be eligible for a Google Cloud [free trial](https://cloud.google.com/free).

<br />

## Before you begin

1. Create a [Cloud SQL
   Second Generation instance](https://docs.cloud.google.com/sql/docs/mysql/create-instance#create-2nd-gen) with a [private IP](https://docs.cloud.google.com/sql/docs/mysql/configure-private-ip).
2. Create a [database user](https://docs.cloud.google.com/sql/docs/mysql/create-manage-users.md.txt#creating).

## Create a service using the phpMyAdmin image

### Console

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

   [Go to Cloud Run](https://console.cloud.google.com/run)
2. Select **Create service**.

   1. In the **Container image** URL field, enter `phpmyadmin`. Cloud Run pulls the image from the public [Docker Hub](https://hub.docker.com/_/phpmyadmin).
   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.

      > [!NOTE]
      > **Note:** You can also use a Serverless VPC Access instead of routing traffic directly to a VPC. In the [comparison table](https://docs.cloud.google.com/run/docs/configuring/connecting-vpc.md.txt#comparison-table), learn the difference between the two ways.

## Connect to the service using Cloud Run proxy

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

> [!IMPORTANT]
> **Important:** We don't recommend exposing phpMyAdmin to the public internet directly. If you prefer an alternative to the local proxy, you can configure [IAP](https://docs.cloud.google.com/iap/docs/enabling-cloud-run.md.txt) to enforce user authentication.

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

   ```sql
   gcloud run services proxy phpmyadmin --port=8080
   ```

   If [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud.md.txt) 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](https://console.cloud.google.com/logs) in the [Google Cloud console](https://console.cloud.google.com/).

## 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.

<br />

### Delete the project


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

To delete the project:

> [!CAUTION]
> **Caution** : Deleting a project has the following effects:
>
> - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
> - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.
>
>
> If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects
> can help you avoid exceeding project quota limits.

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

   [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)
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.

<br />

<br />

### Delete instances


To delete a Cloud SQL instance:

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

   [Go to Instances](https://console.cloud.google.com/sql/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.

<br />

<br />

## What's next

- [Learn more about phpMyAdmin](http://www.phpmyadmin.net/home_page/docs.php).
- Explore reference architectures, diagrams, and best practices about Google Cloud. Take a look at our [Cloud Architecture Center](https://docs.cloud.google.com/architecture).