You will find this tutorial helpful if you:
- Run an application on Google App Engine for its platform-as-a-service (PaaS) features.
- Use Google Cloud SQL as your database.
- Prefer to use a web interface for database administration or you are already familiar with using phpMyAdmin as an interface for MySQL.
If you use Google Compute Engine for its infrastructure-as-a-service (IaaS) features, consider using one of the development stacks or products available through Click to Deploy. Deployments of stacks that include MySQL, such as LAMP and LEMP, or products such as Drupal, provide an option to install phpMyAdmin as part of the deployment.
Objectives
- Deploy phpMyAdmin on Google App Engine.
- Set user passwords for access to Cloud SQL.
Time required
After meeting the prerequisties, this tutorial takes approximately 15 minutes to complete.
Prerequisites
- Download the Google App Engine SDK for PHP. You'll need the SDK to deploy phpMyAdmin on Google App Engine.
- Create an instance of Cloud SQL.
- (Optional) You can use an existing App Engine application or deploy a new one that uses your Cloud SQL instance. For example, create and deploy the guestbook sample. While you can simply deploy phpMyAdmin on its own, you'll probably want to use it alongside some other App Engine application in your real-world scenario.
- Enable billing.
Download the phpMyAdmin source code
You'll deploy phpMyAdmin as a module of your App Engine application, so you must download the source code for phpMyAdmin. Follow these steps:
-
In a terminal window, enter the following command to download the source code for phpMyAdmin version 4.3.9:
$ wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.3.9/phpMyAdmin-4.3.9-all-languages.tar.bz2If you want to use a different version of phpMyAdmin, you can find the links to available versions on the phpMyAdmin Downloads page.
-
Make a new directory. You will extract the files into this directory.
$ mkdir phpMyAdmin -
Extract the files from the archive into the new directory.
$ tar -xvf phpMyAdmin-4.3.9-all-languages.tar.bz2 -C phpMyAdmin --strip-components=1
Prepare the files for deployment
Deploying phpMyAdmin requires that you create three files: app.yaml, which
contains the configuration information for Google App Engine;
config.inc.php, which contains the configuration information for phpMyAdmin;
and php.ini, which contains application-specific configuration for PHP.
Create app.yaml
The App Engine configuration file specifies how URL paths correspond to request handlers and static files. It also contains information about the application code, such as the application ID and the latest version identifier. Follow these steps to create the file:
-
In the directory that you created, named
phpMyAdmin, create a new file namedapp.yaml.$ cd phpMyAdmin $ touch app.yaml -
Using your favorite editor, paste the following text into
app.yaml.application: <your-project-id> version: 1 module: phpmyadmin runtime: php55 api_version: 1 handlers: - url: /(.*\.(ico$|jpg$|png$|gif$)) static_files: \1 upload: (.*\.(ico$|jpg$|png$|gif$)) application_readable: true - url: /(.*\.(htm$|html$|css$|js$)) static_files: \1 upload: (.*\.(htm$|html$|css$|js$)) application_readable: true - url: /(.*\.(php$)) script: \1 login: admin - url: /(.+) script: index.php login: admin - url: /.* script: index.php login: admin -
Change the value for
applicationto match your project ID. -
If you are deploying phpMyAdmin as the first and only application in App Engine, change the value for
modulefromphpmyadmintodefault.Normally, you would deploy phpMyAdmin as a module of an existing application and provide a name for the module. However, if you haven't yet deployed an application, then you are required to use the module name "default". That's fine for the purposes of this tutorial if you're just trying out phpMyAdmin on App Engine.
-
Save the file.
Create config.inc.php
Follow these steps to create the phpMyAdmin configuration file.
-
Create a new file named
config.inc.php.$ touch config.inc.php -
Using your favorite editor, paste the following text into
config.inc.php.<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /* * 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-project-id>:<your-cloudsql-instance>'; $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; ?> -
In your web browser, open the blowfish secret generator.
- Copy the unique blowfish secret that the page generated. Be careful to copy the generated secret, not the example secret.
- Paste the new secret in place of
<your-secret>inconfig.inc.php. - Change the value for
$hostto use the project ID and name for your Google Cloud SQL instance. To find the instance name in the Developers Console, see the Cloud SQL instances page. - Save the file.
Create php.ini
In its code, phpMyAdmin uses functions that are disabled by default in Google
App Engine. Follow these steps to add a php.ini file so that App Engine
enables the functions again:
-
In the
phpMyAdmindirectory, create the file.$ touch php.ini -
Edit 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 Google App Engine.
-
Check for updates for your
gcloudcomponents. This will ensure that you're using the latest version.$ gcloud components update -
Deploy the application. Replace
<your-app-id>with the correct app ID.$ appcfg.py -A <your-app-id> update .
This command deploys phpMyAdmin as a module of your application as specified in
app.yaml. Deploying as a module helps to ensure that phpMyAdmin runs in the
same data center as your main application, which makes for better performance.
Log in to phpMyAdmin
You can now log in to phpMyAdmin. The config.inc.php file that you deployed
allowed for logging in without a password. For now, that's how you'll log in,
until you set passwords in the next section.
-
In your web browser, enter the URL for phpMyAdmin to open the welcome page. Be sure to change the URL to use your app ID.
https://phpmyadmin-dot-<your-app-id>.appspot.com -
For Username, enter root.
-
Leave Password blank.
-
Click Go.
Set passwords
It's important to password-protect your Cloud SQL instance.
When you created your instance, Cloud SQL created the following four host
combinations for root users and granted all global privileges to these users:
- %
- 127.0.0.1
- ::1
- localhost
The first host (%) represents remote access, such as when you connect to the
database by using the MySQL command-line client with an IP address. You may have
already set a password for this type of access in the Google Developers Console.
The other three hosts are various ways of representing a local connection, such
as when phpMyAdmin connects to the database from App Engine. By default,
connecting through localhost or its variants requires no password in Cloud
SQL.
Until now, allowing connections as a local user with no password has not been an issue because it couldn't be done from outside of App Engine. Deploying phpMyAdmin changes that because it exposed a web interface from your App Engine application to Cloud SQL.
Follow these steps to add passwords for the root users:
- In phpMyAdmin, select the Users tab.
- For the first user,
root %, click Edit Privileges. (If you have already set a password forroot %, you can instead start editing theroot 127.0.0.1entry.) - Click Change password.
- In the Password and Re-type boxes, enter the password.
- Click Go.
- Repeat these steps for the remaining
localhostusers.
You will now need to enter the password when you log in as root using
phpMyAdmin. You can set or change the root % password at any time in the
Google Developers Console, but doing so won't change the passwords for the localhost
root users. Note that the user named Any has USAGE privileges, which is
equivalent to no privileges. This is the appropriate setting and requires no
passwords to be set.
As you develop your App Engine app, remember to password protect any user accounts that you create to access databases in Cloud SQL.