<?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: Sony AK</title>
    <description>The latest articles on DEV Community by Sony AK (@sonyarianto).</description>
    <link>https://dev.to/sonyarianto</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%2F45583%2Fbe20bc85-6bbb-4ee8-90d0-d9fabe9d2f28.png</url>
      <title>DEV Community: Sony AK</title>
      <link>https://dev.to/sonyarianto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sonyarianto"/>
    <language>en</language>
    <item>
      <title>How to use Playwright with external/existing Chrome</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Sat, 22 Jul 2023 19:50:51 +0000</pubDate>
      <link>https://dev.to/sonyarianto/how-to-use-playwright-with-externalexisting-chrome-4nf1</link>
      <guid>https://dev.to/sonyarianto/how-to-use-playwright-with-externalexisting-chrome-4nf1</guid>
      <description>&lt;p&gt;Mostly example using Playwright in JavaScript is using Chromium that bundled with Playwright. How about if we want to use existing or external Chrome?&lt;/p&gt;

&lt;p&gt;No worries, it means you have to set the Playwright to connect to a Chromium instance manually using Chrome DevTools Protocol (CDP) and that means you should run the Chrome with &lt;code&gt;--remote-debugging-port=9222&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For the external Chrome I recommend using Chrome for Testing that is good for this situation. Just to to &lt;a href="https://developer.chrome.com/blog/chrome-for-testing" rel="noopener noreferrer"&gt;https://developer.chrome.com/blog/chrome-for-testing&lt;/a&gt; to read more.&lt;/p&gt;

&lt;p&gt;I have created the repository and quick script sample about this. Just go to &lt;a href="https://github.com/sonyarianto/playwright-using-external-chrome" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/playwright-using-external-chrome&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wanna quick try? Here is the script &lt;code&gt;index.js&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;playwright&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connectOverCDP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://localhost:9222&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isConnected&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Connected to Chrome.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Contexts in CDP session: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contexts&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contexts&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://example.com&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;screenshot&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;example.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cannot connect to Chrome.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run it like this. Make sure you already run the Chrome first (with argument &lt;code&gt;--remote-debugging-port=9222&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node ./index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy using Playwright.&lt;/p&gt;

</description>
      <category>playwright</category>
      <category>javascript</category>
      <category>chrome</category>
    </item>
    <item>
      <title>Simple Demo Fluent UI 2 TreeView Web Components with Dynamic Data in Svelte</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Mon, 26 Jun 2023 04:47:51 +0000</pubDate>
      <link>https://dev.to/sonyarianto/simple-demo-fluent-ui-2-treeview-web-components-with-dynamic-data-in-svelte-4102</link>
      <guid>https://dev.to/sonyarianto/simple-demo-fluent-ui-2-treeview-web-components-with-dynamic-data-in-svelte-4102</guid>
      <description>&lt;p&gt;In this simple demo we will show you how to integrate the object tree  structure into Microsoft Fluent UI 2 TreeView Web Components in Svelte. The tree structure only has single root.&lt;/p&gt;

&lt;p&gt;Check this out on this Svelte REPL link &lt;a href="https://svelte.dev/repl/317e16c270b84d2dba580f8a19445c92" rel="noopener noreferrer"&gt;https://svelte.dev/repl/317e16c270b84d2dba580f8a19445c92&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Good for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Anyone that confuse about integrating the data into the TreeView.&lt;/li&gt;
&lt;li&gt;Anyone that want to create a UI that has TreeView display.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enjoy the hacking.&lt;/p&gt;

</description>
      <category>fluent</category>
      <category>svelte</category>
      <category>treeview</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Demo of Mini PHP Framework (using Symfony routing and Blade template)</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Sat, 24 Jun 2023 10:59:36 +0000</pubDate>
      <link>https://dev.to/sonyarianto/demo-of-mini-php-framework-using-symfony-routing-and-blade-template-5h94</link>
      <guid>https://dev.to/sonyarianto/demo-of-mini-php-framework-using-symfony-routing-and-blade-template-5h94</guid>
      <description>&lt;p&gt;In this quick demo we will create mini PHP framework by using vanilla PHP plus Symfony routing component (to handle routing) and Blade template engine (to handle templating). Why? Why not. I just want to mix and match.&lt;/p&gt;

&lt;p&gt;See the skeleton demo here &lt;a href="https://github.com/sonyarianto/mini-php-framework" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/mini-php-framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enjoy the PHP coding.&lt;/p&gt;

</description>
      <category>php</category>
      <category>phpframework</category>
      <category>symfony</category>
      <category>blade</category>
    </item>
    <item>
      <title>Simple GitHub Actions Demo (update README.md content if a file updated)</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Sat, 24 Jun 2023 10:51:23 +0000</pubDate>
      <link>https://dev.to/sonyarianto/simple-github-actions-demo-update-readmemd-content-if-a-file-updated-24nm</link>
      <guid>https://dev.to/sonyarianto/simple-github-actions-demo-update-readmemd-content-if-a-file-updated-24nm</guid>
      <description>&lt;p&gt;I just want to share quick demo about how to use GitHub Actions for fun.&lt;/p&gt;

&lt;p&gt;The scenario is simple, I have a repo that contains &lt;code&gt;test.php&lt;/code&gt; and &lt;code&gt;README.md&lt;/code&gt; files. When I update the &lt;code&gt;test.php&lt;/code&gt; (means git push happen) it will update part of content in &lt;code&gt;README.md&lt;/code&gt; file with the content of &lt;code&gt;test.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;See the demo at &lt;a href="https://github.com/sonyarianto/github-actions-push-and-display-it-on-readme" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/github-actions-push-and-display-it-on-readme&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The workflow is on &lt;code&gt;.github/workflows/update-readme.yml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy the GitHub Actions.&lt;/p&gt;

</description>
      <category>github</category>
      <category>githubactions</category>
      <category>git</category>
    </item>
    <item>
      <title>Using Redux with Svelte and SvelteKit</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Sun, 18 Jun 2023 09:50:46 +0000</pubDate>
      <link>https://dev.to/sonyarianto/using-redux-with-svelte-and-sveltekit-28oc</link>
      <guid>https://dev.to/sonyarianto/using-redux-with-svelte-and-sveltekit-28oc</guid>
      <description>&lt;p&gt;Redux with Svelte is fun to use. We will play with Redux (Redux Toolkit) and Svelte this time. Why Redux Toolkit? Relax bro, Redux Toolkit is modern recommended way to use Redux. It's official from Redux team and it's already included with Redux package.&lt;/p&gt;

&lt;p&gt;I will give you 2 (two) repositories to play with. Both very simple to understand how Redux works using Svelte or SvelteKit.&lt;/p&gt;

&lt;p&gt;Just check it out at these.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sonyarianto/redux-with-svelte" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/redux-with-svelte&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/sonyarianto/redux-with-sveltekit" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/redux-with-sveltekit&lt;/a&gt;&lt;br&gt;
&lt;a href="https://svelte.dev/repl/778d2aab2e1e462d9da6f7cc3c7b62bb" rel="noopener noreferrer"&gt;https://svelte.dev/repl/778d2aab2e1e462d9da6f7cc3c7b62bb&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically both project is a simple counter application (increment and decrement) but this is essential to learn state management with Redux.&lt;/p&gt;

&lt;p&gt;No distraction guaranteed, no split files, all code in single file &lt;code&gt;src/App.svelte&lt;/code&gt; or &lt;code&gt;src/routes/+page.svelte&lt;/code&gt;. No CSS. Just focus on the code.&lt;/p&gt;

&lt;p&gt;Enjoy and I hope you like it.&lt;/p&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>redux</category>
      <category>vite</category>
    </item>
    <item>
      <title>Using Redux without Build Steps (a.k.a via CDN)</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Fri, 16 Jun 2023 06:56:08 +0000</pubDate>
      <link>https://dev.to/sonyarianto/using-redux-without-build-steps-aka-via-cdn-4bgc</link>
      <guid>https://dev.to/sonyarianto/using-redux-without-build-steps-aka-via-cdn-4bgc</guid>
      <description>&lt;p&gt;Learning Redux sometimes hard, even still hard for me, even harder if we just learn and never use it.&lt;/p&gt;

&lt;p&gt;Buy hey I just created a GitHub repository that contains educational material (a.k.a simple sample) about how to use Redux without any complexity.&lt;/p&gt;

&lt;p&gt;Check it out at &lt;a href="https://github.com/sonyarianto/redux-without-buildsteps" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/redux-without-buildsteps&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's called "Redux without Build Steps", it will show you about how to use the famous Redux just by using their CDN script. No installation, no &lt;code&gt;npm install&lt;/code&gt; things and all code is in a single HTML file, even we do not need a web server to run it.&lt;/p&gt;

&lt;p&gt;Hope you enjoy it learning Redux.&lt;/p&gt;

</description>
      <category>redux</category>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to use React without build steps or framework</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Wed, 31 May 2023 19:44:19 +0000</pubDate>
      <link>https://dev.to/sonyarianto/how-to-use-react-without-build-steps-5f9</link>
      <guid>https://dev.to/sonyarianto/how-to-use-react-without-build-steps-5f9</guid>
      <description>&lt;p&gt;Why React without build steps? Why not. Sometimes we are boring with doing &lt;code&gt;npm install&lt;/code&gt; bla bla bla. Let's doing React like jQuery things, just use CDN and run hahaha.&lt;/p&gt;

&lt;p&gt;Let's start.&lt;/p&gt;

&lt;p&gt;Just go to &lt;a href="https://github.com/sonyarianto/react-without-buildsteps" rel="noopener noreferrer"&gt;https://github.com/sonyarianto/react-without-buildsteps&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is single &lt;code&gt;index.html&lt;/code&gt; file there and without build steps means we just use CDN version for all of our React operation. That's includes the router and the Babel to handle the JSX code.&lt;/p&gt;

&lt;p&gt;Here is the CDN URLs that used on that projects.&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;script src="https://cdn.jsdelivr.net/npm/react@18.2.0/umd/react.production.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/react-dom@18.2.0/umd/react-dom.production.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/@remix-run/router@1.6.2/dist/router.umd.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/react-router@6.11.2/dist/umd/react-router.production.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/react-router-dom@6.11.2/dist/umd/react-router-dom.production.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.22.4/babel.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then finally the demo is on&lt;/p&gt;

&lt;p&gt;&lt;a href="https://react-without-buildsteps.vercel.app/" rel="noopener noreferrer"&gt;https://react-without-buildsteps.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoy it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Read the remake version of this article at &lt;a href="https://corner.buka.sh/building-react-applications-without-a-build-step-a-simple-approach/" rel="noopener noreferrer"&gt;Buka Corner&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>cdn</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Jogja, the project generator for web frameworks</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Sat, 08 Apr 2023 14:23:44 +0000</pubDate>
      <link>https://dev.to/sonyarianto/jogja-the-project-generator-for-web-frameworks-3keo</link>
      <guid>https://dev.to/sonyarianto/jogja-the-project-generator-for-web-frameworks-3keo</guid>
      <description>&lt;p&gt;Every web framework usually has its own CLI to generate project. Let say Next.js has &lt;code&gt;npx create-next-app@latest&lt;/code&gt; or Vue.js has &lt;code&gt;npm init vue@latest&lt;/code&gt;. Jogja makes create project easy for many web frameworks by using interactive menu.&lt;/p&gt;

&lt;h2&gt;
  
  
  Screenshot
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fik00jhat5xkvaxuox78y.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fik00jhat5xkvaxuox78y.jpg" alt="jogja in action" width="800" height="614"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It supports many famous and popular JavaScript web frameworks at the moments, such as Next.js, Vue.js, SvelteKit, Remix, Astro, AdonisJS and many more.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -g jogja
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will install &lt;code&gt;jogja&lt;/code&gt; globally and after finish you can call &lt;code&gt;jogja&lt;/code&gt; on your command prompt.&lt;/p&gt;

&lt;p&gt;Just think &lt;code&gt;jogja&lt;/code&gt; like an aggregator of create project CLI for many web framework to make create project easy and interactive way. Basically &lt;code&gt;jogja&lt;/code&gt; will only run the each framework CLI command to create the new project.&lt;/p&gt;

&lt;p&gt;That's it. Thanks for reading.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>cli</category>
      <category>framework</category>
      <category>tooling</category>
    </item>
    <item>
      <title>PHP Tips: How to Read Remote Text File and Download to Local</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Wed, 25 Mar 2020 09:02:02 +0000</pubDate>
      <link>https://dev.to/sonyarianto/php-tips-how-to-read-remote-text-file-and-download-to-local-11j8</link>
      <guid>https://dev.to/sonyarianto/php-tips-how-to-read-remote-text-file-and-download-to-local-11j8</guid>
      <description>&lt;p&gt;Who still use PHP? Raise your hand! Hahaha. OK, because of self-explanatory title, here is how to do it. We will use several functions on PHP for this purpose, such as &lt;code&gt;fopen&lt;/code&gt;, &lt;code&gt;feof&lt;/code&gt;, &lt;code&gt;fgets&lt;/code&gt;, &lt;code&gt;fwrite&lt;/code&gt; and &lt;code&gt;fclose&lt;/code&gt; functions. Yes, that's lower level functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenario
&lt;/h2&gt;

&lt;p&gt;Suppose we have remote text file stored on a website, let's called it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://bolabanget.id/myfile.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We want to create a PHP script that download that file (&lt;code&gt;myfile.json&lt;/code&gt;) to our local computer with name (&lt;code&gt;myfile.local.json&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Here is the script.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code
&lt;/h2&gt;

&lt;p&gt;File: &lt;code&gt;download_file.php&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c1"&gt;// open the source file with read-only mode&lt;/span&gt;
&lt;span class="nv"&gt;$source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;fopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://bolabanget.id/myfile.json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"r"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Unable to open file!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// prepare local file with write mode (if not exists it will try to create one)&lt;/span&gt;
&lt;span class="nv"&gt;$target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;fopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'myfile.local.json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'w'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="k"&gt;die&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Unable to open file"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// prepare variable for content of the source file&lt;/span&gt;
&lt;span class="nv"&gt;$content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// tests for end-of-file on a source file pointer&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;feof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$source&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// fgets will get line from file pointer&lt;/span&gt;
  &lt;span class="nv"&gt;$content&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;fgets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$source&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// write the $content variable to target file handle&lt;/span&gt;
&lt;span class="nb"&gt;fwrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// close all open files from our operation above&lt;/span&gt;
&lt;span class="nb"&gt;fclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$source&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;fclose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php download_file.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything OK, you should have file &lt;code&gt;myfile.local.json&lt;/code&gt; on your current folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternative Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/hepisec"&gt;@hepisec&lt;/a&gt; comes with additional alternative on comments, we can do above task as well with the following code. This code using higher level functions such as &lt;code&gt;file_get_contents&lt;/code&gt; and &lt;code&gt;file_put_contents&lt;/code&gt;. Thank you!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nv"&gt;$src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;file_get_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://bolabanget.id/myfile.json'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;file_put_contents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'myfile.local.json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$src&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you enjoy it and any additional code or comments are welcome.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;PHP Documentation at &lt;a href="https://www.php.net/manual/en/" rel="noopener noreferrer"&gt;https://www.php.net/manual/en/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cover photo by Christina Morillo at &lt;a href="https://www.pexels.com/photo/two-women-looking-at-the-code-at-laptop-1181263/" rel="noopener noreferrer"&gt;https://www.pexels.com/photo/two-women-looking-at-the-code-at-laptop-1181263/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Thanks to &lt;a href="https://dev.to/hepisec"&gt;@hepisec&lt;/a&gt; for the additional code&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
      <category>beginners</category>
    </item>
    <item>
      <title>PHP Quick Tip: How to check loaded extensions on CLI</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Wed, 26 Feb 2020 03:41:15 +0000</pubDate>
      <link>https://dev.to/sonyarianto/php-quick-tip-how-to-check-loaded-extensions-on-cli-37bf</link>
      <guid>https://dev.to/sonyarianto/php-quick-tip-how-to-check-loaded-extensions-on-cli-37bf</guid>
      <description>&lt;p&gt;Suppose we have PHP installed on our machine and we want to quick check what extensions loaded on our PHP. Plus you just want to know through CLI. It's easy.&lt;/p&gt;

&lt;p&gt;Usually I just type this.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;It will display complete information about PHP and all its configuration. It is similar like we call &lt;code&gt;phpinfo()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;The second is typing this 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 -r "print_r(get_loaded_extensions());"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will display loaded extensions only. The result example is like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Array
(
    [0] =&amp;gt; Core
    [1] =&amp;gt; date
    [2] =&amp;gt; libxml
    [3] =&amp;gt; openssl
    [4] =&amp;gt; pcre
    [5] =&amp;gt; zlib
    [6] =&amp;gt; filter
    [7] =&amp;gt; hash
    [8] =&amp;gt; pcntl
    [9] =&amp;gt; Reflection
    [10] =&amp;gt; SPL
    [11] =&amp;gt; sodium
    [12] =&amp;gt; session
    [13] =&amp;gt; standard
    [14] =&amp;gt; mysqlnd
    [15] =&amp;gt; PDO
    [16] =&amp;gt; xml
    [17] =&amp;gt; bcmath
    [18] =&amp;gt; calendar
    [19] =&amp;gt; ctype
    [20] =&amp;gt; curl
    [21] =&amp;gt; dom
    [22] =&amp;gt; mbstring
    [23] =&amp;gt; fileinfo
    [24] =&amp;gt; ftp
    [25] =&amp;gt; gd
    [26] =&amp;gt; gettext
    [27] =&amp;gt; iconv
    [28] =&amp;gt; igbinary
    [29] =&amp;gt; imap
    [30] =&amp;gt; json
    [31] =&amp;gt; exif
    [32] =&amp;gt; msgpack
    [33] =&amp;gt; mysqli
    [34] =&amp;gt; pdo_mysql
    [35] =&amp;gt; Phar
    [36] =&amp;gt; posix
    [37] =&amp;gt; readline
    [38] =&amp;gt; shmop
    [39] =&amp;gt; SimpleXML
    [40] =&amp;gt; sockets
    [41] =&amp;gt; sysvmsg
    [42] =&amp;gt; sysvsem
    [43] =&amp;gt; sysvshm
    [44] =&amp;gt; tokenizer
    [45] =&amp;gt; wddx
    [46] =&amp;gt; xmlreader
    [47] =&amp;gt; xmlwriter
    [48] =&amp;gt; xsl
    [49] =&amp;gt; memcached
    [50] =&amp;gt; Zend OPcache
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thank you and I hope you enjoy it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Cover image Pencil Shred by Pixabay from &lt;a href="https://www.pexels.com/photo/cake-candy-celebration-chocolate-261738/" rel="noopener noreferrer"&gt;https://www.pexels.com/photo/cake-candy-celebration-chocolate-261738/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>php</category>
      <category>tip</category>
      <category>cli</category>
    </item>
    <item>
      <title>How to add git branch name to shell prompt in Ubuntu</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Sat, 11 Jan 2020 12:28:17 +0000</pubDate>
      <link>https://dev.to/sonyarianto/how-to-add-git-branch-name-to-shell-prompt-in-ubuntu-1gdj</link>
      <guid>https://dev.to/sonyarianto/how-to-add-git-branch-name-to-shell-prompt-in-ubuntu-1gdj</guid>
      <description>&lt;p&gt;When I work in a git repository directory that has many branches, I want to know which branch I am currently in on my shell prompt. Below is the sample output result.&lt;/p&gt;

&lt;p&gt;Before my shell prompt is like this. Note suppose I am on folder &lt;code&gt;~/general/repos/playground&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sony@ubuntu:~/general/repos/playground$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will create like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sony@ubuntu:~/general/repos/playground (master)$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On above example, I am on my &lt;code&gt;playground&lt;/code&gt; git repository directory and it display the branch name &lt;code&gt;master&lt;/code&gt;. It means I am on &lt;code&gt;master&lt;/code&gt; branch now.&lt;/p&gt;

&lt;p&gt;Today I will share how to create it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scenario
&lt;/h2&gt;

&lt;p&gt;I want to add git branch name to my shell prompt when I am in a project repository directory. I am using Ubuntu, so the default shell is &lt;code&gt;bash&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-step to go there
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; Go to your shell prompt first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; We have to know the current prompt setting, type like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo $PS1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;$PS1 is the enviroment variable that store the default prompt setting we see every time when we log in the console.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;On mine, the setting is like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks great.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; Open file &lt;code&gt;~/.bashrc&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vi ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; Add this function on the bottom of your &lt;code&gt;~/.bashrc&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git_branch&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  git branch 2&amp;gt; /dev/null | &lt;span class="nb"&gt;sed&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'/^[^*]/d'&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s1"&gt;'s/* \(.*\)/(\1)/'&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5.&lt;/strong&gt; Add this on the bottom of your &lt;code&gt;~/.bashrc&lt;/code&gt; file. Add the &lt;code&gt;git_branch&lt;/code&gt; function on the shell prompt, by adding it on &lt;code&gt;PS1&lt;/code&gt; variable. Sample like below (that based on my &lt;code&gt;$PS1&lt;/code&gt; output above).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \$(git_branch)\$ "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6.&lt;/strong&gt; You are done. Now save the file &lt;code&gt;~/.bashrc&lt;/code&gt; and run this command to reflect the changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can close the terminal and re-open again to reflect the changes.&lt;/p&gt;

&lt;p&gt;Now on my shell prompt will display like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sony@ubuntu:~/general/repos/playground (master)$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add color to make it better
&lt;/h2&gt;

&lt;p&gt;This is just additional cosmetics things. I will make the branch indicator &lt;code&gt;(master)&lt;/code&gt; to green for foreground color. Add this &lt;code&gt;\[\033[00;32m\]\$(git_branch)\[\033[00m\]&lt;/code&gt; to your &lt;code&gt;PS1&lt;/code&gt; variable. On mine is like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[\033[00;32m\]\$(git_branch)\[\033[00m\]\$ "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;Thank you and I hope you enjoy it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikibooks.org/wiki/Guide_to_Unix/Explanations/Shell_Prompt" rel="noopener noreferrer"&gt;https://en.wikibooks.org/wiki/Guide_to_Unix/Explanations/Shell_Prompt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.shellhacks.com/show-git-branch-terminal-command-prompt/" rel="noopener noreferrer"&gt;https://www.shellhacks.com/show-git-branch-terminal-command-prompt/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://linoxide.com/how-tos/change-bash-prompt-variable-ps1/" rel="noopener noreferrer"&gt;https://linoxide.com/how-tos/change-bash-prompt-variable-ps1/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://askubuntu.com/questions/590899/how-do-i-check-which-shell-i-am-using" rel="noopener noreferrer"&gt;https://askubuntu.com/questions/590899/how-do-i-check-which-shell-i-am-using&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Cover image is photo by Adrianna Calvo from Pexels at &lt;a href="https://www.pexels.com/photo/sea-nature-beach-sand-21859/" rel="noopener noreferrer"&gt;https://www.pexels.com/photo/sea-nature-beach-sand-21859/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>shell</category>
      <category>productivity</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>How to start PHP built-in web server along with setting environment variable</title>
      <dc:creator>Sony AK</dc:creator>
      <pubDate>Wed, 08 Jan 2020 04:58:15 +0000</pubDate>
      <link>https://dev.to/sonyarianto/how-to-start-php-built-in-web-server-along-with-setting-environment-variable-3905</link>
      <guid>https://dev.to/sonyarianto/how-to-start-php-built-in-web-server-along-with-setting-environment-variable-3905</guid>
      <description>&lt;p&gt;I often use PHP built-in web server for my PHP projects during testing and development phase. The PHP projects in many cases using environment variable to define configuration or controlling app behaviour (e.g. running on prod or test environment).&lt;/p&gt;

&lt;h2&gt;
  
  
  Usual way
&lt;/h2&gt;

&lt;p&gt;Setting environment variable can be done like this on Linux.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export NAME=VALUE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Start server with setting environment variables
&lt;/h2&gt;

&lt;p&gt;If you want to set environment variable during the start of PHP built-in web server just type like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MYENV=myvalue php -S 0.0.0.0:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For setting multiple environment variables can be done like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MYENV=myvalue MYOTHERENV=myothervalue php -S 0.0.0.0:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If above not working, try this one as well.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MYENV=myvalue php -d variables_order=EGPCS -S 0.0.0.0:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On PHP you can get the environment variable with this code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
  &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nb"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MYENV'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Windows you can do that via git-bash shell.&lt;/p&gt;

&lt;p&gt;Thank you and I hope you enjoy it.&lt;/p&gt;

</description>
      <category>php</category>
      <category>productivity</category>
      <category>tip</category>
    </item>
  </channel>
</rss>
