You can use Laravel with Git deployment on RunCloud to seamlessly update your live applications. Follow the instructions below to deploy your first Laravel app on RunCloud.
Prerequisite: Make sure you have a Laravel app available in one of the supported Git repositories, such as GitHub, Bitbucket, or GitLab. You also need to change your default PHP CLI version from the RunCloud dashboard to the version that you want to use with your application.
- Create a new web app on RunCloud by clicking on the Deploy New Web App button in the top right corner of the dashboard.
Switch to the Git Repository tab, and select your git provider. Provide a suitable name for your web app.
- Configure the domain name and the SSL certificate for your web application.
- In the Git section, provide the name of the repository, and the name of the branch (usually
main
) that you want to use for this application.
- Next, you’ll need to configure the deployment keys for your web app.
Copy the public key provided in RunCloud dashboard and add it to your Git repository as a deploy key. If you need detailed instructions, check out the post corresponding to your git provider.
- Next, you need to set up the public folder of your web app and specify the PHP version of your web app. You can find these settings under the Basic Settings and Stack section of your web app.
- The public folder should be the same as the public folder of your Laravel app, usually
/public
. The PHP version should be compatible with your Laravel app. Click on the Deploy button to apply the changes.
- After deploying your application, log in to your server via SSH for the one-time configuration. Log in as the user of the web app and navigate to the root of your web app – you can find the Root Path of your application in the RunCloud dashboard.
- In the root directory of your application, run the following commands to install the dependencies, copy the environment file, generate the app key, and cache the configuration of your Laravel app:
composer install
cp .env.example .env
php artisan key:generate
php artisan config:cache
- Next, create a database for your web app on RunCloud. You will need to create a database, a database user, and a database password for your Laravel app. You can refer how to create a database for your web application to get step-by-step instructions.
- After creating the database, go to your Application Settings in the RunCloud dashboard and change the web application type to Laravel. You can find this setting under the Stack section of your web app. Select Laravel from the drop-down menu and click on the Save button.
- On the same page, scroll down and attach your database to your web app. You can find this setting under the Linked Database section of your web app settings. Select the database that you created in the step 9, and click on the Attach Database button.
- Refresh your RunCloud dashboard by hitting the
F5
button orCtrl + R
and you will see a new section in the left menu called Environment Variables. Click on it and edit the environment variables of your Laravel app. You will need to add the database credentials that you created in the previous step.
For example:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your-database-name
DB_USERNAME=your-database-user
DB_PASSWORD=your-database-password
Click on the Save button at the bottom of the page to apply the changes.
- Go back to your SSH terminal and run the following commands to update the dependencies, migrate the database tables, and seed the database with some data (optional) of your Laravel app:
composer update
php artisan migrate
php artisan db:seed
That’s it, you can start using your Laravel app by visiting the URL that you provided earlier. RunCloud makes it easy to manage your web apps. You can run PHP Artisan commands directly from RunCloud dashboard by navigating to the Laravel Artisan section in the left menu.
You can also configure Webhooks to automatically deploy a new version of your app in the future when a change is pushed to your git repository. Just submit the URL provided in the Git Webhook URL tab to your Git provider. If you need step-by-step instructions for this, refer to the post corresponding to your git provider.