Since you develop article and informational web pages in HTML and PHP, the most efficient way to deploy a “Hello World” app on Google Cloud is using Cloud Run.
Cloud Run is a managed platform that takes your containerized code and puts it on the web with a generated URL. Here is a streamlined guide to getting your first PHP page live.
1. Prerequisites
* A Google Cloud Project with billing enabled.
* The gcloud CLI installed on your local machine (or use the Cloud Shell directly in the browser).
* APIs enabled: Enable the Cloud Run and Cloud Build APIs in your console.
2. Prepare Your Files
Create a new folder for your project and add these two essential files.
index.php
This is your actual informational page.
<?php
echo “<h1>Hello World from Google Cloud!</h1>”;
echo “<p>This page is running on Cloud Run using PHP.</p>”;
?>
Dockerfile
Since Cloud Run uses containers, this file tells Google Cloud how to set up the environment (Apache + PHP).
# Use the official PHP image with Apache
FROM php:8.2-apache
# Copy your local code to the container
COPY index.php /var/www/html/index.php
# Adjust Apache to listen on the port Cloud Run expects ($PORT)
RUN sed -i ‘s/80/${PORT}/g’ /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
# Start Apache
CMD [“apache2-foreground”]
3. Deploy to Cloud Run
Open your terminal (or Cloud Shell) inside your project folder and run this single command:
gcloud run deploy hello-world-php –source . –region us-central1 –allow-unauthenticated
What this command does:
* Uploads your code to Google Cloud.
* Builds a container image using the Dockerfile.
* Deploys that image to a serverless URL.
* –allow-unauthenticated makes the website public (essential for web pages).
4. View Your App
Once the command finishes, the terminal will provide a Service URL (e.g., https://hello-world-php-xxxx.a.run.app).
* Scalability: Google will automatically scale this to zero when no one is visiting, saving you money.
* Updates: To update your page, just change index.php and run the same gcloud run deploy command again.
Would you like me to show you how to connect a custom domain to this Cloud Run service, or perhaps how to set up a CI/CD pipeline so it updates automatically when you push code?
Extending your Hello World app with a custom domain and automated updates (CI/CD) transforms it from a test project into a professional web environment. Here is how to handle both.
1. Map a Custom Domain
Since you are using Cloud Run, you can map a domain (like http://www.yourarticle.com) directly to your service.
* Open Domain Mappings: In the Google Cloud Console, go to Cloud Run > Manage Custom Domains.
* Add Mapping: Click Add Mapping and select your hello-world-php service.
* Verify Ownership: If you haven’t used this domain with Google before, you’ll be prompted to verify it via Google Search Console. You typically do this by adding a TXT record to your DNS settings (at GoDaddy, Namecheap, etc.).
* Update DNS: Once verified, Google will provide you with A and AAAA records (or a CNAME). Copy these and add them to your domain registrar’s DNS management panel.
* Wait for SSL: Google will automatically provision a free SSL certificate (https). This usually takes anywhere from 15 minutes to an hour to activate after the DNS propagates.
2. Setup Automated Updates (CI/CD)
To avoid running gcloud run deploy manually every time you update your HTML/PHP files, you can link your project to a GitHub or GitLab repository.
Step-by-Step with Cloud Build:
* Push to Git: Upload your project (including the Dockerfile and index.php) to a repository on GitHub.
* Setup Continuous Deployment:
* Go to the Cloud Run page in your console.
* Click on your service name, then click Set Up Continuous Deployment.
* Select GitHub as your provider and choose your repository.
* Configure Build:
* Select your branch (e.g., main).
* Choose Dockerfile as the build type.
* Save: Now, every time you git push a change to your repository, Google Cloud will automatically build a new container and update your live website.
Which method should you choose?
| Feature | Best For… |
|—|—|
| Manual Deploy | Quick testing or one-off informational pages. |
| CI/CD (GitHub) | Sites you update frequently (articles, blogs). |
| Custom Domain | Professional branding and SEO. |
Comparison of Hosting Options for PHP
| Feature | Cloud Run | App Engine |
|—|—|—|
| Scale to Zero | Yes (Free when no traffic) | Yes (Standard environment) |
| Language Support | Any (via Docker) | Specific Runtimes |
| Best For | Containers/Modern PHP | Traditional Web Apps |
For more visual guidance on the process, you can check out this Cloud Run Custom Domain Tutorial. This video is particularly useful because it walks through the entire live deployment process, including the tricky DNS verification steps.
Would you like me to generate a cloudbuild.yaml file for you? This would give you more advanced control over your automated build process.
Leave a comment