Use phpMyAdmin with Cloud SQL on App Engine standard environment
You will find this tutorial helpful if you:
- Run applications on App Engine.
- UseCloud SQL as your database.
- Use phpMyAdmin as an interface for MySQL or you prefer a web interface fordatabase administration.
If you use Compute Engine, consider using one of the development stacksor products availablethrough Click to Deploy. Deployments of stacks that include MySQL, such asLAMP andLEMP, or products such asDrupal, provide an option toinstall phpMyAdmin as part of the deployment.
Objectives
- Deploy phpMyAdmin on App Engine standard environment.
Costs
This tutorial uses billable components of Cloud Platform,including:
- App Engine
- Cloud SQL
Use thePricing Calculator to generate a costestimate based on your projected usage.
Before you begin
- 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.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Install thegcloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Toinitialize the gcloud CLI, run the following command:
gcloudinit
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
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.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Install thegcloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Toinitialize the gcloud CLI, run the following command:
gcloudinit
- Create aCloud SQLSecond Generation instance.
- (Optional) Deploy an App Engine application that uses your Cloud SQL instance or select an existing application.
For example,create and deploy the guestbook sample. Although you can deploy phpMyAdmin on its own, you'll probably want to use it with an App Engine application in your real-world scenario.
Download the phpMyAdmin source code
You'll deploy phpMyAdmin as a service of your App Engine application, soyou must download the source code for phpMyAdmin. Follow these steps:
In a Cloud Shell terminal, enter the following command to download the source codefor phpMyAdmin version 4.9.5:
wgethttps://files.phpmyadmin.net/phpMyAdmin/4.9.5/phpMyAdmin-4.9.5-all-languages.tar.gzTo use a different version of phpMyAdmin, use the linksto available versions on thephpMyAdmin Downloads page.
Make a new directory. You will extract the files into this directory.
mkdirphpMyAdminExtract the files from the archive into the new directory.
tar-xzvfphpMyAdmin-4.9.5-all-languages.tar.gz-CphpMyAdmin--strip-components=1
Prepare the files for deployment
Deploying phpMyAdmin requires that you create three files:app.yaml, whichcontains the configuration information for App Engine;config.inc.php, which contains the configuration information for phpMyAdmin;andphp.ini, which contains application-specific configuration for PHP.
Createapp.yaml
TheApp Engine configuration filespecifies how URL paths correspond to request handlers and static files. It alsocontains information about the application code, such as the application ID andthe latest version identifier. Follow these steps to create the file:
In the directory that you created, named
phpMyAdmin, create a new filenamedapp.yaml.cdphpMyAdmintouchapp.yamlUsing your favorite editor, paste the following text into
app.yaml.service:phpmyadminruntime:php55api_version:1handlers:-url:/(.+\.(ico|jpg|png|gif))$static_files:\1upload:(.+\.(ico|jpg|png|gif))$application_readable:true-url:/(.+\.(htm|html|css|js))$static_files:\1upload:(.+\.(htm|html|css|js))$application_readable:true-url:/(.+\.php)$script:\1login:admin-url:/.*script:index.phplogin:adminIf you are deploying phpMyAdmin as the first and only application in App Engine, change the value for
servicefromphpmyadmintodefault.Normally, you would deploy phpMyAdmin as a service of an existing application and provide a name for the service. However, if you haven't yet deployed an application, then you are required to use the service name "default". That's fine for the purposes of this tutorial if you're trying out phpMyAdmin on App Engine.
This tutorial works only for App Engine standard environment.
Save the file.
Createconfig.inc.php
Follow these steps to create the phpMyAdmin configuration file.
Create a new file named
config.inc.php.touchconfig.inc.phpUsing your favorite editor, paste the following text into
config.inc.php.<?php/** * Copyright 2016 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * This is needed for cookie based authentication to encrypt password in * cookie * http://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator */$cfg['blowfish_secret'] = '{{your_secret}}'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! *//* * Servers configuration */$i = 0;// Change this to use the project and instance that you've created.$host = '/cloudsql/{{your_connection_string}}';$type = 'socket';/** First server*/$i++;/* Authentication type */$cfg['Servers'][$i]['auth_type'] = 'cookie';/* Server parameters */$cfg['Servers'][$i]['socket'] = $host;$cfg['Servers'][$i]['connect_type'] = $type;$cfg['Servers'][$i]['compress'] = false;/* Select mysql if your server does not have mysqli */$cfg['Servers'][$i]['extension'] = 'mysqli';$cfg['Servers'][$i]['AllowNoPassword'] = true;/* * End of servers configuration *//* * Directories for saving/loading files from server */$cfg['UploadDir'] = '';$cfg['SaveDir'] = '';/** Other settings*/$cfg['PmaNoRelation_DisableWarning'] = true;$cfg['ExecTimeLimit'] = 60;$cfg['CheckConfigurationPermissions'] = false;Open Google Cloud Shell and execute the following to get a random string for your blowfish:
php-r"echo password_hash(uniqid(), PASSWORD_BCRYPT).PHP_EOL;"Paste the new secret in place of
{{your_secret}}inconfig.inc.php.Go to theCloud SQL instances page in the Google Cloud console.
Click the Cloud SQL instance to display its Instance details page.
Replace the value of
{{your_connection_string}}(within the$hostvariable) with theInstance connection name property.Save the file.
Createphp.ini
In its code, phpMyAdmin uses functions that are disabled by default in App Engine.Follow these steps to add aphp.ini file so that App Engineenables the functions again:
In the
phpMyAdmindirectory, create the file.touchphp.iniEdit the file and add the following line:
google_app_engine.enable_functions="php_uname, getmypid"Save the file.
Deploy the application
Use the following commands to deploy your application to App Engine.
Check for updates for your
gcloudcomponents.gcloudcomponentsupdateDeploy the application by running the following command from within the
phpMyAdmindirectory where yourapp.yamlfile is located:gcloudappdeployThis command deploys the app to the
phpMyAdminservice, as specified yourapp.yamlfile. Deploying to a separate service helps to ensure thatphpMyAdmin runs in the same data center as your main application, whichimproves performance. To learn more about deploying your app from thecommand line, seeDeploying a PHP App.
Log in to phpMyAdmin
You can now log in to phpMyAdmin.
In your web browser, enter the URL for phpMyAdmin to open the welcome page,changing the URL to use your app ID.
https://phpmyadmin-dot-[YOUR_APP_ID].appspot.comForUsername, enterroot.
Enter the root password you provided whenyou configured the root account.
ClickGo.
As you develop your App Engine app, remember to password protect any useraccounts that you create to access databases in Cloud SQL.
Troubleshoot
App Engine uses the Cloud SQL Auth Proxy to connect to Cloud SQLSecond Generation instances.For more information about how the Cloud SQL Auth Proxy works, seeAbout the Cloud SQL Auth Proxy.
TheApp Engine logs in theGoogle Cloud consolecan provide information about App Engine errors.
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:
Delete instances
To delete a Cloud SQL instance:
- In the Google Cloud console, go to theInstances page.
- Click the name of the SQL instance you that want to delete.
- To delete the instance, clickDelete, and then follow the instructions.
What's next
- Learn more about phpMyAdmin.
- Explore reference architectures, diagrams, and best practices about Google Cloud.Take a look at ourCloud Architecture Center.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-02 UTC.