在「Container image」(容器映像檔) 網址欄位中,輸入 phpmyadmin。Cloud Run 會從公開的 Docker Hub 提取映像檔。
在「Service name」(服務名稱) 欄位中輸入 phpmyadmin。
請檢查 Require authentication。
按一下「容器、磁碟區、網路與安全性」,設定下列選項:
在「Port」(通訊埠) 欄位中,輸入 80 做為容器通訊埠的值。
在「環境變數」中新增 PMA_HOST,並將值設為 Cloud SQL 執行個體的內部 IP 位址。
在「Networking」(網路) 中,選取「Connect to a VPC for outbound traffic」(連線至虛擬私有雲,以傳出流量) 和「Send traffic directly to a VPC」(直接將流量傳送至虛擬私有雲)。選擇與 Cloud SQL 執行個體相同的網路。
如要測試設定,請輸入網址和通訊埠號碼 (例如 http://127.0.0.1:8080/),
然後輸入使用者名稱 (管理員名稱) 和密碼。由於您使用本機 Cloud Run 開發人員 Proxy 安全地存取服務,因此可能會看到錯誤訊息,但可以忽略:There is a mismatch between HTTPS indicated on the server and client。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[],[],null,["# Use phpMyAdmin with Cloud SQL on Cloud Run\n\n*** ** * ** ***\n\nThis 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.\n\n\u003cbr /\u003e\n\nYou will find this tutorial helpful if you:\n\n- Host applications on Cloud Run.\n- Use [Cloud SQL](/sql/docs) as your database.\n- Want to use phpMyAdmin as an interface for MySQL or prefer a web interface for database administration.\n\nObjectives\n----------\n\n- Learn how to deploy phpMyAdmin on Cloud Run.\n\nCosts\n-----\n\nThis tutorial uses billable components of Google Cloud,\nincluding:\n\n- [Cloud Run](/run/pricing)\n- [Cloud SQL](/sql/pricing)\n\nTo generate a cost estimate based on your projected usage, use the [Pricing Calculator](/products/calculator). \nNew Cloud Platform users might be eligible for a Google Cloud [free trial](/free-trial). \n\n\u003cbr /\u003e\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n [Install](/sdk/docs/install) the [gcloud CLI](/sdk/gcloud).\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n [Install](/sdk/docs/install) the [gcloud CLI](/sdk/gcloud).\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n\n1. Create a [Cloud SQL\n Second Generation instance](/sql/docs/mysql/create-instance#create-2nd-gen) with a [private IP](/sql/docs/mysql/configure-private-ip).\n2. Create a [database user](/sql/docs/mysql/create-manage-users#creating). \n\nCreate a service using the phpMyAdmin image\n-------------------------------------------\n\n### Console\n\n1. In the Google Cloud console, go to Cloud Run:\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n2. Select **Create service**.\n\n 1. In the **Container image** URL field, enter `phpmyadmin`. Cloud Run pulls the image from the public [Docker Hub](https://hub.docker.com/_/phpmyadmin).\n 2. In the **Service name** field, enter `phpmyadmin`.\n 3. Check `Require authentication`.\n 4. Click **Container(s), volumes, networking, security** to set the following options:\n 1. In the **Port** field, enter `80` for the value of the container port.\n 2. In **Environment variables** , add `PMA_HOST` and set the value to be the internal IP address of the Cloud SQL instance.\n 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.\n\n | **Note:** You can also use a Serverless VPC Access instead of routing traffic directly to a VPC. In the [comparison table](/run/docs/configuring/connecting-vpc#comparison-table), learn the difference between the two ways.\n\nConnect to the service using Cloud Run proxy\n--------------------------------------------\n\nTo securely access the IAM-protected service, use the Cloud Run developer proxy.\n| **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](/iap/docs/enabling-cloud-run) to enforce user authentication.\n\n1. To start the proxy on the previously created service, use the following command:\n\n gcloud run services proxy phpmyadmin --port=8080\n\n If [gcloud CLI](/sdk/gcloud) prompts you to install the `cloud-run-proxy` components, then enter `Y`.\n2. To test the setup, enter the URL and port number (for example, `http://127.0.0.1:8080/`),\n and then with the username (admin name) and password. Since you're\n using the local Cloud Run developer proxy to access the service\n securely, you might see an error message, which can be ignored:\n `There is a mismatch between HTTPS indicated on the server and client`.\n\nTroubleshoot\n------------\n\nTo obtain information about Cloud Run errors, access the\n[Cloud Run logs](https://console.cloud.google.com/logs) in the [Google Cloud console](https://console.cloud.google.com/).\n\nClean up\n--------\n\n\nAfter you finish the tutorial, you can clean up the resources that you created so that they\nstop using quota and incurring charges. The following sections describe how to delete or turn off\nthese resources.\n\n\u003cbr /\u003e\n\n### Delete the project\n\n\nThe easiest way to eliminate billing is to delete the project that you\ncreated for the tutorial.\n\nTo delete the project:\n\n| **Caution** : Deleting a project has the following effects:\n|\n| - **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.\n| - **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.\n|\n|\n| If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects\n| can help you avoid exceeding project quota limits.\n1. In the Google Cloud console, go to the **Manage resources** page.\n\n [Go to Manage resources](https://console.cloud.google.com/iam-admin/projects)\n2. In the project list, select the project that you want to delete, and then click **Delete**.\n3. In the dialog, type the project ID, and then click **Shut down** to delete the project.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Delete instances\n\n\nTo delete a Cloud SQL instance:\n\n1. In the Google Cloud console, go to the **Instances** page.\n\n [Go to Instances](https://console.cloud.google.com/sql/instances)\n2. Click the name of the SQL instance you that want to delete.\n3. To delete the instance, click delete **Delete**, and then follow the instructions.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Learn more about phpMyAdmin](http://www.phpmyadmin.net/home_page/docs.php).\n- Explore reference architectures, diagrams, and best practices about Google Cloud. Take a look at our [Cloud Architecture Center](/architecture)."]]