<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adinnu Benedict</title>
    <description>The latest articles on DEV Community by Adinnu Benedict (@benqoder).</description>
    <link>https://dev.to/benqoder</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F273908%2F162dbb58-cb59-4743-880b-e1db4dcf5e39.jpeg</url>
      <title>DEV Community: Adinnu Benedict</title>
      <link>https://dev.to/benqoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/benqoder"/>
    <language>en</language>
    <item>
      <title>Deploying Laravel App To Shared Hosting (Namecheap) Using Laravel Deployer And Github</title>
      <dc:creator>Adinnu Benedict</dc:creator>
      <pubDate>Sun, 24 Nov 2019 02:34:25 +0000</pubDate>
      <link>https://dev.to/benqoder/deploying-laravel-app-to-shared-hosting-namecheap-using-laravel-deployer-and-github-49i8</link>
      <guid>https://dev.to/benqoder/deploying-laravel-app-to-shared-hosting-namecheap-using-laravel-deployer-and-github-49i8</guid>
      <description>&lt;p&gt;There are lot of tutorials and guides out there that treats this same topic but you will run into issues very quickly while trying to follow them.&lt;/p&gt;

&lt;p&gt;Recently, I was stuck on a project that I must use the shared hosting provided by my client because of low App development budget.&lt;/p&gt;

&lt;p&gt;Most of the guide I found involved&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Editing the index.php before upload&lt;/li&gt;
&lt;li&gt;Editing code on production or replacing files after each change&lt;/li&gt;
&lt;li&gt;No git management or Version control&lt;/li&gt;
&lt;li&gt;No real deployment&lt;/li&gt;
&lt;li&gt;Had lots of security issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I take it on myself to hack through the process of deploying a Laravel app on Shared hosting server while avoiding the problems listed above and I found out it was easier than I thought.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tools
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;A Working Laravel App On Github&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/lorisleiva/laravel-deployer" rel="noopener noreferrer"&gt;Laravel Deployer&lt;/a&gt; Package.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.namecheap.com/hosting/shared" rel="noopener noreferrer"&gt;Namecheap Shared Hosting&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Let's Get To Work
&lt;/h3&gt;

&lt;h5&gt;
  
  
  First we have to setup our hosting cPanel to help deploy easily
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;Login to your Namecheap cPanel Account.&lt;/li&gt;
&lt;li&gt;Navigate to &lt;b&gt;Manage Shell&lt;/b&gt; and &lt;b&gt;Enable SSH access&lt;/b&gt;. Note the &lt;b&gt;Access Details&lt;/b&gt; Displayed&lt;/li&gt;
&lt;li&gt;Navigate to &lt;b&gt;Select PHP Version&lt;/b&gt; and make sure &lt;b&gt;apcu&lt;/b&gt; is enabled&lt;/li&gt;
&lt;li&gt;Optionally, You can create a database if needed&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Next, let's setup up our project for deployment
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;a href="https://github.com/lorisleiva/laravel-deployer" rel="noopener noreferrer"&gt;Laravel deployer&lt;/a&gt; Package by running on the CLI&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require lorisleiva/laravel-deployer
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next, we must generate our deployer config file by running. This config file will tell deployer about our Project, Server and Deployment method.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan deploy:init
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br&gt;
Respond to the CLI Question while replacing&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;b&gt;Repository URL&lt;/b&gt; with your project url on Github&lt;/li&gt;
&lt;li&gt;
&lt;b&gt;Hostname of your deployment server&lt;/b&gt; with your domain name&lt;/li&gt;
&lt;li&gt;
&lt;b&gt;Deployment path (absolute to the server)&lt;/b&gt; with /home/&lt;b&gt;your-cPanel-username&lt;/b&gt;/source&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;On the root directory of the project, create a file called &lt;b&gt;deployer_task.php&lt;/b&gt; and paste the following code inside of it.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Deployer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Symlink Laravel public To public_html'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;task&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app:symlink_public_html'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ln -s /home/{{your-cpanel-username}}/source/current/public /home/{{your-cpanel-username}}/public_html'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;b&gt;config/deploy.php&lt;/b&gt;, scroll till you find the &lt;b&gt;hosts&lt;/b&gt; config and in the section that defines your domain, add or update the follow keys&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'deploy_path' =&amp;gt; '/home/{{your-cpanel-username}}/source',
'user' =&amp;gt; {{your-cpanel-username}},
'strategy' =&amp;gt; 'firstdeploy',
'port' =&amp;gt; 21098, // Port provided by cPanel ssh
'http_user' =&amp;gt; {{your-cpanel-username}},
'writable_mode' =&amp;gt; 'chmod' 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scroll to the &lt;b&gt;include&lt;/b&gt; section add the deployer_task.php we created like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    'include' =&amp;gt; [
        base_path('deployer_task.php')
    ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Scroll again in deployer_task.php file in the &lt;b&gt;hooks&lt;/b&gt; section add &lt;b&gt;app:symlink_public_html&lt;/b&gt; in &lt;b&gt;done&lt;/b&gt; section like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    'hooks' =&amp;gt; [
        .....

        'done' =&amp;gt; [
             ......
             'app:symlink_public_html'
        ]

        .....
     ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;h3&gt;
  
  
  Finally Let's Deploy
&lt;/h3&gt;

&lt;p&gt;All you have to do now is push your code to Github and then run &lt;code&gt;&lt;/code&gt;&lt;code&gt;bash&lt;br&gt;
php artisan deploy&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt; If you setup everything correctly, Your Github Repo password and Server password will be requested multiple times during the deployment process&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fbenqoder%2Fimage%2Fupload%2Fv1574562067%2FCLI_idtpxp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fbenqoder%2Fimage%2Fupload%2Fv1574562067%2FCLI_idtpxp.png" alt="Deployment Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  By Now, your app has been deployed successfully. You can now view your website. 🚀🚀🚀🚀
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Other Notes;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;After first deployment, you should change you deployment strategy to &lt;b&gt;basic&lt;/b&gt; like in step 4 above&lt;/li&gt;
&lt;li&gt;Your migration may not run until you follow this post &lt;a href="https://laravel-news.com/laravel-5-4-key-too-long-error/" rel="noopener noreferrer"&gt;Here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You can read more about Laravel deployer &lt;a href="https://github.com/lorisleiva/laravel-deployer" rel="noopener noreferrer"&gt;Here&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Thanks For Reading My First Blog Post Ever. I Hope It Has Helped You. If you need help you can reach me on twitter &lt;a href="https://twitter.com/benqoder" rel="noopener noreferrer"&gt;@BenQoder&lt;/a&gt;
&lt;/h5&gt;

</description>
      <category>laravel</category>
      <category>cpanel</category>
      <category>git</category>
      <category>deployer</category>
    </item>
  </channel>
</rss>
