<?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: Nazareno Pesado</title>
    <description>The latest articles on DEV Community by Nazareno Pesado (@npesado).</description>
    <link>https://dev.to/npesado</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%2F342242%2Fb095e28e-e923-4a38-a07c-1eea59405bc4.png</url>
      <title>DEV Community: Nazareno Pesado</title>
      <link>https://dev.to/npesado</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/npesado"/>
    <language>en</language>
    <item>
      <title>Install ext-sodium on AWS Lightsail Bitnami LAMP Instance</title>
      <dc:creator>Nazareno Pesado</dc:creator>
      <pubDate>Fri, 30 Jul 2021 14:07:46 +0000</pubDate>
      <link>https://dev.to/npesado/install-ext-sodium-on-aws-lightsail-bitnami-lamp-instance-4gid</link>
      <guid>https://dev.to/npesado/install-ext-sodium-on-aws-lightsail-bitnami-lamp-instance-4gid</guid>
      <description>&lt;p&gt;One of my agency projects on Laravel has a composer dependency that needs "sodium PHP extension", but Bitnami LAMP instance doesn't come with it installed. &lt;/p&gt;

&lt;p&gt;So after trying for almost one hour i successfully install it following this steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First you need to install libsodium-dev through apt
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install libsodium-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Then, using PECL (PHP Extension Manager) you have to install the extension per se
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo pecl install -f libsodium
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Finally, edit php.ini file to activate the extension and restart the services
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /opt/bitnami/php/etc/php.ini
# find "extension=sodium" and uncomment it

sudo /opt/bitnami/ctlscript.sh restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With these steps you have installed PHP sodium extension in your instance&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>Use a custom domain and SSL on AWS Lightsail instance</title>
      <dc:creator>Nazareno Pesado</dc:creator>
      <pubDate>Wed, 21 Jul 2021 13:17:40 +0000</pubDate>
      <link>https://dev.to/npesado/use-a-custom-domain-and-ssl-on-aws-lightsail-instance-3m1o</link>
      <guid>https://dev.to/npesado/use-a-custom-domain-and-ssl-on-aws-lightsail-instance-3m1o</guid>
      <description>&lt;p&gt;In our agency bitopia.digital we need to migrate a platform, which we have hosted in a GoDaddy VPS to a AWS Lightsail instance.&lt;/p&gt;

&lt;p&gt;We started to love❤️ Lightsail because it's simplicity to up and run different system blueprints that makes our business run smooth.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp04rjv6u78frs54qtiwj.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%2Fp04rjv6u78frs54qtiwj.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We found two issues in the process, so i'm writing this to help any of you who maybe are trying to achieve this kind of stuff.&lt;/p&gt;

&lt;h2&gt;
  
  
  The learning process
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Update domain zone
&lt;/h3&gt;

&lt;p&gt;The first one is that we already have a domain name registered in GoDaddy and we need to point it to the need instance.&lt;/p&gt;

&lt;p&gt;We opened domain panel in GoDaddy and updated the A record in our DNS Zone to point to the AWS Lightsail instance static public IP&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq32wxnh45amgmude77rx.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%2Fq32wxnh45amgmude77rx.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That process takes a little while, so you can check the DNS propagation process with a tool like &lt;a href="https://dnschecker.org" rel="noopener noreferrer"&gt;https://dnschecker.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that we already have our domain pointed to our new instance but here is where it came the second issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reissue the SSL certificate
&lt;/h3&gt;

&lt;p&gt;This step could be tricky, but it's easy to follow along.&lt;br&gt;
The first thing we need to do is to generate a a new private key for our AWS Lightsail instance.&lt;/p&gt;

&lt;p&gt;We logged in through SSH in our instance and we run the following command to generate a new private key:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo openssl genrsa -out /opt/bitnami/apache2/conf/bitnami/certs/server.key 2048


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

&lt;/div&gt;

&lt;p&gt;With that key we need to create a certificate to send to the Certificate Authority:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo openssl req -new -key /opt/bitnami/apache2/conf/bitnami/certs/server.key -out /opt/bitnami/apache2/conf/bitnami/certs/cert.csr


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

&lt;/div&gt;

&lt;p&gt;Send cert.csr to the certificate authority. When the certificate authority completes their checks, they will hand over your new certificate to you.&lt;/p&gt;

&lt;p&gt;With the new certificate file (probably a *.crt file), we need to upload it to our instance with the following name:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

/opt/bitnami/apache2/conf/bitnami/certs/server.crt


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

&lt;/div&gt;

&lt;p&gt;After this step we need to update the server name in the apache2 httpd.conf file with the domain name&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo8g3b3wwjz7gcdi8cenu.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%2Fo8g3b3wwjz7gcdi8cenu.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this we have our new instance up and running with a domain and a SSL certificate.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>Convert images to WebP</title>
      <dc:creator>Nazareno Pesado</dc:creator>
      <pubDate>Wed, 03 Feb 2021 14:48:33 +0000</pubDate>
      <link>https://dev.to/npesado/convert-images-to-webp-4i06</link>
      <guid>https://dev.to/npesado/convert-images-to-webp-4i06</guid>
      <description>&lt;p&gt;When you try to optimize the front-end of you website you realized that &lt;a href="https://developers.google.com/speed/pagespeed/insights/?hl=es"&gt;PageSpeed from Google&lt;/a&gt; suggests to use WebP images because, &lt;a href="https://developers.google.com/speed/webp"&gt;as they say&lt;/a&gt;, are 26% smaller in size.&lt;/p&gt;

&lt;p&gt;I'm going to teach you how to use &lt;a href="https://spatie.be/docs/laravel-medialibrary/"&gt;Spatie Media Library&lt;/a&gt;, an awesome PHP + Laravel library to achieve this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start
&lt;/h2&gt;

&lt;h4&gt;
  
  
  1. &lt;a href="https://spatie.be/docs/laravel-medialibrary/v8/installation-setup"&gt;Install Spatie Media Library&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  2. &lt;a href="https://spatie.be/docs/laravel-medialibrary/v8/basic-usage/preparing-your-model"&gt;Prepare your model&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  3. &lt;a href="https://spatie.be/docs/laravel-medialibrary/v8/basic-usage/associating-files"&gt;Associate a file to your model&lt;/a&gt;
&lt;/h4&gt;

&lt;h4&gt;
  
  
  4. &lt;a href="https://spatie.be/docs/laravel-medialibrary/v8/converting-images/defining-conversions"&gt;Converting your images&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;This step could be confusing because in the documentation doesn't specify how to achieve the proper conversion to WebP (or another format you need).&lt;/p&gt;

&lt;p&gt;The first thing you have to do is to add a method called &lt;strong&gt;registerMediaConversions&lt;/strong&gt; to your model. Look at this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Course extends Model implements HasMedia
{
    use InteractsWithMedia;

    public function registerMediaConversions(Media $media = null): void
    {
        $this-&amp;gt;addMediaConversion('cover')
            -&amp;gt;format(Manipulations::FORMAT_WEBP)
            -&amp;gt;width(320)
            -&amp;gt;height(200)
            -&amp;gt;nonQueued();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Important things
&lt;/h3&gt;

&lt;p&gt;Calling to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;addMediaConversion('cover')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we define the name of the conversion that we are going to need later to get the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;format(Manipulations::FORMAT_WEBP)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is the method that &lt;strong&gt;makes the magic of conversion to WebP&lt;/strong&gt; (or to another format)&lt;/p&gt;

&lt;p&gt;We include&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt;nonQueued()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to perform the conversion without queue it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Retrieve the image
&lt;/h3&gt;

&lt;p&gt;So after the conversion we need to retrieve the image to use it in the front-end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$urlToFirstImage = $course-&amp;gt;getFirstMediaUrl('images', 'cover');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first parameter we define the collection where we retrieve the image.&lt;br&gt;
Te second parameter we specify the conversion name we defined before.&lt;/p&gt;

&lt;p&gt;So in that simple way we can convert an image to WebP using Spatie Media Library.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please refer to the &lt;a href="https://spatie.be/docs/laravel-medialibrary/v8/introduction"&gt;library documentation&lt;/a&gt; to expand the usage and adjust this to your specific needs.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>programming</category>
      <category>codenewbie</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
