<?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: olorunda olaoluwa</title>
    <description>The latest articles on DEV Community by olorunda olaoluwa (@olorundaolaoluw).</description>
    <link>https://dev.to/olorundaolaoluw</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%2F348616%2Fd7e2fc14-0d09-4351-9f29-db7ec4e49d9c.png</url>
      <title>DEV Community: olorunda olaoluwa</title>
      <link>https://dev.to/olorundaolaoluw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/olorundaolaoluw"/>
    <language>en</language>
    <item>
      <title>Deploying Laravel Application On AWS ElasticBeanstalk from Git using CodePipeline</title>
      <dc:creator>olorunda olaoluwa</dc:creator>
      <pubDate>Thu, 06 Oct 2022 15:48:59 +0000</pubDate>
      <link>https://dev.to/olorundaolaoluw/deploying-laravel-application-on-aws-elasticbeanstalk-from-git-using-codepipeline-2p6n</link>
      <guid>https://dev.to/olorundaolaoluw/deploying-laravel-application-on-aws-elasticbeanstalk-from-git-using-codepipeline-2p6n</guid>
      <description>&lt;p&gt;So you have built your awesome laravel application, and now you want to deploy it on AWS Elasticbeanstalk .&lt;/p&gt;

&lt;p&gt;Here are some steps that could help you to successfully deploy your laravel application on elastic beanstalk from GIT using CodePipeline.&lt;/p&gt;

&lt;p&gt;This article is for someone who is familiar with the aws environment but struggling deploying Laravel application on elastickbeanstalk from Git using CodePiepline&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1 :&lt;/strong&gt;&lt;br&gt;
Create a  “&lt;strong&gt;.ebextensions&lt;/strong&gt;” folder in you Laravel Application Root directory  as shown in the image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8la9c1hnwcv2cnkq4jj4.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8la9c1hnwcv2cnkq4jj4.png" alt="Step 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inside the “&lt;strong&gt;.ebextensions&lt;/strong&gt;” folder , create an “&lt;strong&gt;environment.config&lt;/strong&gt;”  file , it could be any name of your choice , copy and paste the content below in the config file you created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;option_settings:
  aws:elasticbeanstalk:container:php:phpini:
    document_root: /public
  aws:elasticbeanstalk:application:environment:
    APP_NAME: Laravel
    APP_ENV: local
    APP_KEY: “your_app_key”
    APP_DEBUG: true
    APP_URL: http://localhost
    LOG_CHANNEL: stack
    LOG_DEPRECATIONS_CHANNEL: null
    LOG_LEVEL: debug
    DB_CONNECTION: mysql
    DB_HOST: "${RDS_HOSTNAME}"
    DB_PORT: "${RDS_HOSTNAME}"
    DB_DATABASE: "${RDS_DB_NAME}"
    DB_USERNAME: "${RDS_USERNAME}"
    DB_PASSWORD: "${RDS_PASSWORD}"
    BROADCAST_DRIVER: log
    CACHE_DRIVER: file
    FILESYSTEM_DRIVER: local
    QUEUE_CONNECTION: sync
    SESSION_DRIVER: file
    SESSION_LIFETIME: 120
    MEMCACHED_HOST: 127.0.0.1
    REDIS_HOST: 127.0.0.1
    REDIS_PASSWORD: null
    REDIS_PORT: 6379
    MAIL_MAILER: smtp
    MAIL_HOST: mailhog
    MAIL_PORT: 1025
    MAIL_USERNAME: null
    MAIL_PASSWORD: null
    MAIL_ENCRYPTION: null
    MAIL_FROM_ADDRESS: null
    MAIL_FROM_NAME="${APP_NAME}"
    AWS_ACCESS_KEY_ID: ''
    AWS_SECRET_ACCESS_KEY: ''
    AWS_DEFAULT_REGION: us-east-1
    AWS_BUCKET: ''
    AWS_USE_PATH_STYLE_ENDPOINT: false
    PUSHER_APP_ID: ''
    PUSHER_APP_KEY: ''
    PUSHER_APP_SECRET: ''
    PUSHER_APP_CLUSTER: mt1
    MIX_PUSHER_APP_KEY: "${PUSHER_APP_KEY}"
    MIX_PUSHER_APP_CLUSTER: "${PUSHER_APP_CLUSTER}"
container_commands:
  01-no_dev:
    command: "composer.phar install --optimize-autoloader"
  02-artisan_optmize:
    command: "php artisan optimize"
files:
    "/etc/cron.d/schedule_run":
        mode: "000644"
        owner: root
        group: root
        content: |
            * * * * * webapp php /var/www/html/artisan schedule:run --env=production &amp;gt;&amp;gt; /dev/null 2&amp;gt;&amp;amp;1
    "/etc/php.d/99max_size.ini" :
        mode: "000755"
        owner: root
        group: root
        content: |
          upload_max_filesize = 128M
          post_max_size = 128M 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a second config file , could be anyname different from the name of the first config file. Copy and paste the content below in the newly created config file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commands:
    setvars:
        command: /opt/elasticbeanstalk/bin/get-config optionsettings | \jq '."aws:elasticbeanstalk:application:environment"' | \jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' &amp;gt; /etc/profile.d/local.sh

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command in this config file exposes the ElasticBeanstalk environment variables to the EC2 instance created by the Elasticbeanstalk instance so that your laravel application can have access to the environment variables&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&lt;br&gt;
Create a &lt;strong&gt;.platform&lt;/strong&gt; folder in the root of your laravel application , following this structure in the image below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyjztjdrpedzsg3pwkjwr.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyjztjdrpedzsg3pwkjwr.png" alt="Image 2"&gt;&lt;/a&gt;&lt;br&gt;
Copy and paste the content below in the &lt;strong&gt;laravel.conf&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;location / {
         try_files $uri $uri/ /index.php?$query_string;
         gzip_static on;
     }
 client_max_body_size 128M;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3 :&lt;/strong&gt;&lt;br&gt;
Head over to &lt;a href="https://console.aws.amazon.com" rel="noopener noreferrer"&gt;https://console.aws.amazon.com&lt;/a&gt;, create an elastic beanstalk instance , select “&lt;strong&gt;Web server enviroment&lt;/strong&gt;” as show in the picture below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzlwesz23fqboqlpicx68.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzlwesz23fqboqlpicx68.png" alt="Image 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bwfju3y1qs10ektlpz9.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bwfju3y1qs10ektlpz9.png" alt="Image 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 :&lt;/strong&gt; After you are done creating your elasticbeanstalk instance , go &lt;a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_PHP.rds.html" rel="noopener noreferrer"&gt;here&lt;/a&gt; to see how to attach an rds database to your elasticbeanstalk instance . This will expose the following environment variables to your laravel application&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    RDS_HOSTNAME
    RDS_HOSTNAME
    RDS_DB_NAME
    RDS_USERNAME
    RDS_PASSWORD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can either change your laravel config to read this environment variable name directly in your “&lt;strong&gt;config/database.php&lt;/strong&gt;” or you reference it as shown in the environment.config file you created in step 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;• Create a code pipeline on AWS.&lt;br&gt;
• Choose Source Provider as “&lt;strong&gt;Github (Version 2)&lt;/strong&gt;” , you can skip the build stage.&lt;br&gt;
• On the Deploy stage  choose “AWS Elasticbeanstalk” as your deploy provider, you would then select the earlier created application from the list of application names available&lt;br&gt;
• Once you are done filling all the necessary information, review and release changes &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4axoo19m1kuwibcjay5.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv4axoo19m1kuwibcjay5.png" alt="Image 5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Your Pipeline would run through all the stages and automatically deploy your laravel application to your elasticbeanstalk environment &lt;/p&gt;

</description>
      <category>aws</category>
      <category>codepipeline</category>
      <category>elasticbeanstalk</category>
      <category>laravel</category>
    </item>
  </channel>
</rss>
