{"id":4234,"date":"2022-11-08T14:00:24","date_gmt":"2022-11-08T14:00:24","guid":{"rendered":"https:\/\/osharaprd.wpenginepowered.com\/?p=4234"},"modified":"2024-03-08T15:41:52","modified_gmt":"2024-03-08T20:41:52","slug":"install-laravel-github","status":"publish","type":"post","link":"https:\/\/oshara.ca\/en\/install-laravel-github\/","title":{"rendered":"How to Install Laravel Web Application (cloning Laravel project from GitHub)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Laravel is a powerful PHP framework and its slogan is \u2018The PHP Framework for Web Artisans\u2019.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At our web agency we often receive questions about Laravel app web development.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you forgot the steps or Laravel commands during the installation of your projects, this setup tutorial is for you.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is our Laravel tutorial for installing projects on Linux or Windows server from Github and other Git repositories.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-what-is-laravel\">What is Laravel?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Laravel is a popular and powerful PHP web application framework that makes it easy for developers to deploy modern, scalable, and secure web applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of the key advantages of Laravel is that it simplifies many common app web development tasks, such as routing, authentication, database management, and more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It also includes many pre-built components and packages that can be easily integrated into your application, such as caching, session management, and email sending.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-login-with-the-right-permissions-optional\">Login With the Right Permissions (Optional)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you are logged in as root or super admin on your server locally, make sure you change your user to the default web user for the Laravel project.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Simply do this:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Su yourusername<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-clone-your-repo\">Clone Your Repo<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Whether your project is hosted on Github, Gitlab, Bitbucket or other, it all comes back to GIT, so we can use git on our local machine or server to clone our project.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>git clone linktoyourpo.com\/project name<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Note that you clone projects in 2 ways, one in HTTPS mode and one in SSH mode.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PRO TIP: You can clone your project from a specific branch by doing git clone use this tag:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>-b nameofthebranch linktoyourepo.com\/projectname<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-access-your-project-directory\">Access Your Project Directory<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After cloning Laravel project from GitHub, a new folder with the name of your Laravel project should be created in your current location.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You just need to access it by making:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>cd projectname<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-install-the-project-dependencies-from-the-composer\">Install the Project Dependencies from the Composer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each time you clone a new Laravel project, you have to install all the dependencies of the project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need these packages to start the application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When we run the <strong>composer<\/strong>, it checks the <strong>composer.json<\/strong> file that is in your repo and lists all the composer packages your repo needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As these packages are constantly changing, the source code is usually not submitted to git, thanks to the .gitignore that should always contain the vendor directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So to install all the necessary source code, we run the composer with the following command.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>composer install<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can also think about how to simplify and automate your workflow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-install-npm-dependencies-optional\">Install NPM Dependencies (Optional)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is exactly like the previous step with the only difference being that it will allow you to install Vue.js, Bootstrap.css, Lodash and Laravel Mix etc\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In short, instead of installing PHP code as in the previous step, it\u2019s a matter of installing the required Javascript (or Node) packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The list of packages needed in this case are listed in \u2018packages.json\u2019 file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your project doesn\u2019t use vue.js, node or other you can skip this step, otherwise you have to do:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>npm install<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Others prefer Yarn, if that\u2019s the case, just do it.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Yarn<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-create-a-copy-of-your-env-file\">Create a Copy of Your .env File<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The .env files are generally not submitted to your repo, if this is not the case I invite you to correct this for security reasons.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But there is an example env file and Laravel, which is a template of the .env that every Laravel project needs to start.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So we will make a copy of the .env.example file and create an .env file that we can fill in with our configuration settings.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>cp .env.example .env<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-generate-your-encryption-key\">Generate Your Encryption Key<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Laravel requires that you have an encryption key for each application or website development, this is usually randomly generated and stored in your .env.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The application will use this encryption key to encrypt various elements of your application, such as cookies, password hashes and many other elements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fortunately, Laravel\u2019s command line tools allow you to generate this key easily. In the terminal, we can execute this command to generate this key.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>php artisan key:generate<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Close and open your .env file again, you should notice that the key was generated in the variable: <strong>APP_KEY<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-some-practical-commands-optional\">Some Practical Commands (Optional)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If your Laravel project does not contain a database at this level it should already be working.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If this is the case \u2013 Perfect: everything works like clockwork.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"500\" height=\"344\" src=\"https:\/\/cdn.oshara.ca\/wpsite\/2022\/11\/19032338\/O1GnjDTrkG9KMxQ60Xv1_opt_pandgif.gif\" alt=\"If your Laravel Project doesn't Contain a Database it Should Work Already\" class=\"wp-image-4237\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Otherwise, try these commands that can help:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set the right permissions on all directories and files in your project by simply running:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>chmod 755 -R nameofyourproject\/<\/strong><\/li>\n\n\n\n<li><strong>chmod -R o+w nameofyourproject\/storage<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"otoc-clean-up-your-project\">Clean up your project<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>php artisan cache:clear<\/strong><\/li>\n\n\n\n<li><strong>php artisan view:clear<\/strong><\/li>\n\n\n\n<li><strong>php artisan config:clear<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you have to add to your \/public\/ or \/index.php\/ url<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What if you have a database?&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, let\u2019s get on with it.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-create-an-empty-database-for-your-project\">Create an Empty Database for Your Project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create an empty database for your project using any database tools you prefer (My favorite is Datagrip for Mac, but sometimes I use DBForge, or Mysql Workbench or even good old Phpmyadmin).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Don\u2019t forget to back up the whole thing, you can do that with a simple shell script.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-configure-your-env-file-to-allow-a-connection-to-the-database\">Configure Your .env File to Allow a Connection to the Database<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We will want to allow Laravel to connect to the database you just created in previous step. To do this we need to add the connection references in the .env file and Laravel will take care of the connection from there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the .env file, fill in the options <strong>DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD<\/strong> so that they match the credentials of the database you have just created.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-add-the-tables-and-contents-of-your-database-with-migrations-or-in-sql\">Add the Tables and Contents of Your Database with Migrations or in SQL<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Migrations in Laravel allow you to have all your DB architecture in your code and with a simple command line you <strong>recreate all your tables<\/strong><\/li>\n\n\n\n<li><strong>php artisan migrate<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This command creates the structure of your database but does not fill any tables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the repository has a seed file, this is the time to run it, in order to fill your database with startup or dummy data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>php artisan db:seed<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">PRO TIP: You can combine the 2 previous commands into one command which is this one:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>php artisan migrate:fresh \u2013seed<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Migrations are super handy, but if you don\u2019t have one you simply import the SQL file from your old database with your favorite database tools. This will create all your tables with your contents.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"otoc-conclusion\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all you need to start a Laravel project. Of course, some projects have specific steps that apply only to that project, but the steps I\u2019ve described above are the necessary steps you\u2019ll need to follow to start any standard Laravel project from a git clone.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s essentially the same thing on Windows, unless you don\u2019t have a batch terminal. This would be surprising because if you install Git on a Windows server or machine (as opposed to Ubuntu), then right-click in your folder, you should get the \u2018Git bash here\u2019 option and you\u2019re done.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We at Oshara have been doing web development with Laravel from the beginning. Laravel was just a few months old (circa 2011) when we started website development and custom applications with it. It\u2019s a great tool and it simplifies things a lot.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"544\" height=\"738\" src=\"https:\/\/cdn.oshara.ca\/wpsite\/2022\/11\/19032221\/Get_Git-Bash-Here.png\" alt=\"Git-Bash-Menu\" class=\"wp-image-8404\" srcset=\"https:\/\/cdn.oshara.ca\/wpsite\/2022\/11\/19032221\/Get_Git-Bash-Here.png 544w, https:\/\/cdn.oshara.ca\/wpsite\/2022\/11\/19032221\/Get_Git-Bash-Here-221x300.png 221w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>So installing Laravel was not that hard, right?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope this has helped you get started on your next Laravel project. Don\u2019t forget to subscribe to our newsletter and follow us on social networks for more great tutorials on popular web technologies and marketing techniques.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have any problems with Laravel, please let us help you <a href=\"https:\/\/oshara.ca\/en\/contact\/\" title=\"\">contact our team at Oshara<\/a>. We run the best web development gig in Montreal.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel is a powerful PHP framework and its slogan is \u2018The PHP Framework for Web Artisans\u2019. At our web agency we often receive questions about Laravel app web development. If you forgot the steps or Laravel commands during the installation of your projects, this setup tutorial is for you.&nbsp; Here is our Laravel tutorial for [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":9024,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[26],"tags":[225,226,227,410],"class_list":["post-4234","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-installlaravelclonedfromgit","tag-installlaravelwebapplication","tag-laravelgithub","tag-web-agency-montreal"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/posts\/4234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/comments?post=4234"}],"version-history":[{"count":0,"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/posts\/4234\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/media\/9024"}],"wp:attachment":[{"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/media?parent=4234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/categories?post=4234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oshara.ca\/en\/wp-json\/wp\/v2\/tags?post=4234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}