Before pushing to Forge, we need to build the project for production. To do that, run the following command from your terminal with
laravel-todolist as your working directory.
$ npm run build:prod -s
Once the above command finishes, initialize a git repository for your project like so:
$ git init $ git add . $ git commit -m 'first commit'
We will be pushing our project to Github since Forge provides Github integration (you can also host the project yourself or with any other provider. For this tutorial we will be using Github as our provider). We also assume that you have added your public key to Github and are able to push/pull from your own repositories.
Create a new Github repository and add the repository as a remote endpoint to your project like so:
$ git remote add origin email@example.com:<username>/<project-name>.git
Now push your code to Github:
$ git push origin master
Once it is pushed, open Forge and login to your account. We are also using DigitalOcean as our host (you can always choose any other provider) for this tutorial.
Then create a new server as shown in the image below (give a name you like, along with the region):
Once you create your server, you will get a mail from Forge with credentials for your newly provisioned server and database. Make a note of it.
This step is optional and is only needed if you want root console access to your running instance:
Click on the server you just created and add your SSH keys by navigating to the "SSH keys" tab.
Click the button "Edit files" at the bottom of the page and click "Edit PHP FPM Configuration" as shown in the image below:
Add this line:
extension=v8js.so to the PHP FPM Configuration file as shown in the image below:
Click the button "Edit files" again and click "Edit PHP CLI Configuration" as shown in the image below:
Add this line:
extension=v8js.so to the PHP CLI Configuration file as shown in the image below:
In the "Sites" tab and create a new site within your newly created server. The "Root Domain" should be the fully qualified domain you intend to host your site on.
Then click on the "Manage" button for your site. Once you are redirected to your site's dashboard, install your recently pushed
laravel-todolist repository from Github onto the newly created Site. To do that, just fill your Repository path, a Branch (default is master) and ensure that you enable the Install Composer Dependencies checkbox.
Click the "Edit Deploy Script" button and add the
deploy.sh line as highlighted below (make sure to replace <SUDO-PASSWORD-FROM-EMAIL> with the "Sudo password" you received in your mail from Forge) :
cd <PATH-AS-SHOWN-IN-DEPLOY-SCRIPT> git pull origin master echo "<SUDO-PASSWORD-FROM-EMAIL>" | sudo -S sh deploy.sh composer install --no-interaction --no-dev --prefer-dist php artisan migrate --force
Now, navigate to the "Environment" tab and click "Edit Environment" button. Add the following environment settings to your environment tab (replace the <DATABASE-PASSWORD-RECEIVED-FROM-MAIL> with the "Database password" you received in your Forge email. Also replace <APP-KEY-FROM-ENV> with the APP_KEY generated in your
APP_ENV=production APP_DEBUG=true APP_KEY=<APP-KEY-FROM-ENV> DB_USERNAME=forge DB_PASSWORD=<DATABASE-PASSWORD-RECEIVED-FROM-MAIL> API_PREFIX=api API_DEBUG=true RUBIX_RTL=false
Now navigate back to the "Apps" tab and click the green "Deploy Now" button to deploy your site! You can also click on "Enable Quick Deploy" to automatically deploy your app everytime you push your code to Github.
For the last step, go back to the "Server Details" page and click the "Restart Services" button at the very bottom of the page. Then click "Restart Server" menu item as shown in the image. Once the server is restarted, your site is fully configured and ready to go. Visit your fully qualified domain name to test your newly uploaded app.