In this lesson we'll finally deploy our Laravel QA app in our Production Server.  To follow this lesson  you need to have a remote repository and push your app there.

In your project repository you can hit the Clone or download button. Make sure you're using Clone with SSH then copy the url of your project.

Switch over to the terminal window where you login to your remote server. Change directory to directory where you will put your laravel project. In my case I'll put it in /var/www/html/laraveldemo.site.

cd /var/www/html/laraveldemo.site

Inside this directory just paste the url of your remote repository. Do not hit enter before you add space and follow with dot (.). By specifying the dot after remote url it will tell git to clone the repository and use the current directory to contain the local repo. If you did not specify it your local repository will be placed in new directory.

Once that done we can install Laravel dependencies by running this command:

composer install

Next, we need to have .env file in our Production Server. We can simply copy the .env.example like so:

cp .env.example .env

Then we also need to generate the application key. We can do that by running this command:

php artisan key:generate 

Next, we need to make the boostrap/cache directory accessible by user and group of our system. This can be done by running this command:

sudo chmod -R ug+rwx storage bootstrap/cache

Don't forget to configure your database credentials in your .env file. Also if you enabled Laravel verification feature you need to configure your smtp credentials.

APP_ENV=production

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_database
DB_USERNAME=laravel_user
DB_PASSWORD=password

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your-user-email
MAIL_PASSWORD=your-password-email
MAIL_ENCRYPTION=null

Last, we can run our database migration php artisan migrate. You will get a confirmation message. Just answer yes then hit Enter to continue.

Once that done, you can head over to your browser and reopen or refresh your site. If everything was good you will have your laravel app show up.

Testing

To ensure that our production app is working fine let's register new user by hitting the Register link on the top right. Fill in the form and then hit Register button on the bottom.

If you enable the verified feature you will have this message show up.

You need to go to your email and verify your account by hitting Verify Email Address button.

Once your account verified you will get this message show up.

You can then make further tests such as create new question, create new answer, vote up and vote down, etc.

Congratulations, now you have deployed your Laravel application in your Production Server. In the next lesson we will see how to deploy the future changes.