You will find this tutorial helpful if you:
- Run applications on App Engine.
- Use Cloud SQL as your database.
- Use phpMyAdmin as an interface for MySQL or you prefer a web interface for database administration.
If you use Compute Engine, 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 App Engine standard environment.
Costs
This tutorial uses billable components of Cloud Platform, including:
- App Engine
- Cloud SQL
Use the Pricing Calculator to generate a cost
estimate 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.
-
Make sure that billing is enabled for your Google Cloud project.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- Create a Cloud SQL Second 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, so you must download the source code for phpMyAdmin. Follow these steps:
In a Cloud Shell terminal, enter the following command to download the source code for phpMyAdmin version 4.9.5:
wget https://files.phpmyadmin.net/phpMyAdmin/4.9.5/phpMyAdmin-4.9.5-all-languages.tar.gz
To use a different version of phpMyAdmin, use 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 -xzvf phpMyAdmin-4.9.5-all-languages.tar.gz -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 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
.If you are deploying phpMyAdmin as the first and only application in App Engine, change the value for
service
fromphpmyadmin
todefault
.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.
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
.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 the Cloud 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$host
variable) with the Instance connection name property.Save the file.
Create php.ini
In its code, phpMyAdmin uses functions that are disabled by default in App Engine.
Follow these steps to add a php.ini
file so that App Engine
enables the functions again:
In the
phpMyAdmin
directory, create the file.touch php.ini
Edit the file and add the following line:
Save the file.
Deploy the application
Use the following commands to deploy your application to App Engine.
Check for updates for your
gcloud
components.gcloud components update
Deploy the application by running the following command from within the
phpMyAdmin
directory where yourapp.yaml
file is located:gcloud app deploy
This command deploys the app to the
phpMyAdmin
service, as specified yourapp.yaml
file. Deploying to a separate service helps to ensure that phpMyAdmin runs in the same data center as your main application, which improves performance. To learn more about deploying your app from the command line, see Deploying 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.com
For Username, enter root.
Enter the root password you provided when you configured the root account.
Click Go.
As you develop your App Engine app, remember to password protect any user accounts that you create to access databases in Cloud SQL.
Troubleshoot
App Engine uses the Cloud SQL Auth Proxy to connect to Cloud SQL Second Generation instances. For more information about how the Cloud SQL Auth Proxy works, see About the Cloud SQL Auth Proxy.
The App Engine logs in the Google Cloud console can 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:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Delete instances
To delete a Cloud SQL instance:
- In the Google Cloud console, go to the Instances page.
- Click the name of the SQL instance you that want to delete.
- To delete the instance, click Delete, 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 our Cloud Architecture Center.