1. Create your Laravel app
-
To create a new Laravel project, run the following commands:
Alternatively, you can deploy an existing Laravel project. To do so,Terminal
cdinto your Laravel repository root folder. -
To generate a sensible default Upsun configuration,
run the following command from within the project’s directory:
The Upsun CLI detects a PHP & Laravel stack. Follow the prompts to specify a name for your project and select the needed services. While optional, it is recommended to add Redis to your project to handle Laravel cache, queues & sessions. TheTerminal
.upsun/config.yamland.environmentconfiguration files are generated. -
Enable the PHP extensions required by the services you selected.
For example,pdo_mysqlis enabled by default, but you may need to enable others likeredisorpdo_pgsql:See all the available PHP extensions..upsun/config.yaml -
Laravel requires an encryption key.
To generate the key locally, runphp artisan key:generate. Copy the key from your local.envfile into.environmentas follows:.environment -
Add and commit your changes:
Terminal
2. Create your Upsun project
To create a project on Upsun, run the following command from within the project’s directory:Terminal
--set-remote flag sets the new project as the remote for this repository.
Tip
You can link any repository to an existing Upsun project using the following command:Terminal
3. Deploy your project
To deploy your project, run the following command:Terminal
CTRL+C in your terminal.
To go back to displaying the logs, run upsun activity:log.
Congratulations, your first Laravel app has been deployed on Upsun!
Tip
Now that your app is deployed in production mode, you can set up a custom domain.4. Configure write access
The Upsun default configuration stipulates three writable folders in.upsun/config.yaml:
"/.config""bootstrap/cache""storage"
5. Make changes to your project
Now that your project is deployed, you can start making changes to it. For example, you might want to fix a bug or add a new feature. In your project, the main branch always represents the production environment. Other branches are for developing new features, fixing bugs, or updating the infrastructure. To make changes to your project, follow these steps:-
Create a new environment (a Git branch) to make changes without impacting production:
This command creates a new localTerminal
feat-aGit branch based on the main Git branch, and activates a related environment on Upsun. The new environment inherits the data (service data and assets) of its parent environment (the production environment here). -
Make changes to your project.
For example, edit the
resources/views/welcome.blade.phptemplate and make the following visual changes: -
Add and commit your changes:
Terminal
-
Deploy your changes to the
feat-aenvironment:Note that each environment has its own domain name. To view the domain name of your new environment, run the following command:TerminalTerminal -
Iterate by changing the code, committing, and deploying.
When satisfied with your changes, merge them to the main branch, deploy,
and remove the feature branch:
Note that deploying to production is fast because the image built for theTerminal
feat-aenvironment is reused. For a long running branch, keep the code up-to-date with the main branch by usinggit merge mainorgit rebase main. Also, keep the data in sync with the production environment by usingupsun env:sync.