How do i start a php service?

  • Overview
  • Solutions
  • Products
  • Pricing
  • Resources
  • Docs
    • Overview
    • Guides
    • Reference
    • Samples
    • Resources
  • Support
  • Console
  • Contact Us
  • Get started for free

Stay organized with collections Save and categorize content based on your preferences.

Learn how to create a simple Hello World application, package it into a container image, upload the container image to Container Registry, and then deploy the container image to Cloud Run. You can use other languages in addition to the ones shown.

Before you begin

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. Install and initialize the Google Cloud CLI.
  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  7. Install and initialize the Google Cloud CLI.
    1. To set the default project for your Cloud Run service:
       gcloud config set project PROJECT_ID
      Replace PROJECT_ID with the name of the project you created for this quickstart.

Write the sample application

To write an application in PHP:

  1. Create a new directory named helloworld-php and change directory into it:

    mkdir helloworld-php
    cd helloworld-php
    
  2. Create a file named index.php and paste the following code into it (make sure you add <?php to the top of the file):

    This code responds to requests with our "Hello World" greeting. HTTP handling is done by an Apache web server in the container.

  3. Create a new file named Dockerfile in the same directory as the source files. The PHP Dockerfile starts an Apache web server that listens on the port defined by the PORT environment variable:

  4. Add a .dockerignore file to exclude files from your container image.

Your app is finished and ready to be deployed.

Deploy to Cloud Run from source

Important: This quickstart assumes that you have owner or editor roles in the project you are using for the quickstart. Otherwise, refer to Cloud Run deployment permissions, Cloud Build permissions, and Artifact Registry permissions for the permissions required.

Deploy from source automatically builds a container image from source code and deploys it.

To deploy from source:

  1. In your source code directory, deploy from source using the following command:

    gcloud run deploy

    If prompted to enable the API, Reply y to enable.

    1. When you are prompted for the source code location, press Enter to deploy the current folder.

    2. When you are prompted for the service name, press Enter to accept the default name, helloworld.

    3. If you are prompted to enable the Artifact Registry API, respond by pressing y.

    4. When you are prompted for region: select the region of your choice, for example us-central1.

    5. You will be prompted to allow unauthenticated invocations: respond y .

    Then wait a few moments until the deployment is complete. On success, the command line displays the service URL.

  2. Visit your deployed service by opening the service URL in a web browser.

Cloud Run locations

Cloud Run is regional, which means the infrastructure that runs your Cloud Run services is located in a specific region and is managed by Google to be redundantly available across all the zones within that region.

Meeting your latency, availability, or durability requirements are primary factors for selecting the region where your Cloud Run services are run. You can generally select the region nearest to your users but you should consider the location of the other Google Cloud products that are used by your Cloud Run service. Using Google Cloud products together across multiple locations can affect your service's latency as well as cost.

Cloud Run is available in the following regions:

Subject to Tier 1 pricing

Subject to Tier 2 pricing

If you already created a Cloud Run service, you can view the region in the Cloud Run dashboard in the Google Cloud console.

Congratulations! You have just deployed a container image from source code to Cloud Run. Cloud Run automatically and horizontally scales out your container image to handle the received requests, then scales in when demand decreases. You only pay for the CPU, memory, and networking consumed during request handling.

Clean up

Remove your test project

While Cloud Run does not charge when the service is not in use, you might still be charged for storing the container image in Artifact Registry. You can delete your container image or delete your Cloud project to avoid incurring charges. Deleting your Cloud project stops billing for all the resources used within that project.

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

What's next

For more information on building a container from code source and pushing to a repository, see:

  • Developing Cloud Run services
  • Building Containers
  • Deploying from source code

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-10-11 UTC.

[{ "type": "thumb-down", "id": "hardToUnderstand", "label":"Hard to understand" },{ "type": "thumb-down", "id": "incorrectInformationOrSampleCode", "label":"Incorrect information or sample code" },{ "type": "thumb-down", "id": "missingTheInformationSamplesINeed", "label":"Missing the information/samples I need" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]

How do I create a PHP service?

Write the sample application.
Create a new directory named helloworld-php and change directory into it: mkdir helloworld-php. cd helloworld-php..
Create a file named index.php and paste the following code into it (make sure you add <? php to the top of the file): run/helloworld/index.php. View on GitHub Feedback..

How do I start a PHP program?

Step 1: First of all, open the Apache Friends website and download XAMPP for Windows, and install it. Step 2: Start the XAMPP Program Control Panel. Click on the “Start” button next to the “Apache” to start your Apache Web Server. Also, start “MySQL” if your PHP programs depend on a MySQL database to run.

What is the command to start PHP server?

You just follow the steps to run PHP program using command line..
Open terminal or command line window..
Goto the specified folder or directory where php files are present..
Then we can run php code using the following command: php file_name.php..

How do I run a PHP script as a service?

Next, please ensure that your PHP script can run normally from the command line..
Start a command prompt (Start button > Run > cmd.exe).
In the window that appears, type the full path to the PHP executable (php.exe) followed by the full path to the script you wish to run as a windows service..