<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ google cloud run - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ google cloud run - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 05:06:53 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/google-cloud-run/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to run Laravel on Google Cloud Run with Continuous Integration - a step by step guide ]]>
                </title>
                <description>
                    <![CDATA[ By Geshan Manandhar Laravel has soared in popularity over the last few years. The Laravel community even says that Laravel has made writing PHP more enjoyable instead of a pain. Laravel 6 has some interesting new features. Getting a super scaleable w... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-setup-laravel-6-on-google-cloud-run-with-continuous-integration-ci-step-by-step/</link>
                <guid isPermaLink="false">66d45edd73634435aafcefa2</guid>
                
                    <category>
                        <![CDATA[ Devops ]]>
                    </category>
                
                    <category>
                        <![CDATA[ google cloud ]]>
                    </category>
                
                    <category>
                        <![CDATA[ google cloud run ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Laravel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Software Engineering ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 14 Nov 2019 20:04:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/11/laravel6-on-gcr-f.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Geshan Manandhar</p>
<p>Laravel has <a target="_blank" href="https://trends.google.com/trends/explore?date=2014-11-12%202019-11-12&amp;q=laravel,symfony">soared</a> in popularity over the last few years. The Laravel community even says that Laravel has made writing PHP more enjoyable instead of a pain. Laravel 6 has some interesting new <a target="_blank" href="https://laracasts.com/series/whats-new-in-laravel-6">features</a>. Getting a super scaleable working URL for your application takes hours if not days. Setting up something like Kubernetes is a huge task. This is where Google Cloud Run shines: you can get a working HTTPS URL for any of your containerized apps in minutes.</p>
<p><a target="_blank" href="https://cloud.google.com/run/">Google Cloud Run</a> is serverless and fully managed by Google. You get super scale, billing by the second, HTTPS URLs, and your own domain mapping. If you want to run stateless containers, Cloud Run is hands down the easiest way to do it. In this post, I will detail how to get your Laravel 6 app working on Google cloud run with Continuous Integration (CI).</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li>You are familiar with PHP/Composer and aware of Laravel (if you’ve landed here you are, I suppose)</li>
<li>You know how to use Git from the CLI</li>
<li>Your code is hosted on GitHub for CI/CD and you are familiar with GitHub</li>
<li>Know a fair bit of Docker, maybe even multi-stage build</li>
<li>Have a working Google cloud account (they give you <a target="_blank" href="https://cloud.google.com/free/">$300 credit</a> free for 1 yr, no reasons not to have an account)</li>
</ul>
<h2 id="heading-why-is-cloud-run-a-great-option-for-beginners"><strong>Why is Cloud Run a great option for beginners?</strong></h2>
<p>For two main reasons:</p>
<ol>
<li>Learn about the best practices and software like docker and CI/CD</li>
<li>Getting the basics going just involves clicking a button, selecting 2 things, waiting for 5 mins, and you get a working HTTPS URL. Can it be any easier than this? :)</li>
</ol>
<h2 id="heading-steps-to-deploy"><strong>Steps to deploy</strong></h2>
<p>Below are the steps to set up and deploy Laravel 6 on Cloud Run:</p>
<h3 id="heading-1-clone-laravel-or-new-laravel-project"><strong>1. Clone Laravel or new Laravel project</strong></h3>
<p>Start by cloning Laravel or using composer or the Laravel CLI as indicated in the official <a target="_blank" href="https://laravel.com/docs/5.8/installation">installation</a> guide. I am using composer to get the latest Laravel as below:</p>
<h4 id="heading-command"><strong>Command</strong></h4>
<p>I ran the following command to get the latest Laravel:</p>
<pre><code class="lang-bash">composer create-project --prefer-dist laravel/laravel laravel6-on-google-cloud-run
</code></pre>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/01install-laravel.jpg" alt="Installing Laravel with composer" width="800" height="395" loading="lazy">
<em>Creating a new Laravel Project with Composer</em></p>
<h3 id="heading-2-test-it-locally-first"><strong>2. Test it locally first</strong></h3>
<p>Then run <code>cd laravel6-on-google-cloud-run</code> then <code>php artisan serve</code> to see if it is working. For me it was fine when I went to <code>http://localhost:8000</code> on a web browser. I had PHP 7.2 installed locally.</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/02running-laravel.jpg" alt="Running Laravel locally" width="800" height="410" loading="lazy">
<em>Laravel running locally without Docker</em></p>
<h3 id="heading-3-create-a-new-github-repo"><strong>3. Create a new GitHub repo</strong></h3>
<p>Create a new repository on Github like below:</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/03github-repo.jpg" alt="Creating a repo for Laravel on Github" width="767" height="616" loading="lazy">
<em>Create a new public repo on Github</em></p>
<p>You can use any Git hosting provider, but for this example I will be using <a target="_blank" href="https://github.com/features/actions">Github Actions</a> to run tests (and Github is the most popular git hosting tool).</p>
<h3 id="heading-4-add-repo-push-readme"><strong>4. Add repo, push readme</strong></h3>
<p>Now after you have the repo created, add it to your local Laravel copy and push the Readme file. To do this run the following commands on your CLI:</p>
<pre><code>git init
code . # I used VS code to change the readme
git add readme.md
git commit -m <span class="hljs-string">"Initial commit -- App Readme"</span>
git remote add origin git@github.com:geshan/laravel6-on-google-cloud-run.git
git push -u origin master
</code></pre><h4 id="heading-after-running-the-above-commands-i-had-this-on-my-github-repo"><strong>After running the above commands I had this on my Github repo</strong></h4>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/04initial-push.jpg" alt="After the first push, repo looks like this" width="1054" height="736" loading="lazy">
<em>Repo after pushing the readme to master branch</em></p>
<h3 id="heading-5-add-full-laravel-open-a-pr"><strong>5. Add full Laravel, open a PR</strong></h3>
<p>Now let’s add the whole app as a PR to the Github repo by executing the following commands:</p>
<pre><code>git checkout -b laravel6-full-app
git add .gitignore
git add .
git commit -m <span class="hljs-string">"Add the whole Laravel 6 app"</span>
git push origin laravel6-full-app
</code></pre><p>After that go and open a Pull Request (PR), on the repo like <a target="_blank" href="https://github.com/geshan/laravel6-on-google-cloud-run/pull/1">this</a> one. You might be thinking I am the only one working on this, why do I need a PR? Well, it is always better to do things methodically even if it is just one person working on the project :).</p>
<p>After that merge your pull request.</p>
<h3 id="heading-6-setup-tests-with-github-actionshttpsgithubcomfeaturesactions"><strong>6. Setup tests with <a target="_blank" href="https://github.com/features/actions">GitHub actions</a></strong></h3>
<p>Now the fun part: after you merged your PR now Github knows that this is a Laravel project. Click on the  <code>Actions</code> tab on your repo page and you should be able to see something like below:</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/05github-actions.jpg" alt="Click Actions tab to view options" width="800" height="440" loading="lazy">
<em>Setup the CI workflow for Laravel with Github Actions</em></p>
<p>Click the <code>Set up this workflow</code> under <code>Laravel</code> then on the next page click the <code>Start commit</code> button on the top right. After that add a commit message like below and click <code>Commit new file</code>.</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/06gh-actions-ci.jpg" alt="Add Laravel tests action" width="800" height="418" loading="lazy">
<em>Steps to setup the CI workflow with Github Actions</em></p>
<p>There you go, you have your CI setup. Laravel default tests will run on each git push now. Wasn’t that easy? Thank Github for this great intelligence. No more creating <code>.myCIname.yml</code> files :).</p>
<h3 id="heading-7-add-docker-and-docker-compose-to-run-app-locally"><strong>7. Add docker and docker-compose to run app locally</strong></h3>
<p>Now let’s add docker and docker-compose to run the app locally without PHP or artisan serve. </p>
<p>We will need the container to run Laravel on Google Cloud Run too. This part is inspired by the <a target="_blank" href="https://nsirap.com/posts/010-laravel-on-google-cloud-run/">Laravel on Google Cloud Run</a> post by Nicolas. If you want to learn more about <a target="_blank" href="https://www.docker.com/">Docker</a> and Laravel please refer to this <a target="_blank" href="https://geshan.com.np/blog/2015/10/getting-started-with-laravel-mariadb-mysql-docker/">post</a>.</p>
<p>Run the following commands first to get your master up to date as we added the <code>workflow</code> file from Github interface:</p>
<pre><code>git checkout master
git fetch
git pull --rebase origin master # <span class="hljs-keyword">as</span> we added the workflow file <span class="hljs-keyword">from</span> github interface
git checkout -b docker
</code></pre><p>Add a key to the <code>.env.example</code> file. Copy it from the <code>.env</code> file like below:</p>
<pre><code>APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:DJkdj8L5Di3rUkUOwmBFCrr5dsIYU/s7s+W52ClI4AA=
APP_DEBUG=<span class="hljs-literal">true</span>
APP_URL=http:<span class="hljs-comment">//localhost</span>
</code></pre><p>As this is just a demo this is ok to do. For a real app always be careful with secrets. For production-ready apps do turn of the debugging and other dev related things.</p>
<p>Add the following <code>Dockerfile</code> on the project root:</p>
<pre><code>FROM composer:<span class="hljs-number">1.9</span><span class="hljs-number">.0</span> <span class="hljs-keyword">as</span> build
WORKDIR /app
COPY . /app
RUN composer <span class="hljs-built_in">global</span> <span class="hljs-built_in">require</span> hirak/prestissimo &amp;&amp; composer install

FROM php:<span class="hljs-number">7.3</span>-apache-stretch
RUN docker-php-ext-install pdo pdo_mysql

EXPOSE <span class="hljs-number">8080</span>
COPY --<span class="hljs-keyword">from</span>=build /app /<span class="hljs-keyword">var</span>/www/
COPY docker/<span class="hljs-number">000</span>-<span class="hljs-keyword">default</span>.conf /etc/apache2/sites-available/<span class="hljs-number">000</span>-<span class="hljs-keyword">default</span>.conf
COPY .env.example /<span class="hljs-keyword">var</span>/www/.env
RUN chmod <span class="hljs-number">777</span> -R /<span class="hljs-keyword">var</span>/www/storage/ &amp;&amp; \
    echo <span class="hljs-string">"Listen 8080"</span> &gt;&gt; <span class="hljs-regexp">/etc/</span>apache2/ports.conf &amp;&amp; \
    chown -R www-data:www-data /<span class="hljs-keyword">var</span>/www/ &amp;&amp; \
    a2enmod rewrite
</code></pre><p>Then add the following file at <code>docker/000-default.conf</code></p>
<pre><code>&lt;VirtualHost *:<span class="hljs-number">8080</span>&gt;

  ServerAdmin webmaster@localhost
  DocumentRoot /<span class="hljs-keyword">var</span>/www/public/

  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Directory</span> /<span class="hljs-attr">var</span>/<span class="hljs-attr">www</span>/&gt;</span></span>
    AllowOverride All
    Require all granted
  &lt;/Directory&gt;

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

&lt;/VirtualHost&gt;
</code></pre><p>After that add the following <code>docker-compose.yml</code></p>
<pre><code>version: <span class="hljs-string">'3'</span>
<span class="hljs-attr">services</span>:
  app:
    build:
      context: ./
    volumes:
      - .:<span class="hljs-regexp">/var/</span>www
    <span class="hljs-attr">ports</span>:
      - <span class="hljs-string">"8080:8080"</span>
    <span class="hljs-attr">environment</span>:
      - APP_ENV=local
</code></pre><h4 id="heading-lets-boil-down-to-main-things"><strong>Let's Boil down to main things</strong></h4>
<p>If you try to understand everything here it might be overwhelming, so let me boil down the main parts:</p>
<ol>
<li>We are using the official PHP Apache docker image to run Laravel, which has PHP version 7.3.</li>
<li>We are using a multistage build to get the dependencies with Composer then we're copying them to the main docker image that has PHP 7.3 and Apache.</li>
<li>As Google Cloud Run requires the web-server to be listening to port <code>8080</code> and we are using <code>000-default.conf</code> to configure this</li>
<li>To make things easy to run with the single command <code>docker-compose up</code> we are using docker-compose.</li>
<li>Now as you have read this far, run <code>docker-compose up</code> on your root and then after everything runs go to <code>http://localhost:8080</code> to see that Laravel 6 is running locally on Docker. Below is my <code>docker-compose up</code> output towards the end:</li>
</ol>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/07docker-compose-output.jpg" alt="Docker compose running Laravel with PHP 7.3 and Apache" width="800" height="306" loading="lazy">
<em>Docker compose running successfully on local machine</em></p>
<p>As Laravel is running fine with Docker, let’s open a PR like <a target="_blank" href="https://github.com/geshan/laravel6-on-google-cloud-run/pull/2/files">this</a> one to add Docker to our project. I ran the following commands on the root of the project before opening the Pull Request (PR):</p>
<pre><code>git status
</code></pre><p>It should give you something like below:</p>
<pre><code>On branch docker
Untracked files:
  (use <span class="hljs-string">"git add &lt;file&gt;..."</span> to include <span class="hljs-keyword">in</span> what will be committed)

  Dockerfile
  docker-compose.yml
  docker/

nothing added to commit but untracked files present (use <span class="hljs-string">"git add"</span> to track)
</code></pre><p>Now run the following commands:</p>
<pre><code>git add .
git commit -m <span class="hljs-string">"Add docker and docker compose"</span>
git push origin docker
</code></pre><p>As a bonus it will run the Laravel default test on the push, like you can see below:</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/08test-running-gh.jpg" alt="On each push PHP unit tests will run" width="800" height="486" loading="lazy">
<em>Default Laravel tests running with Github Actions</em></p>
<p>Only the owner of the repo has access to the <code>Actions</code> tab so other people don’t necessarily need to know the results of your test builds :).</p>
<h3 id="heading-8-add-deploy-to-google-cloud-buttonhttpsgithubcomgooglecloudplatformcloud-run-button"><strong>8. Add deploy to <a target="_blank" href="https://github.com/GoogleCloudPlatform/cloud-run-button">Google Cloud button</a></strong></h3>
<p>Now let’s deploy this Laravel setup to Google Cloud Run the easy way. Given that you have merged your PR from the <code>docker</code> branch, let’s run the following commands:</p>
<pre><code>git checkout master
git fetch
git pull --rebase origin master
git checkout -b cloud-run-button
</code></pre><p>Then add the following to your <code>readme.md</code> file:</p>
<pre><code>### Run on Google cloud run

[![Run on Google Cloud](https:<span class="hljs-comment">//storage.googleapis.com/cloudrun/button.svg)](https://console.cloud.google.com/cloudshell/editor?shellonly=true&amp;cloudshell_image=gcr.io/cloudrun/button&amp;cloudshell_git_repo=https://github.com/geshan/laravel6-on-google-cloud-run.git)</span>
</code></pre><p>Be careful and replace the last part with your repo’s <code>HTTPs</code> URL. For example, if your repo is at <code>https://github.com/ghaleroshan/laravel6-on-google-cloud-run</code> it will be <code>https://github.com/ghaleroshan/laravel6-on-google-cloud-run.git</code>, then commit and push. Your PR should look something like <a target="_blank" href="https://github.com/geshan/laravel6-on-google-cloud-run/pull/3/files">this</a> one.</p>
<h3 id="heading-9-deploy-on-google-cloud-run"><strong>9. Deploy on Google Cloud Run</strong></h3>
<p>After you merge your Pull Request (PR), then go to your repo page and click on the <code>Run on Google Cloud</code> button.</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/09cloud-run-button.jpg" alt="Click on the blue button to deploy the app" width="800" height="442" loading="lazy">
<em>Github readme after adding the Run on Google Cloud button</em></p>
<p>After that, if you are logged into your Google account and have Google cloud setup with 1 project, click “Proceed”. You might need to wait a bit, then</p>
<ol>
<li>Choose the project – <code>Choose a project to deploy this application</code></li>
<li>Choose the region – <code>Choose a region to deploy this application</code>, I usually go with <code>us-central-1</code></li>
<li>Then wait for the container to be built and deployed. You can see my process below:</li>
</ol>
<p>If everything goes fine on your <code>Google Cloud Shell</code>, you will see the HTTPS URL that you can hit to see your Laravel app running like below:</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/10laravel-running-gcr.jpg" alt="Hit the given URL to see its running" width="800" height="387" loading="lazy">
<em>Deploy screen of Google Cloud Shell for Laravel 6 on Cloud Run</em></p>
<p>What just happened above is:</p>
<ol>
<li>After choosing the region, the script built a docker container image from the <code>Dockerfile</code> in the repo</li>
<li>Then it pushed the built image to <a target="_blank" href="https://cloud.google.com/container-registry/">Google Container Registry</a></li>
<li>After that using the <a target="_blank" href="https://cloud.google.com/sdk/gcloud/">gcloud</a> CLI it deployed the built image to Cloud Run, which gave back the URL.</li>
</ol>
<h3 id="heading-10-hurray-your-app-is-working"><strong>10. Hurray, your app is working</strong></h3>
<p>After you git the URL you should see your app working on Google Cloud Run like below:</p>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/11laravel-url.jpg" alt="Laravel Running on Google Cloud Run" width="800" height="367" loading="lazy">
<em>Laravel running on Google Cloud Run with Serverless HTTPS URL :)</em></p>
<p>If you want to deploy another version you can merge your PR to master and click the button again to deploy.</p>
<h2 id="heading-more-about-google-cloud-run"><strong>More about Google Cloud Run</strong></h2>
<p>The <a target="_blank" href="https://cloud.google.com/run/pricing">pricing</a> for Google Cloud Run is very generous. You can run any containerized app or web app on Google cloud run. I ran a pet project that got ~ 1 request per minute and I did not have to pay anything.</p>
<p>Behind the scenes, it is using <a target="_blank" href="https://cloud.google.com/knative/">Knative</a> and <a target="_blank" href="https://kubernetes.io/">Kubernetes</a>. It can also be run on your Kubernetes cluster but who would choose to manage a K8s cluster if you can just push and get a scaleable serverless fully managed app :).</p>
<h2 id="heading-tldr"><strong>TLDR</strong></h2>
<p>To run Laravel 6 on Google Cloud Run quickly follow the steps below:</p>
<ol>
<li>Make sure you are logged into your <a target="_blank" href="https://console.cloud.google.com/">Google Cloud Account</a></li>
<li>Go to <a target="_blank" href="https://github.com/geshan/laravel6-on-google-cloud-run">https://github.com/geshan/laravel6-on-google-cloud-run</a></li>
<li>Click the “Run On Google Cloud” blue button</li>
<li>Select your project</li>
<li>Select your region</li>
<li>Wait and get the URL of your Laravel App as below, Enjoy!</li>
</ol>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/10laravel-running-gcr.jpg" alt="Hit the given URL to see its running" width="800" height="387" loading="lazy">
<em>Deploy log of Cloud Run button to deploy Laravel on Google Cloud Run</em></p>
<hr>
<p><img src="https://geshan.com.np/images/laravel6-on-google-cloud-run/11laravel-url.jpg" alt="Laravel Running on Google Cloud Run" width="800" height="367" loading="lazy">
<em>Laravel Running successfully on Google Cloud Run</em></p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>There you go – running a Laravel app on Google cloud run was pretty easy. You have even got test running on Github with Github actions. Hope it helps. To do a CI/CD approach you can check out this <a target="_blank" href="https://medium.com/google-cloud/simplifying-continuous-deployment-to-cloud-run-with-cloud-build-including-custom-domain-setup-ssl-22d23bed5cd6">post</a>. It shows deployment using Cloud build. As the same container is running for local and production (Google Cloud Run) environment you don’t need to learn a new framework to go Serverless.</p>
<blockquote>
<p>Any containerized web app can be run on Google Cloud Run, it is a great service. You can read more at https://geshan.com.np</p>
</blockquote>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
