<?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>Forem: Youssef Selem</title>
    <description>The latest articles on Forem by Youssef Selem (@yousseffarag96).</description>
    <link>https://forem.com/yousseffarag96</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%2F370200%2Fc9fb3ea3-8800-4f9d-af0d-feff97463c6c.jpg</url>
      <title>Forem: Youssef Selem</title>
      <link>https://forem.com/yousseffarag96</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/yousseffarag96"/>
    <language>en</language>
    <item>
      <title>Laravel Deployment on Elastic Beanstalk</title>
      <dc:creator>Youssef Selem</dc:creator>
      <pubDate>Mon, 20 Apr 2020 21:44:22 +0000</pubDate>
      <link>https://forem.com/yousseffarag96/laravel-deployment-on-elastic-beanstalk-2jia</link>
      <guid>https://forem.com/yousseffarag96/laravel-deployment-on-elastic-beanstalk-2jia</guid>
      <description>&lt;p&gt;so i was trying to deploy Laravel web application on AWS elastic beanstalk, although it appeared to be easy it wasn't. some obstacles were hidden or unanswered whether i should upload all project files ,how to connect to this instance, where to begin and many more questions. I've found answers for most of these questions,before i get started special thanks to the youtube channel &lt;a href="https://www.youtube.com/channel/UCWD8eDGfiYDBjw44v2Yrggg"&gt;ProCoder&lt;/a&gt; it helped me a lot.&lt;/p&gt;

&lt;blockquote&gt;Note: this tutorial is for Linux users especially Ubuntu&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Requirements:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;stable project on your localhost&lt;/li&gt;
&lt;li&gt;AWS account , you can use the free tier&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Create a new empty project&lt;/h2&gt;

&lt;h4&gt;
  
  
  on your AWS console choose elastic beanstalk and create new project without adding anything from your project
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---1zrIJps--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fyzkgwr111fe5y5rf9nw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---1zrIJps--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fyzkgwr111fe5y5rf9nw.png" alt="Alt Text" width="880" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;select web server environment, then you will be in Application page&lt;/p&gt;

&lt;h4&gt;
  
  
  write your application info
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--drCdYeYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pnsumivo9fol8balknjg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--drCdYeYY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pnsumivo9fol8balknjg.png" alt="Alt Text" width="880" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  write your environment name , domin and descrption
&lt;/h4&gt;

&lt;blockquote&gt;Note: by default AWS will choose them for you&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n34b3JPs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h6muukf7m1ypaj6dsdui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n34b3JPs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h6muukf7m1ypaj6dsdui.png" alt="Alt Text" width="880" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  from platform drop down menu choose PHP and the rest will be chosen automatically
&lt;/h4&gt;

&lt;blockquote&gt;Note: feel free to change both the platform branch and platform version&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TyrUw0DV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dszcgf5hkq6dx8em1h8h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TyrUw0DV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dszcgf5hkq6dx8em1h8h.png" alt="Alt Text" width="880" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  choose sample application and click on configure , scroll down till you find Database click on edit
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XoXEkKWo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5o2s2puiihuxrdvz5qhc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XoXEkKWo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5o2s2puiihuxrdvz5qhc.png" alt="Alt Text" width="880" height="353"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--quMlMGFB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i9gpfxdewhgm38f4wr4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--quMlMGFB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i9gpfxdewhgm38f4wr4q.png" alt="Alt Text" width="485" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  in this section the most important part is the username and password, save your settings and create your instance
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yP7x0bTg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eq3evuazwdtcqlljakcs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yP7x0bTg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eq3evuazwdtcqlljakcs.png" alt="Alt Text" width="880" height="795"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;Note: if your AWS account is free stick to db.t2.micro instance&lt;/blockquote&gt;

&lt;h2&gt;In your laravel project&lt;/h2&gt;

&lt;h3&gt;Edit database configuration&lt;/h3&gt;

&lt;p&gt;open your database config file /config/database.php now edit and make three global variables&lt;/p&gt;

&lt;pre&gt;define('RDS_HOSTNAME', $_SERVER['RDS_HOSTNAME']);
define('RDS_USERNAME', $_SERVER['RDS_USERNAME']);
define('RDS_PASSWORD', $_SERVER['RDS_PASSWORD']);
define('RDS_DB_NAME', $_SERVER['RDS_DB_NAME']);&lt;/pre&gt;

&lt;p&gt;now scroll down to connections and edit it to be something like that&lt;/p&gt;

&lt;pre&gt;'mysql' =&amp;gt; [
            'driver' =&amp;gt; 'mysql',
            'host' =&amp;gt; RDS_HOSTNAME,
            'port' =&amp;gt; env('DB_PORT', '3306'),
            'database' =&amp;gt; RDS_DB_NAME,
            'username' =&amp;gt; RDS_USERNAME,
            'password' =&amp;gt; RDS_PASSWORD,
        ]&lt;/pre&gt;

&lt;h3&gt;Zip your files&lt;/h3&gt;

&lt;p&gt;this part is a little bit tricky cause if you didn't notice the files you're zipping it might affect your
    server,also make sure you're not adding any hidden folders. your files should be something like that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;app&lt;/li&gt;
&lt;li&gt;bootstrap&lt;/li&gt;
&lt;li&gt;config&lt;/li&gt;
&lt;li&gt;database&lt;/li&gt;
&lt;li&gt;hooks&lt;/li&gt;
&lt;li&gt;public&lt;/li&gt;
&lt;li&gt;resources&lt;/li&gt;
&lt;li&gt;routes&lt;/li&gt;
&lt;li&gt;storage&lt;/li&gt;
&lt;li&gt;tests&lt;/li&gt;
&lt;li&gt;.editorconfig&lt;/li&gt;
&lt;li&gt;.env&lt;/li&gt;
&lt;li&gt;.env.example&lt;/li&gt;
&lt;li&gt;.gitattributes&lt;/li&gt;
&lt;li&gt;.styleci.yml&lt;/li&gt;
&lt;li&gt;artisan&lt;/li&gt;
&lt;li&gt;composer.json&lt;/li&gt;
&lt;li&gt;composer.lock&lt;/li&gt;
&lt;li&gt;package.json&lt;/li&gt;
&lt;li&gt;package-lock.json&lt;/li&gt;
&lt;li&gt;phpunit.xml&lt;/li&gt;
&lt;li&gt;server.php&lt;/li&gt;
&lt;li&gt;webpack.mix.js&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;Note: i've added the .env file to the file tree to make it easier but feel free to remove it&lt;/blockquote&gt;

&lt;h3&gt;Upload zipped file&lt;/h3&gt;

&lt;p&gt;now open your elastic beanstalk tab ,choose the environment that you'd like to deploy to , then click on the upload and deploy button,choose your file give it a label and press deploy.&lt;/p&gt;

&lt;h3&gt;Web app route&lt;/h3&gt;

&lt;p&gt;on the left-side of your environment page click on configuration,then edit your software section,now change document root to be /public and apply the changes&lt;/p&gt;

&lt;blockquote&gt;Note: if your application need to migrate data and/or other installation don't worry continue to the SSH section&lt;/blockquote&gt;

&lt;h2&gt;Add key pair to your elastic beanstalk&lt;/h2&gt;

&lt;p&gt;this step is very important because it will help you connect with your EC2 instance from anywhere of course by using your key pair file(.pem)&lt;/p&gt;

&lt;blockquote&gt;If you haven't made a key pair yet, make one by clicking Key Pairs below Security Group in the EC2 tab&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;In the AWS console, open the Elastic Beanstalk tab&lt;/li&gt;
&lt;li&gt;Select Environment&lt;/li&gt;
&lt;li&gt;Select Configurations in left panel&lt;/li&gt;
&lt;li&gt;Select Security&lt;/li&gt;
&lt;li&gt;Under "EC2 key pair:", select the name of your key pair in the Existing Key Pair field&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;open your env using SSH&lt;/h2&gt;

&lt;p&gt;open EC2 tab then choose running instance and click on connect ,follow the instruction page about accessing your instance and you'd be online&lt;/p&gt;

&lt;h3&gt;Install composer in your instance&lt;/h3&gt;

&lt;pre&gt;sudo curl -sS https://getcomposer.org/installer | sudo php&lt;/pre&gt;

&lt;pre&gt;sudo mv composer.phar /user/local/bin/composer&lt;/pre&gt;

&lt;pre&gt;sudo ln /user/local/bin/composer /user/bin/composer&lt;/pre&gt;

&lt;h3&gt;Open current version&lt;/h3&gt;

&lt;p&gt;first give the current user permission to write&lt;/p&gt;

&lt;pre&gt;sudo chown -R ec2-user /var/app/current/&lt;/pre&gt;

&lt;blockquote&gt;Note: ec2-user is the name of your ec2 by default&lt;/blockquote&gt;

&lt;pre&gt;cd /var/app/current/&lt;/pre&gt;

&lt;pre&gt;composer dump-autoload&lt;/pre&gt;

&lt;p&gt;now all your artisan commands will work perfectly fine&lt;/p&gt;

&lt;pre&gt;php artisan migrate&lt;/pre&gt;

&lt;p&gt;change your storage file permission so that the server can access it&lt;/p&gt;

&lt;pre&gt;sudo chmod -R 0777 storage&lt;/pre&gt;

&lt;pre&gt;sudo chmod 777 storage/logs/laravel.log&lt;/pre&gt;

&lt;pre&gt;sudo chmod 777 storage/framework/cache&lt;/pre&gt;

&lt;p&gt;now everything is working perfectly fine you can run your own artisan commands&lt;/p&gt;

</description>
      <category>aws</category>
      <category>laravel</category>
      <category>beginners</category>
      <category>php</category>
    </item>
  </channel>
</rss>
