DEV Community: Capripot The latest articles on DEV Community by Capripot (@capripot). https://dev.to/capripot 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%2F72197%2F25a94d4f-6273-45cd-94ed-bb2a0e689950.jpg DEV Community: Capripot https://dev.to/capripot en Use PHP CLI 7.3 on OVHcloud Performance hosting Capripot Tue, 21 Jul 2020 01:11:42 +0000 https://dev.to/capripot/use-php-cli-5-4-on-ovhcloud-performance-hosting-ah0 https://dev.to/capripot/use-php-cli-5-4-on-ovhcloud-performance-hosting-ah0 <p><a href="proxy.php?url=https://www.ovh.com">OVHcloud</a> is the 3rd website hosting company worldwide, 1st in Europe. They have a good product called <a href="proxy.php?url=https://www.ovh.com/world/web-hosting/web-hosting-performance.xml">Performance Hosting</a> which includes a direct SSH access to the shared server.</p> <p>My goal was to use <a href="proxy.php?url=https://github.com/ruckus/ruckusing-migrations">Ruckus Migrations</a> on production the same way I do in my local development. Ruckus is a database migrations manager, it is inspired by the Rake database migration tools available with Ruby-on-Rails framework.</p> <p>In today's version of the hosting, we can use PHP 7.3<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>/usr/local/php7.3/bin/php <span class="nt">-v</span> <span class="c"># PHP 7.3.18 (cli) (built: May 20 2020 12:29:48) ( NTS )</span> </code></pre> </div> <p>Alias it to <code>php7</code> and source <code>.bashrc</code> so our current terminal re-loads commands present in it.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">echo</span> <span class="s2">"alias php7='/usr/local/php7.3/bin/php"</span> <span class="o">&gt;&gt;</span> .bashrc <span class="nb">source</span> .bashrc </code></pre> </div> <p>And we are good to go<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>php7 ruckus.php db:migrate ENV=production </code></pre> </div> <h2> My original solution </h2> <p>To use it, we need PHP 5.3 minimum. The default <code>php</code> command line on Performance Hosting was PHP 4. But actually, other versions of PHP are available. PHP 5.4.45 cli binary is available under the sweet name of <code>php.ORIG.5_4</code>.</p> <p>If we try to use it directly, it will complain because it tries to use the <code>php.ini</code> configuration file used for PHP 4, so we should provide the 5.4 ini file. We can find it through the <code>phpinfo()</code> function.</p> <p>So, after getting to know all these information, we are able to use PHP cli 5.4:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>php.ORIG.5_4 <span class="nt">-c</span> /usr/local/lib/php.ini-2 </code></pre> </div> <p>But since we probably don’t want to memorize all of that to use PHP cli each time we need it, we should export it as an alias in our <code>.bashrc</code> file.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">echo</span> <span class="s2">"alias php5='php.ORIG.5_4 -c /usr/local/lib/php.ini-2'"</span> <span class="o">&gt;&gt;</span> .bashrc </code></pre> </div> <p>After re-sourcing our bash file<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">.</span> .bashrc </code></pre> </div> <p>We can now execute our scripts with PHP cli 5.4<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>php5 ruckus.php db:migrate <span class="nv">ENV</span><span class="o">=</span>production </code></pre> </div> <p><small><em>Originally published on September 23, 2014</em></small><br> <small><em>Photo by OVHcloud</em></small></p> php ovhcloud ovh SSL for Rails with Heroku and Let’s encrypt Capripot Tue, 21 Jul 2020 00:40:52 +0000 https://dev.to/capripot/ssl-for-rails-with-heroku-and-let-s-encrypt-48mn https://dev.to/capripot/ssl-for-rails-with-heroku-and-let-s-encrypt-48mn <p>SSL certificates have been finally made common thanks to <strong>Let’s encrypt</strong>. </p> <p>Since I originally wrote this article, Heroku released <a href="proxy.php?url=https://devcenter.heroku.com/articles/automated-certificate-management">Automated Certificate Management (ACM)</a> which should be the preferred way to do this task. But for the sake of brain exercising, here is the original article.</p> <p>Let’s see how we can configure a Rails app hosted on Heroku with a Let’s encrypt generated certificate. The second part can be applied to any certificate.</p> <p>Replace <code>example.com</code> with your actual domain 😉</p> <h2> Create the page to verify your domain </h2> <p>At this step, I assume you already have an up and running Rails application on Heroku.</p> <p>You need to add the page to serve the private key given by Let’s encrypt to validate the ownership of your domain.</p> <p>Create a controller or use one you have already with the following public method:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight ruby"><code><span class="k">def</span> <span class="nf">letsencrypt</span> <span class="n">render</span> <span class="ss">text: </span><span class="s2">"</span><span class="si">#{</span><span class="n">params</span><span class="p">[</span><span class="ss">:id</span><span class="p">]</span><span class="si">}</span><span class="s2">.</span><span class="si">#{</span><span class="no">ENV</span><span class="p">[</span><span class="s1">'LETS_ENCRYPT_KEY'</span><span class="p">]</span><span class="si">}</span><span class="s2">"</span> <span class="k">end</span> </code></pre> </div> <p>In your <code>config/routes.rb</code> file, add a route to the page you just created.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>get '/.well-known/acme-challenge/:id', to: "pages#letsencrypt", constraints: { id: /[a-z0-9_-]+/i } </code></pre> </div> <h2> Get Let’s encrypt certificate </h2> <p>We need to get Let’s encrypt binaries first. In a working directory:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>git clone https://github.com/letsencrypt/letsencrypt </code></pre> </div> <p>Then just go in the folder and use <code>letsencrypt-auto</code> binary. It’s in development, so you still need to use the <code>--debug</code> flag. Also, to protect your certificate, you need to run the binary as <code>root</code> user, with <code>sudo</code> for instance.<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code><span class="nb">sudo</span> ./letsencrypt-auto certonly <span class="nt">-d</span> your.domain <span class="nt">--debug</span> </code></pre> </div> <p>Set the environment variable <code>LETS_ENCRYPT_KEY</code> to match the private key given by Let’s encrypt binary, that the part given after the <code>.</code>. Here for instance, when you get prompted<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>Make sure your web server displays the following content at http://your.domain/.well-known/acme-challenge/pA0ucRCnGPnG6S-0fVF93A_-0CQb_rSfeDOYvAXh8Ck before continuing: pA0ucRCnGPnG6S-0fVF93A_-0CQb_rSfeDOYvAXh8Ck.Yq3zvhj7vmfBveGvR85p4nwlOBtf7gip40sSrif__Rr </code></pre> </div> <p>the private key is <code>Yq3zvhj7vmfBveGvR85p4nwlOBtf7gip40sSrif__Rr</code>. In a second terminal, in your Rails app folder, do the following:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>heroku config:set <span class="nv">LETS_ENCRYPT_KEY</span><span class="o">=</span>Yq3zvhj7vmfBveGvR85p4nwlOBtf7gip40sSrif__Rr </code></pre> </div> <p>You can then continue with the Let’s encrypt process by pressing ENTER.</p> <p>Now the binary is requesting a certificate via letsencrypt.com and the Authority is checking that your domain is yours by accessing via http protocol, the page <code>http://your.domain/.well-known/acme-challenge/pA0ucRCnGPnG6S-0fVF93A_-0CQb_rSfeDOYvAXh8Ck</code>.</p> <p>You should get a Congratulations message.</p> <h2> Configure Heroku </h2> <p>Assuming you already installed the Heroku CLI, add the ssl endpoint add-on:</p> <p><code>heroku addons:create ssl:endpoint</code></p> <p>Add your new fresh certificate to Heroku:</p> <p><code>sudo heroku certs:add /etc/letsencrypt/live/your.domain/fullchain.pem /etc/letsencrypt/live/your.domain/privkey.pem</code></p> <p>Learn more about <a href="proxy.php?url=https://devcenter.heroku.com/articles/ssl-endpoint">SSL endpoints in Heroku doc</a>.</p> <h2> Reconfigure your DNS </h2> <p>Ask Heroku what is the ssl endpoint your application got<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>heroku certs </code></pre> </div> <p>You get a list like that:<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight shell"><code>Endpoint Common Name<span class="o">(</span>s<span class="o">)</span> Expires Trusted <span class="nt">------------------------</span> <span class="nt">--------------</span> <span class="nt">--------------------</span> <span class="nt">-------</span> endpoint-0.herokussl.com example.com 2016-01-01 00:00 UTC True </code></pre> </div> <p>Change now your DNS entry to<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight plaintext"><code>IN CNAME endpoint-0.herokussl.com. </code></pre> </div> <p>Learn more about <a href="proxy.php?url=https://devcenter.heroku.com/articles/custom-domains#configuring-dns-for-root-domains">configuring your DNS in Heroku doc</a>.</p> <h2> Test your configuration </h2> <p>After your new DNS entry got propagated, you should be able to access <a href="proxy.php?url=https://example.com">https://example.com</a> with a valid secured connection.</p> <p>If you want to test it before, you can access directly <a href="proxy.php?url=https://endpoint-0.herokussl.com">https://endpoint-0.herokussl.com</a> and check the certificate being properly served.</p> <p>🍻 Peace!</p> <p><small><em>Originally published on February 24, 2016</em></small></p> <p><small>Photo by <a href="proxy.php?url=https://unsplash.com/@jeisblack?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jason Blackeye</a> on <a href="proxy.php?url=https://unsplash.com/s/photos/lock-door?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a><small></small></small></p> rails heroku ssl Hello world Capripot Mon, 20 Jul 2020 23:59:17 +0000 https://dev.to/capripot/hello-world-2oio https://dev.to/capripot/hello-world-2oio <p>Hello and welcome to my blog again. I have a bunch of articles I wanted to publish for a while, but work being work, and life being life, I never took the time to do so. </p> <p>Time is of course not something we can create, we need to choose what to do with it. And I finally am choosing to write.</p> <p>So what's the plan? I'm restarting with a couple of refreshed old blog posts. And then I will start a live code series.</p> <p>Thanks for reading! ❤️</p> hello