loading...
Cover image for Laravel Tutorial #8: Deploy

Laravel Tutorial #8: Deploy

ericnanhu profile image Eric Hu Originally published at techjblog.com ・4 min read

Setup a VPS

Read this post for instructions:

img

How to Setup A VPS on Vultr

Install Control Panel and Setup a New Website

There is a lot you can choose from. Here I’ll use aaPanel as an example.

aaPanel Demo

Connect to your server using SSH. If you don’t know how to do that, read the post on How to Setup A VPS on Vultr. Run the shellcode on the official site of aaPanel. Remember, if you choose to use aaPanel, make sure CentOS 7 is installed on your VPS. aaPanel is developed on CentOS, using other systems may cause errors.

After the installation process is finished. Follow the instructions on the screen and log into the panel.

img

From now on, everything should be straightforward. Just install the latest version of Apache or Ngnix (Not necessary, but highly recommended), MySQL and PHP. You can install other tools if you want, but for now, these are all we need.

After you’ve installed all the necessary components, go to “Website”, and click on “Add Site”.

img

Type in the domain you mapped to this server, and create a database. Remember the login information for the database, you’ll need it later on.

You can upload the entire project to the site’s root folder, but the problem is if you want to make modifications to it, you are gonna have to upload the files over and over again.

img

I recommend using GitHub. Download and install the GitHub Desktop on your PC and make a new repository for your project. Push it to the origin.

img

And now you can clone the repository to the root folder of your site. Every time you update your project, just push it to the origin, and then pull it to your server using the command git pull.

Here is a cheat sheet for git commands:

git-cheat-sheet-educationDownload

Configuration

After you pulled the project to the root folder of your site, notice that the .env file is not included. Copy the .env.example and rename it .env. Remember to put in the database information.

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=change to your site's URL

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your database name
DB_USERNAME=database user name
DB_PASSWORD=password

Run composer install to install dependencies:

img

Generate APP_KEY:

php artisan key:generate

Link storage:

php artisan storage:link

Run migrations:

php artisan migrate

img

Install Voyager:

php artisan voyager:install
php artisan voyager:admin your@email.com --create

Configure the BREAD like we did in previous section.

img

Finally, open the .env file again, change APP_ENV to production and APP_DEBUG to false. This is important, or your site will have security issues.

Add some new posts, and now you should be able to access your blog.

img

Troubleshooting

storage/logs/laravel.log Permission Denied

Change the permission for /storage/ to 775.

img

“Specified key was too long” Error

https://laravel-news.com/laravel-5-4-key-too-long-error

xxx Function Disabled For Security Reason

Go to the control panel for your server, and configure PHP.

img

Go to disabled functions and delete the functions that you need to use

img

Now we got a blog with the most basic functions, in the next section of this tutorial, we will talk about some more complicated ones.

Next Post: Laravel Tutorial #9: Search, Pagination, Related Posts and Other Functions

Related Articles

How to Make Your Server More Secure

Laravel Tutorial For Beginners

Django Tutorial For Beginners

Posted on by:

Discussion

markdown guide