{"id":275,"date":"2017-07-03T08:27:56","date_gmt":"2017-07-03T08:27:56","guid":{"rendered":"https:\/\/blog.a2design.biz\/?p=275"},"modified":"2023-12-04T12:07:05","modified_gmt":"2023-12-04T12:07:05","slug":"deploying-laravel-projects","status":"publish","type":"post","link":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/","title":{"rendered":"Deploying Laravel Projects"},"content":{"rendered":"\n<p>To deploy Laravel projects on remote servers, we follow the nine steps outlined below (usually the server runs Ubuntu OS).&nbsp;<\/p>\n\n\n\n<p>All the steps are executed through SSH.<\/p>\n\n\n\n<p><strong>Preparing the Remote Server<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create the repository directory. We usually name it <strong>repository<\/strong> or <strong>repo<\/strong> for short.<\/li>\n\n\n\n<li>Inside the repository directory, create another directory with the name of your project. It would look something like this: <strong>repository\/yourProjectName.git\/<\/strong><\/li>\n\n\n\n<li>Inside your project directory, initialize the git repository by executing the following bash command: <strong>git bash init &#8211;bare<\/strong>. The <strong>&#8211;bare<\/strong> option is used to initialize the version control system without including the source project files in the directory. <\/li>\n\n\n\n<li>Create the <strong>post-receive<\/strong> file.<br>Inside <strong>repository\/yourProjectName.git\/hooks\/<\/strong>, create a file and name it <strong>post-receive<\/strong>.<br>Now execute the bash commands in <strong>post-receive<\/strong>:&nbsp; <br>\u201c<strong>git &#8211;work-tree=\/var\/www\/yourDomain\/ &#8211;git-dir=\u201d\/home\/userName\/repository\/yourProjectName.git checkout -f<\/strong>&#8220;, \u201c<strong>sh var\/www\/yourDomain\/build\/build.sh<\/strong>\u201d. The first command will deploy files to the project directory, while the second command will run the bash script for implementation of our bash commands for the project (more about that later). <\/li>\n\n\n\n<li>Give<strong> <\/strong>proper permissions to <strong>post-receive<\/strong>. Run <strong>chmod +x post-receive<\/strong> inside of <strong>repository\/yourProjectName.git\/hooks\/<\/strong> to give permissions to the file <strong>post-receive <\/strong>to be executed. <\/li>\n\n\n\n<li>Install the LEMP stack (Linux Nginx MySQL PHP). For our projects, we typically use the LEMP stack with modern versions of its modules. You can find all the details on how to install and configure a LEMP stack at the following URL: <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04\">there<\/a>. <\/li>\n\n\n\n<li>Install a package manager. Laravel requires package managers in order to install dependencies. Example package managers include Composer for PHP projects or NPM for JavaScript. <br><br><strong>Prepare Local Project<\/strong><\/li>\n\n\n\n<li>We now need to configure our project for deployment, check and add unwanted files or directory to \u201c<strong>gitignore<\/strong>\u201d, and create \u201c<strong>build.sh\u201d<\/strong>.  <\/li>\n<\/ol>\n\n\n\n<p>Example of <strong>build.sh<\/strong>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">ROOT_DIR=\u201d\/home\/userName\/repository\/yourProjectName.git\u201d\nCOMPOSER_DIR=\u201d\/home\/userName\/.composer\u201d\n\n<span class=\"hljs-keyword\">if<\/span> &#91; ! -f ${COMPOSER_DIR}\/composer.phar ]; then\nphp -r <span class=\"hljs-string\">\"readfile('https:\/\/getcomposer.org\/installer');\"<\/span> | php -- --install-dir=${ROOT_DIR}\nfi\nPHP_PATH=<span class=\"hljs-string\">\"\/usr\/bin\/php-7.2\"<\/span>\n\n${ROOT_DIR} ${COMPOSER_DIR}\/composer.phar install -d ${ROOT_DIR}\n${ROOT_DIR} ${COMPOSER_DIR}\/composer.phar dumpautoload\n\nchmod -R <span class=\"hljs-number\">777<\/span> ${ROOT_DIR}\/storage\/\nchmod -R <span class=\"hljs-number\">777<\/span> ${ROOT_DIR}\/bootstrap\/cache\/\n\n${PHP_PATH} ${ROOT_DIR}\/artisan migrate --force\n${PHP_PATH} ${ROOT_DIR}\/artisan view:clear\n${PHP_PATH} ${ROOT_DIR}\/artisan cache:clear\n${PHP_PATH} ${ROOT_DIR}\/artisan clear-compiled\n${PHP_PATH} ${ROOT_DIR}\/artisan optimize\n\ncd ${ROOT_DIR}\nnpm install\nnpm run prod\n<span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"Done..!\"<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now add a remote branch by executing <strong>git remote add beta ssh:\/\/<\/strong><a href=\"http:\/\/user@mydomain.com\/var\/repo\/beta.git\"><strong>user@ip_or_domain\/<\/strong><\/a><strong>home\/userName\/repository\/yourProjectName.git<\/strong>.You can now run the <strong>git push live master<\/strong> git command to start the deployment process.After the files have finished loading to the remote server, build.sh executes all the instructions. <\/p>\n\n\n\n<p>\n\nThis method of deploying Laravel projects is the most common. However, for some situations, the specific directory paths, package managers, or server configuration might change.&nbsp; \n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To deploy Laravel projects on remote servers, we follow the nine steps outlined below (usually the server runs Ubuntu OS).&nbsp; All the steps are executed through SSH. Preparing the Remote Server Example of build.sh: Now add a remote branch by executing git remote add beta ssh:\/\/user@ip_or_domain\/home\/userName\/repository\/yourProjectName.git.You can now run the git push live master git [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":277,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[9,19],"class_list":["post-275","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-laravel","tag-web-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Deploying Laravel Projects - A2 Design<\/title>\n<meta name=\"description\" content=\"Learn the ins and outs of deploying Laravel projects effortlessly. Discover the best practices to ensure a smooth deployment process.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deploying Laravel Projects - A2 Design\" \/>\n<meta property=\"og:description\" content=\"Learn the ins and outs of deploying Laravel projects effortlessly. Discover the best practices to ensure a smooth deployment process.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/\" \/>\n<meta property=\"og:site_name\" content=\"A2 Design\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-03T08:27:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-04T12:07:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.a2design.biz\/blog\/wp-content\/uploads\/2019\/09\/DEPLOYING-LARAVEL-PROJECTS.png\" \/>\n\t<meta property=\"og:image:width\" content=\"885\" \/>\n\t<meta property=\"og:image:height\" content=\"492\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Elizabeth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Elizabeth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/\",\"url\":\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/\",\"name\":\"Deploying Laravel Projects - A2 Design\",\"isPartOf\":{\"@id\":\"https:\/\/www.a2design.biz\/blog\/#website\"},\"datePublished\":\"2017-07-03T08:27:56+00:00\",\"dateModified\":\"2023-12-04T12:07:05+00:00\",\"author\":{\"@id\":\"https:\/\/www.a2design.biz\/blog\/#\/schema\/person\/3f6a2bb6e559a8591cf9e55fb9b64343\"},\"description\":\"Learn the ins and outs of deploying Laravel projects effortlessly. Discover the best practices to ensure a smooth deployment process.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/www.a2design.biz\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Laravel\",\"item\":\"https:\/\/www.a2design.biz\/blog\/tag\/laravel\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Deploying Laravel Projects\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.a2design.biz\/blog\/#website\",\"url\":\"https:\/\/www.a2design.biz\/blog\/\",\"name\":\"A2 Design\",\"description\":\"Web Development for Startups\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.a2design.biz\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.a2design.biz\/blog\/#\/schema\/person\/3f6a2bb6e559a8591cf9e55fb9b64343\",\"name\":\"Elizabeth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.a2design.biz\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b938a046ae0c5bdcecad8495593bad2280eaf69c3fce1ed422faa3e776b66b6a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b938a046ae0c5bdcecad8495593bad2280eaf69c3fce1ed422faa3e776b66b6a?s=96&d=mm&r=g\",\"caption\":\"Elizabeth\"},\"url\":\"https:\/\/www.a2design.biz\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deploying Laravel Projects - A2 Design","description":"Learn the ins and outs of deploying Laravel projects effortlessly. Discover the best practices to ensure a smooth deployment process.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/","og_locale":"en_US","og_type":"article","og_title":"Deploying Laravel Projects - A2 Design","og_description":"Learn the ins and outs of deploying Laravel projects effortlessly. Discover the best practices to ensure a smooth deployment process.","og_url":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/","og_site_name":"A2 Design","article_published_time":"2017-07-03T08:27:56+00:00","article_modified_time":"2023-12-04T12:07:05+00:00","og_image":[{"width":885,"height":492,"url":"https:\/\/www.a2design.biz\/blog\/wp-content\/uploads\/2019\/09\/DEPLOYING-LARAVEL-PROJECTS.png","type":"image\/png"}],"author":"Elizabeth","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Elizabeth","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/","url":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/","name":"Deploying Laravel Projects - A2 Design","isPartOf":{"@id":"https:\/\/www.a2design.biz\/blog\/#website"},"datePublished":"2017-07-03T08:27:56+00:00","dateModified":"2023-12-04T12:07:05+00:00","author":{"@id":"https:\/\/www.a2design.biz\/blog\/#\/schema\/person\/3f6a2bb6e559a8591cf9e55fb9b64343"},"description":"Learn the ins and outs of deploying Laravel projects effortlessly. Discover the best practices to ensure a smooth deployment process.","breadcrumb":{"@id":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.a2design.biz\/blog\/deploying-laravel-projects\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.a2design.biz\/blog\/"},{"@type":"ListItem","position":2,"name":"Laravel","item":"https:\/\/www.a2design.biz\/blog\/tag\/laravel\/"},{"@type":"ListItem","position":3,"name":"Deploying Laravel Projects"}]},{"@type":"WebSite","@id":"https:\/\/www.a2design.biz\/blog\/#website","url":"https:\/\/www.a2design.biz\/blog\/","name":"A2 Design","description":"Web Development for Startups","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.a2design.biz\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.a2design.biz\/blog\/#\/schema\/person\/3f6a2bb6e559a8591cf9e55fb9b64343","name":"Elizabeth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.a2design.biz\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b938a046ae0c5bdcecad8495593bad2280eaf69c3fce1ed422faa3e776b66b6a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b938a046ae0c5bdcecad8495593bad2280eaf69c3fce1ed422faa3e776b66b6a?s=96&d=mm&r=g","caption":"Elizabeth"},"url":"https:\/\/www.a2design.biz\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":0,"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/media\/277"}],"wp:attachment":[{"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.a2design.biz\/blog\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}