Laravel > Github > Hostinger

Setting up a Laravel development environment, managing your code with GitHub, and deploying it effortlessly through Hostinger can sound daunting, but it doesn’t have to be. In this guide, we will walk you through the process of creating a local Laravel development server, pushing your changes to GitHub, and utilizing Hostinger’s auto-deploy feature to streamline your production workflow. By the end, you will have a solid understanding of each step involved in this process.

Setting Up a Local Laravel Development Server

Before you start coding with Laravel, you need to set up your local environment. Laravel requires PHP, Composer, and a database management system like MySQL. Here's a step-by-step guide to getting everything ready:

  • Install PHP and Composer: Download and install PHP. You can check if PHP is installed by running php -v in your terminal. Next, install Composer, which is the PHP dependency manager.
  • Install Laravel: You can create a new Laravel project by running the following command in your terminal:
    composer create-project --prefer-dist laravel/laravel your-project-name
    Replace your-project-name with your desired project folder name.
  • Set Up Your Environment: Navigate to your project directory: cd your-project-name. Then, copy the example environment file: cp .env.example .env. Open the .env file to configure your database and other settings. Don't forget to run php artisan key:generate to generate a new application key.
  • Run the Development Server: Now that your environment is set, you can start your local server using: php artisan serve. By default, it will be available at http://localhost:8000.

Using GitHub for Version Control

To maintain control over your code as it evolves, it’s crucial to use version control. GitHub will help you manage and share your Laravel project. Here’s how to set it up:

  • Initialize Git: Inside your project directory, initialize Git using: git init.
  • Commit Your Changes: Add your files to the staging area using: git add .. Then, commit your changes with: git commit -m "Initial commit".
  • Create a GitHub Repository: Go to GitHub and create a new repository. Once created, follow the instructions they provide to link your local repository. For example
git remote add origin https://github.com/username/repository.git
  • Push Changes: After making changes to your project, push them to GitHub using: git push -u origin master.

Deploying to Hostinger with Auto Deploy Feature

Now that your project is on GitHub, it’s time to take advantage of Hostinger to auto-deploy updates to your production server. Here’s how to set it up:

  • Connect to Hostinger: Log into your Hostinger account and open the hosting panel for your domain. You’ll find the Git option in the “Advanced” section of the control panel.
  • Add Your Repository: In the Git section, click on the “Add Repository” button and enter your GitHub repository URL. Choose the directory where you want the project to be deployed.
  • Set Up Deployment: You can enable the auto-deploy feature by selecting the "Enable Auto-Deployment" option. Hostinger will automatically deploy changes pushed to the selected branch (usually master or main).
  • Configure Environment Settings: Don’t forget to set your environment variables in the Hostinger control panel for the production environment as they may differ from your local settings.

With everything set, every time you push to your specified branch on GitHub, Hostinger will automatically pull the changes and update your application. This process not only saves time but also ensures that your production environment is always in sync with your latest code changes.

In conclusion, by setting up a local Laravel server, managing your code with GitHub, and utilizing Hostinger’s auto-deploy feature, you can streamline your development and deployment process significantly. Happy coding!

Search

Start typing to see results...