How to host Laravel on Google Cloud VM Instance - ServerAvatar

Published : Sep 13, 2024

Share This Post

cloud-platform

Google Cloud

Google is one of the most famous and reliable cloud providers among all of its competitors in the market. Google Cloud Platform provides a robust and comprehensive set of cloud computing services, catering to diverse business needs from startups to large enterprises.

Get started with Google Cloud
application

Laravel

Laravel is a PHP-based Framework that helps you to build your application with elegant syntax and provides a variety of features. Laravel provides an amazing developer experience.

More info

Laravel is a popular open-source PHP framework designed to enhance the development process by providing a robust set of tools and features. It simplifies building applications with its syntax and modular structure. Laravel offers comprehensive solutions for routing, authentication, and data management, allowing developers to create customized applications efficiently. For hosting Laravel, Google Cloud provides a reliable and scalable infrastructure with robust performance capabilities. ServerAvatar enhances the process by providing an easy, step-by-step guide for setting up a Laravel application on a Google Cloud server, ensuring a seamless and efficient installation.

Create a VM Instance in Google Cloud

Getting started with Google Cloud:

Google is one of the most famous and reliable cloud providers among all of its competitors in the market. Google Cloud Platform provides a robust and comprehensive set of cloud computing services, catering to diverse business needs from startups to large enterprises. With its focus on scalability, performance, security, and innovation, GCP enables organizations to build, deploy, and scale applications and services efficiently in the cloud. Whether it's computing, storage, data analytics, machine learning, or networking, GCP offers a powerful and flexible platform for modern cloud computing requirements.

Google Cloud Platform’s Compute Engine offers robust virtual machine capabilities designed to meet the needs of modern cloud computing environments. Whether you’re looking for flexibility, scalability, performance, or integration with other Google Cloud services, Compute Engine provides a comprehensive solution for running your applications and workloads in the cloud efficiently and securely. Here’s a detailed introduction to Google Cloud as a virtual machine provider:

  • Compute Engine as a primary service: It allows you to quickly scale VMs up or down based on demand, allowing you to handle varying workloads effectively. Users have the flexibility to select VM instance types tailored to their needs for CPU, memory, and disk capacities. Google provides predefined machine types optimized for different tasks, or you can customize machine types to allocate resources according to specific requirements.
  • Key Features and Capabilities: It provides preemptible VMs at a greatly reduced price, ideal for fault-tolerant and batch-processing tasks. VM instances can be migrated live between host systems without any downtime, ensuring exceptional availability and reliability. Users have the option to either create custom VM images or utilize Google's pre-built images for quick deployment of popular software configurations.
  • Integration with Google Services: It offers Control access and permissions for VM instances by managing IAM roles and policies. Compute Engine seamlessly integrates with Google Cloud's VPC networking, enabling the creation of secure and isolated networks tailored for your VMs. It also supports VPNs, Cloud Interconnect, and Google Cloud Load Balancing to efficiently manage network traffic. Moreover, Google's Deployment Manager can be used to automate the creation and management of VMs and associated resources following Infrastructure-as-Code principles.
  • Management and Monitoring: Administer VM instances using the Google Cloud Console, which offers a graphical interface for deploying, monitoring, and managing resources. Engage with Compute Engine programmatically through Google Cloud SDK tools and APIs, enabling automation and seamless integration with other systems.
  • Security and Compliance: Compute Engine incorporates security features such as encryption of data at rest and in transit, secure boot, and IAM controls to safeguard VM instances and data. Google Cloud Platform adheres to various compliance standards (e.g., ISO, SOC, GDPR), providing assurances for regulatory requirements across different industries.

Let’s get started with creating a Virtual Machine on the Google Cloud Platform:

Step 1: Creating a VM in Google Cloud Platform

  • Click on the below link and log in to your Google account.

  • Here you can create a New project or you can select the project you want, and then click on Create a VM as shown in the image below.

Create a VM Instance in Google Cloud

Step 2: Creating a VM Instance

  • For creating a VM instance click on the sidebar, select the Compute Engine, and then click on the VM instances and Create Instance, as depicted in the images below.

Create a VM Instance in Google Cloud

Create a VM Instance in Google Cloud

Step 3: Configuring a New VM Instance

  • Click on New VM Instance, here you can give Name to your virtual machine. Additionally, you can select the Region and Zone of your choice. Moreover, you can select the machine according to your needs from the available types. Refer to the image below.

Create a VM Instance in Google Cloud

Step 4: Select the Machine type

  • Now you have the option to select a Machine Type with predefined configurations of vCPUs and memory which is suitable for most workloads. In addition to this, you can also add Availability policies according to your needs. (Recommended Standard policy)

Create a VM Instance in Google Cloud

  • Also, you can customize your machine that is suitable for your workload as shown in the image below.

Create a VM Instance in Google Cloud

Step 5: Select the Boot disk

  • In this step, you have to select the Operating System for your instance. Click on the Change button to select the boot disk as shown in the image below.

Create a VM Instance in Google Cloud

  • We recommend you to use Ubuntu 20.04 LTS x64 or Ubuntu 22.04 LTS x64. Ubuntu is easy to configure and manage. These operating systems are required if you are using ServerAvatar to manage your instance. Moreover, you can select the disk type you want; however, we recommend you select a Balanced persistence disk with a minimum 25 GB disk size, then click on the Select button as depicted in the following image.

Create a VM Instance in Google Cloud

Step 6: Firewall rules

  • The next step is to allow firewall rules that are available at the time of creating an instance in Google. Select the checkbox next to the HTTP and HTTPS to allow incoming traffic. Click on the Create button to create a VM instance in Google as shown in the image below.

Create a VM Instance in Google Cloud

Step 7: Creating New Firewall Rule

  • Now, you have to go to the VPC network by clicking on the sidebar and then clicking on the Firewall section. After that click on Create Firewall Rule as shown in the images below.

Create a VM Instance in Google Cloud

  • Here you have to enter the details such as the Name of the rule and its description. You can also turn on firewall logs. In addition to this leave the network and priority sections as default. The direction of traffic should be Ingress and Allow the action. In the Targets section, you have three options: All instances in the network, Specified target tags, and Specified service accounts, select from them according to your needs. Furthermore, set the Source filter to IPv4 ranges you can specify the ranges as per your requirement in the Source IPv4 ranges input field. To understand it better refer to the image below.

Create a VM Instance in Google Cloud

  • Lastly, you need to specify the Protocols and ports. ServerAvatar requires 43210 port to be open and the protocol is TCP so add the port number in that field and click on Create as shown in the image below.

Create a VM Instance in Google Cloud

  • Congratulations! You have successfully created your instance in Google Cloud which is now ready to connect with ServerAvatar.

Initial Server Configuration

The Initial server configuration includes the installation and configuration of various packages required to host your website. Usually, You have to write commands and modify configuration files. Luckily, With ServerAvatar, Your full server configuration and optimization can be automated.

Here are the three ways to automatically configure your server with ServerAvatar.

Install and Setup Laravel on Cloud using ServerAvatar

Getting Started With Laravel:

Laravel is a PHP-based Framework that helps you build your application with elegant syntax and provides a variety of features. Laravel provides an amazing developer experience. There are lots of features and tools that are given by Laravel’s environment so that developers can use them to create something new. Laravel is based on MVC (Model, View, Controller) architecture. Laravel is the best choice for small or large projects and full-stack web applications.

Key Features:

  • Open Source: Laravel is open-source, so you have the flexibility to build applications according to your needs.
  • Extensible: Laravel offers the capability to enhance your web application through a wide range of features and tools.
  • Developer-Friendly: Laravel provides an expressive framework with elegant syntax and a scalable environment, and it speeds up your development while maintaining ease of use.
  • Secure: Laravel provides various Authentication processes and middleware to enhance the security of your web application.

Let's begin by creating the application.

Step 1: Create a GitHub application

Start by creating a GitHub Application using ServerAvatar. Go to the Applications tab on the server panel and click on the Create button as shown in the image below.

Install and Setup CodeIgniter on Cloud using ServerAvatar

On the following screen, fill in the Application details, including:

  • Application Name: enter your Application Name.
  • Select Domain: Select between a Test Domain or a Primary Domain as per your requirements.
  • Enter Domain: Enter your Application Domain.
  • Method: Select Git as your application method.
  • Service Provider: Select GitHub as service provider for cloning the repository.
  • Repository Type: Public
  • Clone HTTPS URL: https://github.com/laravel/laravel.git
  • Branch: master
  • Deployment Script: composer update (to update the composer after cloning)

Install and Setup Laravel on Cloud using ServerAvatar

Now, your Application is ready. You can see your Application in the Dashboard.

Install and Setup Laravel on Cloud using ServerAvatar

Step 2: Create a Database

To create a Database that stores your confidential data, Go to the Dashboard and click on the Databases option. Enter Your Database name and just hit on the “Create a Database” button as shown in the image below.

Install and Setup Laravel on Cloud using ServerAvatar

After successfully creating a Database, you can see your Database in the Databases Dashboard.

Install and Setup Laravel on Cloud using ServerAvatar

Step 3: SSH Setup and env Configuration

  • First, go to the Application Dashboard and enable SFTP/SSH Credentials as shown in the below image.

Install and Setup Laravel on Cloud using ServerAvatar

  • After, enabling SFTP/SSH, you can log in to your server. Open a terminal and use the following command: sudo ssh {username}@{ip}
  • Replace {username} with your actual Username and {ip} with your server's IP address. You will be prompted to enter your password. After successful authentication, you will have remote access to your server.
  • Navigate to your Application Path by running the following command: cd LaravelApplication/public_html/

Install and Setup Laravel on Cloud using ServerAvatar

  • Next, you need to copy the .env.example file to the .env file.
  • Command for Copy: cp .env.example .env

Install and Setup Laravel on Cloud using ServerAvatar

Step 4: Generate App Key

  • Next, you need to generate an APP_KEY in your .env file. To generate the key, execute the following command.
  • Command: php artisan key:generate

Install and Setup Laravel on Cloud using ServerAvatar

Step 5: Configure .env file

  • Navigate to the Application Panel access the FIle Manager option and open the public_html folder. Then, click on the Show Hidden Files option.

Install and Setup Laravel on Cloud using ServerAvatar

  • Open the .env file by clicking on it.

Install and Setup Laravel on Cloud using ServerAvatar

  • As shown in the image below, change the APP_URL from http://localhost to your-application-domain in the .env file.
  • Edit and update your application's database details.

Install and Setup Laravel on Cloud using ServerAvatar

  • To find your database credentials, navigate to the Databases section in the server panel and click on the manage users icon next to the database you have set up for your application.

Install and Setup Laravel on Cloud using ServerAvatar

  • You can see your Database credentials as shown in the image below.

Install and Setup Laravel on Cloud using ServerAvatar

Step 6: Migrate Database Tables

  • Now, you have to migrate your Database tables. Execute the following command.
  • Command: php artisan migrate

Install and Setup Laravel on Cloud using ServerAvatar

Step 7: Update Custom Webroot

  • To run your application on a server, you must set your Custom Webroot to public. To update this setting, navigate to the Settings option in the sidebar of your application.
  • Add public in the Custom Webroot Section and click on Update Custom Webroot as shown in the below image.

Install and Setup Laravel on Cloud using ServerAvatar

Step 8: Access Laravel

  • Now, to access Laravel, open your web browser and enter your site's domain.
    • Example: http://lara.satesting1.click
    • For instance: http://your-application-domain

Install and Setup Laravel on Cloud using ServerAvatar

Conclusion :

  • Deploying your PHP Laravel application with ServerAvatar simplifies the entire process, ensuring a smooth and efficient setup. Each step is straightforward and well-guided, from creating the application and database to configuring server settings and migrating database tables.
  • Laravel's robust features, combined with ServerAvatar’s user-friendly interface, make it an excellent choice for developers looking to deploy applications quickly and securely.
  • Following the detailed steps outlined in this guide, you can confidently launch your Laravel application and take advantage of the powerful tools and environment both Laravel and ServerAvatar provide.