<?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: Kwabena Nana Acheampong</title>
    <description>The latest articles on Forem by Kwabena Nana Acheampong (@achiekobby).</description>
    <link>https://forem.com/achiekobby</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%2F876151%2F945eaeab-e087-4a71-a8a4-d63182e9d48b.jpeg</url>
      <title>Forem: Kwabena Nana Acheampong</title>
      <link>https://forem.com/achiekobby</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/achiekobby"/>
    <language>en</language>
    <item>
      <title>Laravel Image Handling using Storage Link</title>
      <dc:creator>Kwabena Nana Acheampong</dc:creator>
      <pubDate>Mon, 23 Sep 2024 08:57:36 +0000</pubDate>
      <link>https://forem.com/achiekobby/laravel-image-handling-using-storage-link-4f03</link>
      <guid>https://forem.com/achiekobby/laravel-image-handling-using-storage-link-4f03</guid>
      <description>&lt;p&gt;In this guide, I will walk you through the process of effectively saving and retrieving images in a Laravel full-stack application. This tutorial assumes you have an active and running Laravel project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-1:&lt;/strong&gt;  Create a Storage Link&lt;br&gt;
Laravel provides a simple and secure way to store files through the storage system. Before saving images, we need to create a symbolic link from the public/storage directory to the storage/app/public directory. This is done using an artisan command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan storage:link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a storage folder inside your public directory, allowing you to access stored images through URLs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-2:&lt;/strong&gt;  Use the Storage Facade in the Controller&lt;br&gt;
To handle image uploads, we can utilize Laravel's Storage facade within the controller method responsible for processing the form submission. Below is an example of how to implement image uploading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function store(Request $request)
{
    try {
        // Define validation rules
        $rules = [
            "image" =&amp;gt; "required|image|mimes:jpeg,png,jpg,gif,svg|max:2048",
        ];

        // Validate the request
        $validation = Validator::make($request-&amp;gt;all(), $rules);
        if ($validation-&amp;gt;fails()) {
            return back()-&amp;gt;with('error', $validation-&amp;gt;errors()-&amp;gt;first())-&amp;gt;withInput($request-&amp;gt;all());
        }

        // Handle image upload
        if ($request-&amp;gt;hasFile('image')) {
            $image = $request-&amp;gt;file('image');
            $imageName = time() . "." . $image-&amp;gt;getClientOriginalExtension();

            // Store the image in the public disk
            $filePath = "images/causes/$imageName";
            Storage::disk('public')-&amp;gt;put($filePath, file_get_contents($image));

            // Save the image path in the database
            $model = ModelClass::create([
                "image" =&amp;gt; $filePath,
            ]);

            return redirect()-&amp;gt;back()-&amp;gt;with('success', 'Record successfully created!');
        }

    } catch (\Exception $e) {
        // Log the error and return a generic message
        Log::error("ERROR_MESSAGE_CAUSES: " . $e-&amp;gt;getMessage());
        return back()-&amp;gt;with('error', 'Sorry, an error occurred. Please try again.');
    }
}


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

&lt;/div&gt;



&lt;p&gt;In this method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We first validate that an image has been uploaded and meets the size and format requirements.&lt;/li&gt;
&lt;li&gt;The image is then saved in the &lt;em&gt;&lt;strong&gt;storage/app/public/images/folder&lt;/strong&gt;&lt;/em&gt; directory.&lt;/li&gt;
&lt;li&gt;The image path is stored in the database for future retrieval.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;STEP-3:&lt;/strong&gt;  Add a Laravel Accessor for Easy Image Retrieval&lt;br&gt;
To make image retrieval more seamless, we can create an accessor in our model. This accessor will automatically append the correct storage URL to the image path when retrieving it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function getImageUrlAttribute()
{
    return $this-&amp;gt;image ? Storage::url($this-&amp;gt;image) : null;
}

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

&lt;/div&gt;



&lt;p&gt;This accessor returns the full URL of the stored image, making it easy to display images in your views.&lt;/p&gt;

&lt;p&gt;In your blade file you can retrieve the image using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="{{ config('services.app_url.domain') . $modelInstance-&amp;gt;image_url }}" alt="No Image" width="100px"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;STEP-4:&lt;/strong&gt;  Configure the Application URL&lt;br&gt;
To ensure images are correctly accessed from the public folder, you should also set the application URL properly in the &lt;em&gt;&lt;strong&gt;config/services.php&lt;/strong&gt;&lt;/em&gt; file. Append this to the return array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"app_url" =&amp;gt; [
    "domain" =&amp;gt; env("APP_URL"),
],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure that your .env file contains the correct URL for your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APP_URL=http://localhost:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures that your application knows where to serve static assets like images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
By following these steps, you can efficiently handle image uploads and retrievals in a Laravel application using the storage link system. The symbolic link allows for seamless access to images, while the Storage facade makes handling file uploads both secure and straightforward.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Renew SSL Certificate on Ubuntu Nginx 22.04 / 20.04 / 18.04.</title>
      <dc:creator>Kwabena Nana Acheampong</dc:creator>
      <pubDate>Sun, 16 Jul 2023 18:38:48 +0000</pubDate>
      <link>https://forem.com/achiekobby/renew-ssl-certificate-on-ubuntu-nginx-2204-2004-1804-41p0</link>
      <guid>https://forem.com/achiekobby/renew-ssl-certificate-on-ubuntu-nginx-2204-2004-1804-41p0</guid>
      <description>&lt;p&gt;&lt;strong&gt;PER-REQUISITES&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to download and upgrade package information from all configured sources.&lt;/p&gt;

&lt;p&gt;2.Run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install python3-certbot-nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to install the Certbot client which is used in managing SSL/TLS certificates with the Nginx web server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NON-WILDCARD SSL RENEWAL&lt;/strong&gt;&lt;br&gt;
For domains which do not require the use of wildcard domains make use of the command below;&lt;/p&gt;

&lt;p&gt;Run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot --nginx -m example@gmail.com -d domain.ddns.net
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;replace the &lt;strong&gt;&lt;em&gt;&lt;a href="mailto:example@gmail.com"&gt;example@gmail.com&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt; with your own email and &lt;strong&gt;&lt;em&gt;domain.ddns.net&lt;/em&gt;&lt;/strong&gt; with the domain you are renewing the SSL for.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Wildcard SSL Certificate Renewal ( if you are using a non-wild card domain then skip step 1a and 1b )&lt;/strong&gt;&lt;br&gt;
Run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot certonly --manual --preferred-challenges=dns --email example@gmail.com --server https://acme-v02.api.letsencrypt.org/directory --agree-dos -d domain.ddns.net -d "*.domain.ddns.net"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;replace the &lt;strong&gt;&lt;a href="mailto:example@gmail.com"&gt;example@gmail.com&lt;/a&gt;&lt;/strong&gt; with your own email and both &lt;strong&gt;&lt;em&gt;domain.ddns.net&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;(&lt;em&gt;"*.domain.ddns.net"&lt;/em&gt;)&lt;/strong&gt; with the domain you are renewing the SSL for.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;1a&lt;/strong&gt;. At this point on the terminal enter "A" to accept terms and "C" to cancel the process and hit Enter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1b&lt;/strong&gt;. This step is to allow redirect of &lt;strong&gt;HTTP&lt;/strong&gt; to the new &lt;strong&gt;HTTPS&lt;/strong&gt;. There are two options to choose from;&lt;br&gt;
a. Enter &lt;strong&gt;type 2&lt;/strong&gt; =&amp;gt; Highly recommended and hit enter.&lt;br&gt;
b. Enter &lt;strong&gt;type 1&lt;/strong&gt;=&amp;gt; To disallow redirect and hit enter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXTRAS&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to ensure the Nginx would reload and pick up the new configurations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot renew --dry-run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to manually renew the SSL certificate before its expiry.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To check your available certs and expiration dates, run
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot certificates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 2 is Not Recommended.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The process of SSL certificate renewal is a critical aspect of maintaining a secure and trustworthy online presence. In this post, we explored the steps needed for the renewal of SSL certificates on an Ubuntu server which is very important aspect of server management in terms of securing data transmissions, establishing trust with visitors, and improving search engine rankings&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>laravel</category>
      <category>nginx</category>
    </item>
  </channel>
</rss>
