<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by HELLO ME. on Medium]]></title>
        <description><![CDATA[Stories by HELLO ME. on Medium]]></description>
        <link>https://medium.com/@leakhand?source=rss-bc5fa83a7e16------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by HELLO ME. on Medium</title>
            <link>https://medium.com/@leakhand?source=rss-bc5fa83a7e16------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:11:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leakhand/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Travel to Koh Phangan from Koh Samui Airport: Songserm Guide]]></title>
            <link>https://medium.com/@leakhand/travel-to-koh-phangan-from-koh-samui-airport-songserm-guide-3491330754d2?source=rss-bc5fa83a7e16------2</link>
            <guid isPermaLink="false">https://medium.com/p/3491330754d2</guid>
            <dc:creator><![CDATA[HELLO ME.]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 10:18:41 GMT</pubDate>
            <atom:updated>2024-04-04T10:18:41.809Z</atom:updated>
            <content:encoded><![CDATA[<h3>Travel to Koh Phangan from Koh Samui Airport: Songserm Guide</h3><p>Imagine you’ve just landed amid the tranquil beauty of Koh Samui ready to discover its neighboring isle’s allure.</p><p>Travel is akin to turning the pages of a vivid narrative; each destination is a fresh chapter brimming with potential experiences. Koh Phangan, nestled like a gem in the Gulf of Thailand, beckons with its vibrant culture and serene beaches, similar to an undiscovered verse yearning to be read. As you prepare to journey from <a href="https://songserm.com/booking?from=USM&amp;to=PNG&amp;endDate=2024-04-04">Koh Samui</a> Airport to this idyllic retreat, let the Songserm guide become your trusted compass.</p><h3>Choosing Your Songserm Connection</h3><p>Selecting the optimal Songserm ferry service to traverse the shimmering waters from Koh Samui to Koh Phangan is a crucial decision for the discerning traveler. An informed choice involves considering departure times from Koh Samui that best align with your schedule, ensuring seamless integration with your onward travel plans. Timeliness, frequency of service, and alignment with local tide conditions are paramount considerations when booking. Additionally, assessing the type of vessel and available amenities can significantly enhance your sea passage, allowing for a comfortable and memorable experience as you voyage towards the enchanting shores of Koh Phangan.</p><h3>Analyzing Ferry Schedules and Prices</h3><p>Understanding the intricacies of ferry schedules is essential. Frequencies vary with seasons and demand, influencing travel plans. Prices fluctuate, reflecting service levels, comforts, and voyage duration.</p><p>Navigating fare structures is paramount for cost-efficiency. Economy class offers basic amenities, while upgraded classes provide enhanced comfort. Comparing different service tiers ensures the best value for each traveler’s preferences.</p><blockquote><a href="https://songserm.com/"><em>Koh Phangan’s Full Moon Parties</em></a><em> catalyze peak ferry travel periods.</em></blockquote><p>Deciphering the timetable’s nuances requires attention to detail. Departures are carefully timed; aligning with flights ensures smooth transitions. Peak travel times often see increased prices and demand, necessitating early bookings to secure seats and desirable rates.</p><h3>Booking Transfer Tickets: Online vs. Onsite</h3><p>Procuring your transportation tickets in advance through digital platforms offers the convenience of arranging travel from any locale. Online booking secures spots before arrival, averting potential unavailability.</p><p>Onsite ticket purchase poses risks of full ferries, especially during elevated travel seasons. Agile planning, therefore, may hinge on pre-departure arrangements.</p><p>When evaluating the merits of online versus onsite ticketing, consider the immediacy of your travel needs juxtaposed against the probability of service saturation. Online reservations afford a buffer against the unforeseen, anchoring travel plans with confirmed availability.</p><p>Navigating the digital realm for ticket bookings furnishes travelers with copious information, from meticulous schedules to navigational advisories. Onsite, while immediate, lacks depth, compelling passengers to often rely on agile decision-making under suboptimal condition. In essence, online bookings are a bulwark against the unpredictability of travel, securing passage ahead of the mutable landscapes of demand.</p><h3>Understanding Koh Phangan’s Allure</h3><p>Koh Phangan embodies an enigmatic charm, far beyond its paradisiacal beaches and cerulean waters. It beckons travelers seeking Thailand’s quintessential island experience.</p><p>At its core lies a tapestry of cultural festivities, including the world-famous Full Moon Party, a magnet for revellers drawn to its shores for unforgettable nocturnal jubilations. Koh Phangan’s topography also unfolds a haven for nature enthusiasts, boasting verdant jungles backed by a symphony of cascading waterfalls.</p><p>The island’s reputation for wellness and spirituality captivates those pursuing tranquility. Yoga retreats and meditation centers dot the landscape, offering serene sanctuaries amidst its tropical allure.</p><h3>Pristine Beaches and Full Moon Parties</h3><p>Koh Phangan is synonymous with pristine beaches, each offering a unique blend of tranquility and scenic beauty under sunny skies. Secluded bays provide a serene escape, while livelier stretches brim with captivating shoreline activities.</p><p>The <a href="https://songserm.com/">Full Moon Party</a> is a global phenomenon, attracting revelers to Haad Rin’s luminescent sands. Enticed by the allure of vibrant celebrations, visitors from across the globe unite under the silvery glow of the moon.</p><p>Indeed, these lunar soirées serve as the pinnacle of the island’s nocturnal revelry, often accompanied by an array of music genres and mesmerizing fire shows.</p><p>Beyond nocturnal festivities, daylight reveals an array of hidden coves and expansive beaches, where azure waters lap against powdery white sands. Sojourners can indulge in moments of quietude or partake in exhilarating water sports.</p><p>Visitors seeking reprieve from the revelry find solace in the island’s less frequented shores. These secluded spots offer an idyllic environment for relaxation, providing a stark contrast to the electrifying ambiance of the Full Moon festivities.</p><p>Ultimately, the island’s appeal lies not only in its vibrant parties but also its coastal sanctuaries. Koh Phangan’s diverse shoreline offers various atmospheres, from the serene to the exhilarating, catering to every traveler’s preference.</p><h3>Serene Sanctuaries and Adventure Activities</h3><p>Koh Phangan is a mosaic of tranquil sanctuaries and thrilling adventure options, each offering a unique experience.</p><ol><li><strong>Wat Phu Khao Noi</strong> — A haven of spirituality and the oldest temple on the island, promising peace and introspection.</li><li><strong>Thong Nai Pan Beaches</strong> — Twin bays with soft sands and crystal waters, perfect for a serene retreat.</li><li><strong>Than Sadet Waterfall National Park</strong> — A historic site with cascading waters amidst lush greenery, ideal for nature lovers.</li><li><strong>The Challenge Phangan</strong> — An adrenaline-fueled obstacle course over water that tests endurance and skill.</li><li><strong>Sunrise Yoga Sessions</strong> — Holistic wellness activities set against the backdrop of Koh Phangan’s stunning scenery.</li></ol><p>Amidst verdant landscapes, these sanctuaries offer a deep connection with nature.</p><p>The array of adventures will satiate the appetite of both thrill-seekers and serenity-searchers alike.</p><h3>Navigating Samui Airport Arrival</h3><p>Upon disembarking at Samui Airport, visitors are greeted by a uniquely open-air terminal design, fostering a seamless transition to the exotic environment outside. With clear signage and attentive staff, navigation is straightforward, leading you efficiently to baggage claim and transfer services.</p><p>As you collect your belongings, take a moment to acquaint yourself with the airport’s amenities. Currency exchange booths and tourist information desks are conveniently situated for immediate assistance. For onward travel to Koh Phangan, locate the Songserm counter where you will receive guidance for your ferry connection, ensuring a smooth continuation of your journey.</p><h3>From Plane to Pier: Transportation Essentials</h3><p>Upon arrival at Samui Airport, anticipate a swift segue to maritime transit. The destination within your grasp, your next step is the transfer to the pier where your sea journey commences.</p><p>Seamlessly, after reclaiming luggage, a dedicated pathway shepherds travelers to a waiting area where the transfer to the pier is coordinated. Representatives from various transfer services, including Songserm, are readily available, offering options that include combined tickets for both the land shuttle and ferry crossing. This integrated approach simplifies the transition and curtails the need for multiple transactions.</p><p>Consequently, a swift and reliable transfer is of paramount importance. With Songserm, expect punctual and comfortable transport options that align with ferry departure times, ensuring travelers experience minimal delay in reaching the pier. Their streamlined service alleviates the stress of coordinating separate legs of travel and imbues confidence in your next steps.</p><p>Finally, the transfer encapsulates a journey that is not merely functional but also imbues a preview of the scenic splendor ahead. As you traverse from the airport to pier with Songserm, the landscapes unfold, setting the tone for the tropical escapade that awaits. Diligent preparation on the part of Songserm guarantees that travelers can embark on this segment with assurance, their anticipation for Koh Phangan’s allure only heightening with each passing mile.</p><h3>Understanding Airport Amenities and Services</h3><p>Koh Samui Airport stands out with its open-air design, blending modern facilities seamlessly within a tropical environment. The layout fosters a serene atmosphere prior to your departure to Koh Phangan.</p><p>Within the terminal, passengers discover a comprehensive suite of amenities tailored to enhance their comfort. Boasting boutique shops, a selection of eateries, currency exchange services, and Wi-Fi access, the airport ensures your wait is as pleasant as possible. Ground services remain attentive to passenger needs, offering assistance and guiding individuals smoothly towards their onward connections.</p><p>Your transit experience includes access to clean and well-maintained restroom facilities, essential for freshening up before the journey ahead. Departure lounges provide ample space to relax, and charging stations are readily available to keep your electronic devices powered and prepared for the adventure ahead.</p><p>Moreover, professional staff offer information on flight statuses and travel tips for your island destination. Their expertise ensures you remain well-informed and confidently equipped as you conclude your airport visit and proceed to the Songserm ferry for the final leg of your journey to Koh Phangan, where paradise beachfront and vibrant festivities await your arrival.</p><h3>Preparing for the Cross-Sea Journey</h3><p>Ensure your provisions align with the maritime journey ahead. Light, water-resistant clothing, appropriate sun protection, and sea-sickness prevention measures are advisable. It is paramount to stay hydrated and apply sunscreen to fend off the tropical sun’s effects over the open water.</p><p>Confirm your tickets and schedule to ensure a seamless transfer from Samui Airport to the pier. This logistical preparation is the foundation of a stress-free crossing, allowing you to transition smoothly to the next phase of your travels.</p><h3>Essential Packing Tips for Ferry Travel</h3><p>Efficient packing is crucial for a comfortable and hassle-free ferry journey.</p><ol><li><strong>Lightweight Clothing</strong>: Opt for breathable fabrics that provide comfort and ease of movement.</li><li><strong>Water-Resistant Gear</strong>: Include a rain jacket or poncho to stay dry during unexpected showers.</li><li><strong>Sun Protection</strong>: Arm yourself with high-SPF sunscreen, a wide-brimmed hat, and sunglasses.</li><li><strong>Seasickness Remedies</strong>: Have ginger candies or motion sickness medication on hand, should the need arise.</li><li><strong>Hydration Essentials</strong>: Pack a reusable water bottle to maintain hydration throughout the voyage.</li><li><strong>Power Banks</strong>: Ensure you have sufficient battery life for your devices with fully charged power banks.</li><li><strong>Essential Documents</strong>: Keep passports, tickets, and reservations readily accessible yet secure.</li><li><strong>Snacks and Entertainment</strong>: Bring light snacks and activities like a book or download music for relaxation.</li></ol><p>Adapt your luggage content to the maritime environment for a more enjoyable experience.</p><p>Carefully chosen items can mitigate common sea travel issues, enhancing your overall voyage comfort.</p><h3>Onboard Expectations and Traveler Etiquette</h3><p>Aboard the Songserm ferry, adherence to etiquette ensures a harmonious journey for all passengers.</p><ol><li><strong>Boarding Promptness</strong>: Arrive at the designated assembly point well before departure to avoid delays.</li><li><strong>Luggage Consideration</strong>: Stow baggage in designated areas, keeping walkways and exits clear.</li><li><strong>Noise Levels</strong>: Maintain a low volume during conversations and when using electronic devices.</li><li><strong>Seat Preservation</strong>: Respect assigned seating arrangements and refrain from occupying unassigned seats.</li><li><strong>Environmental Respect</strong>: Dispose of waste properly and participate in eco-friendly practices aboard.</li></ol><p>Upholding these guidelines will contribute to a seamless and pleasant travel experience.</p><p>Upon embarkation, courteous interactions with crew and fellow travelers are expected and appreciated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3491330754d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node TDD]]></title>
            <link>https://medium.com/@leakhand/node-tdd-a3e3d333dc86?source=rss-bc5fa83a7e16------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3e3d333dc86</guid>
            <dc:creator><![CDATA[HELLO ME.]]></dc:creator>
            <pubDate>Sun, 19 Mar 2017 07:25:22 GMT</pubDate>
            <atom:updated>2019-01-10T15:03:24.977Z</atom:updated>
            <content:encoded><![CDATA[<p>เขียน TDD [Test Driven Development]</p><p>วันนี้ผมจะมาสรุปคร่าวๆ ในการเริ่มต้นเขียน Test ด้วย Mocha, Chai บน Node กันนะครับ</p><h3>Installation</h3><p>ก่อนอื่นให้เราติดตั้ง Yeoman ด้วยคำสั่ง [ถ้ามีแล้วก็ข้ามไป]</p><pre>$ npm install -g yo</pre><h3>Generator-Test</h3><p>จากนั้นก็ติดตั้งตัว Yo Generator ที่ชื่อว่่า: generator-test ด้วยคำสั่ง</p><pre>$ npm install -g generator-test</pre><p>เสร็จแล้วผมจะเริ่มทำการสร้าง Project Test ในตัวอย่างนี้ผมจะใช้ Visual Studio Code เป็น IDE :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w3tOJUleEOv3BiG9F9TYqA.png" /></figure><p>จากนั้นให้ไปยัง folder ของ project และทำการ run command</p><pre>$ yo test</pre><p>หน้าจอจะแสดงผลตามภาพ ให้เลือก Node และตั้งชื่อ project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GTw-TenQvd3nYdbyPpKOHw.png" /></figure><p>หลังจากนั้นรอซักครู่จะได้ ไฟล์เริ่มต้นมาดังภาพ จะเห็นว่ามีส่วนประกอบที่สำคัญอยู่สองส่วนคือ ไฟล์ ข้างในที่ชื่อ ./spec/nodeDayOne.js [ตามชื่อ project]<br>และไฟล์ที่ root ที่ชื่อว่า ./nodeDayOne.js File ในโฟลเดอร์ spec จะเอาไว้สำหรับเขียนเทส ส่วนไฟล์ทีต้องการเทส อยู่ที่เรากำหนดเช่นกัน default จะเป็นตามข้างบนตามที่บอก โดยเราสามารถไปแก้ไขได้ที่ไฟล์ package.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*du3sJ1ojRGHlpFgzc3Yp0w.png" /></figure><p>ลองเปิดไฟล์ package.json ให้ดูในส่วน scripts -&gt; test ผมแก้จาก nodeDayOne.js ไปเป็น *.js เพื่อที่จะได้ไม่ต้องคอยแก้ชื่อไฟล์เวลาเทส</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JeJPDKbXHxHtHvy7eYpOVQ.png" /></figure><p>จากนั้นให้ ทดสอบการรันเทสด้วยคำสั่ง</p><pre>$ npm test</pre><p>จะปรากฏดังภาพถือว่าการตั้งค่าเริ่มต้นถูกต้องหมดละ ทีนี้เราจะลบไฟล์ default ที่มีมาตั้งแต่แรกออกคือ nodeDayOne.js กับ spec/nodeDayOne.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqCcOXzzJNJi1Xwq8FO-Lw.png" /></figure><h3>ลองเขียน Test Calculator กันดู</h3><ol><li>สร้างไฟล์ ./spec/calculator.js</li></ol><p>เริ่มต้นด้วยการใช้ BDD style expect/should <a href="http://chaijs.com/api/bdd/">รายละเอียดเพิ่มเติม</a></p><p>การเขียน TDD ผมจะเริ่มจาก Red — Green — Refactoring</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*c3Y9ok-nPQzuaCpl9Kc_PQ.png" /><figcaption>Red-Green-Refactoring</figcaption></figure><pre>var expect = require(&#39;mocha&#39;).expect;</pre><p>และตามด้วย การเขียน function การบวกเลข</p><pre>describe(&#39;Add&#39;, function(){</pre><pre>    it(&#39;Should be 1&#39;, function(){</pre><pre>        expect(<strong>calculator</strong>.add(1, 0)).to.equal(1);</pre><pre>    })</pre><pre>})</pre><p>ทดสอบรันเทส จะได้ผล Error ตามนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-icSGrOGNglr1ZWwK_2cA.png" /></figure><p>จาก Error นั้นแจ้งว่า calculator is not defined หมายความว่าเรายังไม่ได้กำหนดที่มาที่ไปให้กับตัวแปร calculator ซึ่งในที่นี้คือตัว Calculator Class ที่เรายังไม่ได้สร้าง</p><p>สร้าง Calculator Class ตามตัวอย่างผมสร้างไว้ที่ ./libs/Calculator.js</p><pre>&#39;use strict&#39;;</pre><pre>module.exports = class Calculator {</pre><pre>}</pre><p>จากนั้นกลับมาแก้ไขโค๊ดในไฟล์ ./spec/calculator.js เป็นแบบนี้ <strong>ตัวหนาคือส่วน code ที่เพิ่มเข้ามา</strong></p><pre><strong>var path = require(&#39;path&#39;);</strong></pre><pre>var expect = require(&#39;chai&#39;).expect;</pre><pre><strong>var Calculator = require(path.join(__dirname, &#39;..&#39;, &#39;./libs/Calculator.js&#39;));</strong></pre><pre><strong>var calculator = new Calculator();<br></strong></pre><pre>describe(&#39;Add&#39;, function(){</pre><pre>    it(&#39;Should be 1&#39;, function(){</pre><pre>        expect(calculator.add(1, 0)).to.equal(1);</pre><pre>    })</pre><pre>})</pre><p>จากนั้นให้ลองรัน test อีกครั้งด้วย <strong>npm test </strong>จะเห็นว่า Error เปลี่ยนไปเป็น calculator.add is not a function หมายความว่าตอนนี้เจอ calculator แล้วแต่ไม่เจอ function <strong>add()</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PoiTiiz-jnZ6PRQ-VYh-7Q.png" /><figcaption>TypeError: calculator.add is not a function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSn2A1tSnr-hwa5Ww0QCcw.png" /></figure><p>แก้ไขไฟล์ ./libs/Calculator.js เป็นดังนี้ โดยการเพิ่ม function add</p><pre>&#39;use strict&#39;;</pre><pre>module.exports = class Calculator {<br>   <br><strong>   add(a, b) {</strong></pre><pre><strong>   }</strong></pre><pre>}</pre><p>จากนั้นรัน npm test อีกครั้ง จะเห็นว่า Error เปลี่ยนไปเป็น AssertionError: expected undefined to equal 1 หมายความว่า ค่าที่ได้กลับมาจากการเรียกใช้ function add เป็นค่า undefined</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d06iuO5EAm7B2Im2N2eJgQ.png" /><figcaption>AssertionError: expected undefined to equal 1</figcaption></figure><p>จากนั้นให้แก้ไขเป็น return ค่าที่เรา expect ไว้คือ 1</p><pre>&#39;use strict&#39;;</pre><pre>module.exports = class Calculator {<br>   <br>   add(a, b) {<br>    <strong>return 1;<br></strong>   }</pre><pre>}</pre><p>และทดสอบการรัน test อีกครั้ง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Vx8AYfOBZbz6iuMk3QM8Q.png" /><figcaption>Green</figcaption></figure><p>มาถึงส่วนนี้แสดงว่า การเขียน Code ในส่วน Test เราทำได้ถูกต้องแล้ว ต่อจากนี้คือการ <strong>Refactor Code</strong> ที่เราใช้งานกับ Application ของเราซึ่งการแก้ไขในส่วนนี้จะไม่เกี่ยวข้องกับ Test ที่เรากำหนดไว้หมายความว่าถ้าการแก้ไขใดๆก็ตามที่แก้แล้วได้ Fail นั้นคือการเขียน Logic Condition ที่เราใช้งานนั้นผิด</p><p><strong>พิสูจน์ด้วยการเพิ่ม Test case</strong></p><p>เพิ่มเคส 1+1 จากนั้นทดสอบรัน</p><pre>var path = require(&#39;path&#39;);</pre><pre>var expect = require(&#39;chai&#39;).expect;</pre><pre>var Calculator = require(path.join(__dirname, &#39;..&#39;, &#39;./libs/Calculator.js&#39;));</pre><pre>var calculator = new Calculator();</pre><pre>describe(&#39;Add&#39;, function(){</pre><pre>    it(&#39;Should be 1&#39;, function(){<br>        expect(calculator.add(1, 0)).to.equal(1);<br>    })<br></pre><pre><strong>    it(&#39;<em>Should be 2</em>&#39;, function(){<br>        expect(calculator.add(<em>1, 1</em>)).to.equal(<em>2</em>);<br>    })</strong></pre><pre>})</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M2SU94ZAM--hbJK0OyP2iw.png" /><figcaption>AssertionError: expected 1 to equal 2</figcaption></figure><p>ผลลัพธ์ที่ได้คือ Test Fail แสดงว่า Logical ในส่วนของ ./libs/Calculator.js เราผิด สิ่งที่ต้องทำต่อคือการ Refactoring Code เพิ่มเติม และลองรันดูอีกที</p><pre>&#39;use strict&#39;;</pre><pre>module.exports = class Calculator {<br>   <br>   add(a, b) {<br>    <strong>return a + b;<br></strong>   }</pre><pre>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wKV1_ZlwZFR4GYvL-YGc0A.png" /><figcaption>test success</figcaption></figure><p>จากภาพด้านบนจะเห็นได้ว่า Success หมดแล้วถ้าหากว่าเรามีเคสอื่นที่เราอยากทดสอบเพิ่มก็สามารถเพิ่มเติมได้ตามวิธีด้านบน หากเพิ่มเคสใดๆ เพิ่มเติมแล้ว ผลลัพธ์ Fail สิ่งที่ต้องทำเพิ่มก็คือการ Refactoring ในส่วน Logical ของเรานั่นเองไม่เกี่ยวข้องการการแก้ไข Test Case</p><p>GitLab : <a href="https://gitlab.com/yotewach/NodeDayOne">https://gitlab.com/yotewach/NodeDayOne</a></p><p>Credit : <a href="http://quintagroup.com/services/python/test-driven-development">http://quintagroup.com/services/python/test-driven-development</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3e3d333dc86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ASP.NET Core with EF and MySQL]]></title>
            <link>https://medium.com/@leakhand/asp-net-core-with-ef-and-mysql-ccd52752b1c9?source=rss-bc5fa83a7e16------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccd52752b1c9</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[csharp]]></category>
            <category><![CDATA[entity-framework]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[HELLO ME.]]></dc:creator>
            <pubDate>Tue, 20 Dec 2016 15:58:53 GMT</pubDate>
            <atom:updated>2016-12-20T16:23:19.347Z</atom:updated>
            <content:encoded><![CDATA[<p>Series : .NET Core First Impression part 2</p><p>มาต่อกันจาก <a href="https://medium.com/@leakhand/net-core-first-impression-ba44603d8831#.58njfnvst">Part</a> ที่แล้วนะครับ ในบทความนี้ผมจะแนะนำวิธีการพัฒนา Web API ด้วย ASP.NET Core โดยใช้ ORM ที่ชื่อว่า Entity Framwork เชื่อมต่อไปยังฐานข้อมูล MySQL สำหรับในขั้นตอนของการ Setup ฐานข้อมูล MySQL ผมขอข้ามนะครับเพราะเชื่อว่า สามารถหาได้จาก Google ไม่ว่าจะเป็นการ Setup ผ่าน XAMP หรือวิธีอื่น</p><p>มาถึงขั้นตอนแรกเลยคือตัว Dependencies ที่เราจำเป็นต้องใช้งาน โดยที่เราไปทำการแก้ไขไฟล์ project.json เพิ่ม สองบรรทัดนี้เข้าไป</p><pre>&quot;SapientGuardian.EntityFrameworkCore.MySql&quot;: &quot;7.1.15&quot;,<br>&quot;MySql.Data.EntityFrameworkCore&quot;: &quot;7.0.6-IR31&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOFsJdT1SF2fifvQlfzjRw.png" /><figcaption>เพิ่ม dependencies ในไฟล์ project.json</figcaption></figure><p>จากนั้นให้เปิด terminal แล้วรันคำสั่ง dotnet restore หรือ save file แล้วคลิ๊กที่ popup ด้านบน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBGeu2gjyBBBjSxSyNdwoA.png" /><figcaption>Restore package after edit</figcaption></figure><p>จากนั้นให้สร้างโฟลเดอร์ชื่อว่า Context ที่ root folder และสร้างไฟล์ชื่อว่า IDbContext และ MySqlDbContext.cs และเขียนโค๊ดตามด้านล่าง ** อย่าลืมตรวจสอบ namespace ของตนเองด้วยในที่นี้ผมใช้ “LeakHand”</p><p><strong>File</strong>: <em>IdbContext.cs</em></p><pre>using System;<br>using Microsoft.EntityFrameworkCore.Infrastructure;<br>using Microsoft.EntityFrameworkCore;<br>using LeakHand.Model;</pre><pre>namespace LeakHand.Context<br>{<br>    public interface IDbContext : IDisposable<br>    {<br>        DatabaseFacade Database { get; }<br>        DbSet&lt;Item&gt; Items { get; set; }<br>        int SaveChanges();<br>        DbSet&lt;TEntity&gt; Set&lt;TEntity&gt;() where TEntity : class;<br>    }<br>}</pre><p><strong>File</strong>: <em>MySqlDbContext.cs</em></p><pre>using Microsoft.EntityFrameworkCore;<br>using System;<br>using System.Linq;<br>using LeakHand.Model;</pre><pre>namespace LeakHand.Context<br>{<br>    public class MySqlDbContext : DbContext , IDbContext<br>    {</pre><pre>        public DbSet&lt;Item&gt; Items { get; set; }</pre><pre>        public MySqlDbContext(DbContextOptions&lt;MySqlDbContext&gt; options)<br>            : base(options)<br>        {<br>        }</pre><pre>        protected override void OnModelCreating(ModelBuilder builder)<br>        {</pre><pre>            builder.Entity&lt;Item&gt;().HasKey(m =&gt; m.Id);<br> <br>            // shadow properties<br>            builder.Entity&lt;Item&gt;().Property&lt;DateTime&gt;(&quot;UpdatedTimestamp&quot;);<br>            <br>            base.OnModelCreating(builder);<br>        }<br> <br> <br>        public override int SaveChanges()<br>        {<br>            ChangeTracker.DetectChanges();<br> <br>            updateUpdatedProperty&lt;Item&gt;();<br> <br>            return base.SaveChanges();<br>        }<br> <br>        private void updateUpdatedProperty&lt;T&gt;() where T : class<br>        {<br>            var modifiedSourceInfo =<br>                ChangeTracker.Entries&lt;T&gt;()<br>                    .Where(e =&gt; e.State == EntityState.Added || e.State == EntityState.Modified);<br> <br>            foreach (var entry in modifiedSourceInfo)<br>            {<br>                entry.Property(&quot;UpdatedTimestamp&quot;).CurrentValue = DateTime.UtcNow;<br>            }<br>        }<br>    }<br>}</pre><p>หลังจากได้ Main DbContext File แล้ว Concept อื่นๆแทบจะเหมือนกับตัว EF ตัวปัจจุบันเลย คือเราต้องไปสร้าง Data Model ตามแบบฉบับของตนเองในที่นี้ผมจะสร้าง BaseRepository, TodoRepository, Item <strong><em>Class</em> </strong>และ <strong><em>Interface</em></strong> IToDoRepository</p><p><strong>File</strong>: <em>BaseRepository.cs</em></p><pre>using LeakHand.Context;</pre><pre>namespace LeakHand.Model<br>{<br>    public class BaseRepository&lt;T&gt; where T : class<br>    {<br>        protected IDbContext _dbContext;<br>        public BaseRepository(IDbContext dbContext)<br>        {<br>            _dbContext = dbContext;<br>            _dbContext.Database.EnsureCreated();<br>        }<br>    }<br>}</pre><p><strong>File</strong>: Item</p><pre>namespace LeakHand.Model<br>{<br>    public class Item<br>    {<br>        public int Id { get; set; }<br>        public string Name { get; set; }<br>        public string Description { get; set; }<br>        public bool IsComplete { get; set; }<br>    }</pre><pre>}</pre><p><strong>File</strong>:<strong> </strong><em>ITodoRepository.cs</em></p><pre>using System.Collections.Generic;</pre><pre>namespace LeakHand.Model<br>{<br>    public interface ITodoRepository<br>    {<br>        void Add(Item item);<br>        IEnumerable&lt;Item&gt; GetAll();<br>        Item Find(int id);<br>        Item Remove(int id);<br>        void Update(Item item);<br>    }<br>}</pre><p>TodoRepository.cs</p><pre>using System.Collections.Generic;<br>using System.Linq;<br>using LeakHand.Context;</pre><pre>namespace LeakHand.Model<br>{<br>    public class TodoRepository : BaseRepository&lt;Item&gt;, ITodoRepository<br>    {<br>        public TodoRepository(IDbContext dbContext) : base(dbContext)<br>        {</pre><pre>        }</pre><pre>        public IEnumerable&lt;Item&gt; GetAll()<br>        {<br>            return _dbContext.Items;<br>        }</pre><pre>        public void Add(Item item)<br>        {<br>            _dbContext.Items.Add(item);<br>            _dbContext.SaveChanges();<br>        }</pre><pre>         public Item Find(int id)<br>        {<br>            return _dbContext.Items.FirstOrDefault(c =&gt; c.Id == id);<br>        }</pre><pre>        public Item Remove(int id)<br>        {<br>            Item item = Find(id);<br>            _dbContext.Items.Remove(item);<br>            return item;<br>        }<br>        public void Update(Item item)<br>        {<br>            _dbContext.Items.Update(item);<br>        }<br>    }<br>}</pre><p>หลังจากนั้นให้สร้างไฟล์ Controller โดย Inject <strong>ItodoRepository </strong>เข้าไปใน constructor</p><pre>using System.Collections.Generic;<br>using Microsoft.AspNetCore.Mvc;<br>using LeakHand.Model;</pre><pre>namespace LeakHand.Controllers<br>{<br>    [Route(&quot;api/[controller]&quot;)]<br>    public class TodoController : Controller<br>    {<br>        private ITodoRepository _todoRepository;<br>        public TodoController(ITodoRepository todoRepository)<br>        {<br>            _todoRepository = todoRepository;<br>        }</pre><pre>[HttpGet]<br>        public IEnumerable&lt;Item&gt; GetAll()<br>        {<br>            return _todoRepository.GetAll();<br>        }</pre><pre>[HttpGet(&quot;{id}&quot;, Name = &quot;GetTodo&quot;)]<br>        public IActionResult GetById(int id)<br>        {            <br>            var item = _todoRepository.Find(id);<br>            if (item == null)<br>            {<br>                return NotFound();<br>            }<br>            return new ObjectResult(item);<br>        }<br>    }<br>}</pre><blockquote>หลังจากเสร็จเกี่ยวกับโค๊ดแล้วเราก็ต้องมาสร้าง Table กันต่อ โดยนำ SQL Statement ด้านล่างนี้ไปรันได้เลย<br>Create Table Statement Command</blockquote><pre>CREATE TABLE `leakhand`.`item` <br>( <br>    `id` INT NOT NULL AUTO_INCREMENT , <br>    `name` VARCHAR(200) NOT NULL , <br>    `description` VARCHAR(500) NOT NULL ,<br>    `isComplete` BIT NOT NULL , <br>    `UpdatedTimestamp` TIMESTAMP NOT NULL <br> , PRIMARY KEY (`id`)) <br> ENGINE = InnoDB;</pre><p><strong>Setup Connection String to MySQL</strong></p><p>การกำหนด connection string ของ ASP .NET Core นั้นจะมีไฟล์ที่ชื่อว่า appsettings.json ซึ่งในไฟล์นี้เราสามารถกำหนดค่า config ต่างๆของระบบเราไว้ได้ ในที่นี้เราจะเพิ่ม connection string ที่ใช้เชื่อมต่อไปยังฐานข้อมูล โดยก่อนที่เราจะเชื่อมต่อได้ ควรจะสร้าง Database รอไว้ก่อน ส่วนที่ผมเพิ่มคือที่ชื่อว่า “<strong>ConnectionStrings”</strong></p><pre>{<br>  &quot;Logging&quot;: {<br>    &quot;IncludeScopes&quot;: false,<br>    &quot;LogLevel&quot;: {<br>      &quot;Default&quot;: &quot;Debug&quot;,<br>      &quot;System&quot;: &quot;Information&quot;,<br>      &quot;Microsoft&quot;: &quot;Information&quot;<br>    }<br>  },<br><strong>  &quot;ConnectionStrings&quot;: {<br>    &quot;DataAccessMySqlProvider&quot;: &quot;server=localhost;userid=root;password=root;database=leakhand; convert zero datetime=True&quot;</strong><br>  }<br>}</pre><p>จากนั้นให้เราไปทำการกำหนด Dependencies Injection และการเรียกใช้งาน MySql ที่ทางผมได้สร้างไว้คือ IDbContext ในไฟล์ Startup.cs โดยการแก้ไขในส่วน ConfigureServices</p><pre>public void ConfigureServices(IServiceCollection services)<br>{</pre><pre>    var sqlConnectionString = Configuration.GetConnectionString(&quot;DataAccessMySqlProvider&quot;);</pre><pre>    services.AddDbContext&lt;MySqlDbContext&gt;(options =&gt;<br>                options.UseMySQL(sqlConnectionString)<br>            );</pre><pre> // Register the service and implementation for the database context<br>    services.AddScoped&lt;IDbContext&gt;(provider =&gt;provider.GetService&lt;MySqlDbContext&gt;());<br>    services.AddScoped&lt;ITodoRepository, TodoRepository&gt;();</pre><pre>// Add framework services.<br>    services.AddMvc();<br>}</pre><p>หลังจากนั้นให้ลองรัน Command dotnet build ดูถ้าถูกต้องเรียบร้อยก็จะไม่มี Error ใดๆเกิดขึ้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjfUrxQzA-Xnj_uQWvoC6w.png" /><figcaption>Re-compiler after complete coding</figcaption></figure><p>จากนั้นให้รัน command dotnet run และให้ทดสอบเพิ่มข้อมูลผ่านทาง MySql โดย Insert Record ตัวอย่างเข้าไปซัก 1 Record</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1VEy8_U6TZb82xQ229-Cig.jpeg" /><figcaption>Add test data record</figcaption></figure><p>หลังจากนั้นให้ลองเรียกข้อมูลผ่าน Web API ที่เราทำรอไว้ คือ</p><pre>api/<a href="http://localhost:5000/api/todo">todo<br>http://localhost:5000/api/todo</a></pre><pre>api/<a href="http://localhost:5000/api/todo/1">todo/{id}<br>http://localhost:5000/api/todo/1</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iKzPVePaKM_3KbgLMCGAdw.png" /><figcaption>Test Todo API</figcaption></figure><p>จบปึ้ง ง่วงมากไว้ถ้าไม่ง่วงจะมาเขียนต่อให้ครบทุก API</p><p>ขอบคุณที่อดทนอ่านบทความง่อยๆจนจบ</p><p>Git : <a href="https://github.com/leakhand/LabDotNetCore">https://github.com/leakhand/LabDotNetCore</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccd52752b1c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[.NET Core First Impression]]></title>
            <link>https://medium.com/@leakhand/net-core-first-impression-ba44603d8831?source=rss-bc5fa83a7e16------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba44603d8831</guid>
            <category><![CDATA[dotnet-core]]></category>
            <dc:creator><![CDATA[HELLO ME.]]></dc:creator>
            <pubDate>Sun, 18 Dec 2016 15:17:45 GMT</pubDate>
            <atom:updated>2016-12-20T16:19:43.492Z</atom:updated>
            <content:encoded><![CDATA[<p>Series : .NET Core First Impression part 1</p><p>เว้นว่างจากการเขียนภาษา C# มาหลายเดือนมาก แทบไม่ได้ไปแตะโค๊ดหรือว่า เขียนโปรเจ็คใหม่ๆด้วย .NET เลยก็ว่าได้เพราะว่าไปหลงไหลกับการหัดใช้งานระบบ Linux ที่ต้องมา Support Project และบวกกับต้องไปนั่งแก้โค๊ด Java ที่ใช้ Marven สุดท้ายต้องไปซ้อมมือกับ GIT ให้ชำนาญ เพื่อไม่ให้โปรเจ็คที่เราใช้งานนั้นเกิดปัญหา แน่นอน ทุกอย่างย่อมเริ่มจากศูนย์</p><p>ย้อนกลับมาที่ C#.NET จริงๆแล้วตั้งแต่เริ่มต้นหัดเขียนโปรแกรมมา ตัวผมเองเริ่มจากภาษา PHP =&gt; C แล้วก็วนกลับมาหัดเขียน PHP ใหม่จนพอทำงานได้ จากนั้นได้มีโอกาสเริ่มหัดเขียน C# ด้วยตนเอง ในตอนเริ่มแรกนั้น ไม่เข้าใจ Concept OOP เลยแม้แต่นิ๊ดเดียว (ทุกวันนี้ก็เข้าใจเพิ่มขึ้นมาอีกนิ๊ดนึง)</p><p>เอาหละกลับมาที่ .NET Core ต่อจัดเตรียม เครื่องไม้เครื่องมือก่อนเลยครับ</p><p>เรื่อง Environment ของแต่ละคนก็ลองเช็คดูทีเว็บไซด์หลักของ Microsoft นะครับ<br><a href="https://www.microsoft.com/net/core">https://www.microsoft.com/net/core</a> หรือที่นี่ก็ได้<br><a href="https://www.microsoft.com/net/download/core">https://www.microsoft.com/net/download/core</a></p><p>ส่วนของผมมีสิ่งที่ต้องใช้ดังนี้</p><ol><li><a href="https://go.microsoft.com/fwlink/?LinkID=827524">.NET CORE SDK for Windows</a></li><li><a href="http://code.visualstudio.com/B?utm_expid=101350005-31.YsqwCVJESWmc4UCMDLsNRw.1&amp;utm_referrer=https%3A%2F%2Fwww.microsoft.com%2Fnet%2Fcore">Visual Studio Code</a> Version ล่าสุด เปิดโปรแกรมได้ไวมากครับขอบอก</li><li>NodeJs Version ล่าสุด</li></ol><p>เท่านี้เราก็สามารถเริ่มสร้าง Project ด้วย ASP.NET Core กันได้แล้วครับ</p><h3>Get Start Web API with ASP.NET Core</h3><p>จากนั้นให้เปิดโปรแกรม Visual studio code ขึ้นมาและเปิด Folder ซักโฟลเดอร์นึงที่ต้องการเก็บ Project ในที่นี่ของผมจะไปที่ โฟลเดอร์ D:/NetCore/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jrzI2NNmvsVveWkQ34f5lw.png" /></figure><p>และให้เปิดหน้า Command Terminal โดยไปที่เมนู View และเลือกเมนู Integrated Terminal หรืออาจจะกด Short Key ดูก็ได้นะครับแต่เครื่องผมมันกดแล้วไม่ขึ้น = =</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jP6kQyJP9VvA2jd-GzkvUQ.png" /></figure><p>หลังจากนั้นจะได้หน้าจอ Console โผล่ขึ้นมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_jmzBeahghmMCu14DbUMw.png" /></figure><p>เริ่มจากการติดตั้ง Yeoman กันก่อนด้วย คำสั่ง ถ้ากรณีมีแล้วก็ข้ามขั้นตอนนี้ไปได้เลย</p><pre>npm install yo -g</pre><p>หลังจากนี้เราจะใช้ตัว <a href="https://github.com/OmniSharp/generator-aspnet"><strong>generator-aspnet</strong></a> เป็นตัวช่วยในการสร้าง Bootstrap ให้กับ Project เรา ชีวิตดี๊ดี มีคนทำให้แล้ว จากนั้นตามด้วยคำสั่ง</p><pre>npm install -g generator-aspnet</pre><p>เมื่อติดตั้งเสร็จให้เราสร้าง Project Template ด้วย Command นี้</p><pre>yo aspnet webapi</pre><blockquote>หลังจาก Download Package เรียบร้อย เราจะต้องกำหนดชื่อ Application Name ที่จะใช้งานนั้น “ ชื่อ Application ที่เราตั้งจะไปถูกกำหนดเป็น Default Namespace ให้โดยอัตโนมัติ ” เมื่อติดตั้งเรียบร้อยก็จะได้ ไฟล์ดังภาพตัวอย่าง</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J0M7gt-PvDJFm8OvA7TvUg.png" /><figcaption>After complete install generator-aspnet</figcaption></figure><p>ทีนี้ก็มาถึง Step ในการรัน Application โดยให้เรา CD ไปที่ Project Name ที่เราตั้งตามตัวอย่างชื่อ “LeakHand” จากนั้นรันคำสั่ง “<strong>dotnet restore</strong> เพื่อติดตั้ง package และ dependencies ที่จำเป็นต้องใช้งานใน application โดยที่รายละเอียดของ package ที่จำเป็นต้องใช้งานเราสามารถไปดูและเพิ่มได้ในไฟล์ที่ชื่อว่า project.json” จากนั้นให้รันคำสั่ง “<strong>dotnet build</strong> เพื่อทำการทดสอบ recompile ว่ามี error อะไรไหม **<em>จริงๆแล้วเราสามารถข้ามไปรันคำสั่งถัดไปได้เลยเช่นกัน</em>” และรันคำสั่ง “dotnet run เพื่อ start web application” ถ้าหากไม่พบ error จะได้ดังภาพ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5I3k3bsmha_luPK0ZGZ1A.png" /><figcaption>start .net core web application</figcaption></figure><p>default port ของตัว .net core จะใช้ port 5000 ดูไปดูมานี่มันช่างเหมือน NodeJS เสียนี่กะไร ถ้าอยากทดสอบว่า api เราเรียกได้ไหมจะมี default api มาให้ทดสอบคือ</p><p><a href="http://localhost:5000/api/values">http://localhost:5000/api/values</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhy-rFQhNMVtXSAOPld1ig.png" /></figure><p>หลังจากที่ทดลองก็พบว่า ตัว .NET Core นั้นติดตั้งไม่ยากและใช้งานค่อนข้างง่ายเรียกว่า Concept ในการพัฒนาซอฟแวร์สมัยนี้มันก็คล้ายๆกันไปหมดแต่ละเจ้าพยายามเอาจุดเด่นของตัวเองมานำเสนอ ซึ่ง Microsoft เป็นเจ้าพ่อด้านการใช้งานง่ายอยู่แล้วยิ่งมา Open source ยิ่งทำให้น่าสนใจเข้าไปอีก</p><p>จบปึ๊ง … ไว้มาต่อ การใช้ .NET core + EF + MySQL ทำเว็บ API</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba44603d8831" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ติดตั้ง LEMP บน CentOS 7 และ Config Laravel Site ให้เป็น remote site hook]]></title>
            <link>https://medium.com/@leakhand/%E0%B8%95%E0%B8%B4%E0%B8%94%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87-lemp-%E0%B8%9A%E0%B8%99-centos-7-%E0%B9%81%E0%B8%A5%E0%B8%B0-config-laravel-site-%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99-remote-site-hook-dd970fef889e?source=rss-bc5fa83a7e16------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd970fef889e</guid>
            <category><![CDATA[php7]]></category>
            <category><![CDATA[centos7]]></category>
            <category><![CDATA[centos]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[lemp]]></category>
            <dc:creator><![CDATA[HELLO ME.]]></dc:creator>
            <pubDate>Thu, 03 Nov 2016 15:50:52 GMT</pubDate>
            <atom:updated>2018-02-05T04:33:00.771Z</atom:updated>
            <content:encoded><![CDATA[<p>ก่อนอื่นต้องขอเกริ่นก่อนนะครับ ว่าผมนั้นมีฝีมือในตัว Linux ระดับ Beginner สัดๆ คือใช้เป็นแค่ command พื้นฐาน แต่เหตุผลที่ต้องมาใช้ นั้นเพราะว่า การเช่า Share Host นั้นเริ่มไม่ตอบโจทย์ การทำเว็บไซด์ แบบ multiple site ที่ต้องทำ Laravel เป็น Subdomain เนื่องจากตัว Direct Admin มันง่ายในการใช้งานแต่ยุ่งยากในการแก้ไข และอีกปัญหานึงคือเรื่องความปลอดภัย ที่มันถูกเปิดมาตั้งแต่ต้นบางอันเราก็ไม่ได้จำเป็นต้องใช้งาน และข้อจำกัดอีก bla bla ..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BOOTFILFGtNh39z6N0MHRg.jpeg" /></figure><p><strong>เครื่องที่ผมทำการ Config จะมี Spec ดังนี้</strong></p><ul><li>OS CentOS 7</li><li>2GB RAM</li><li>2CPU Core</li></ul><p><strong>Software Stack ที่ผมต้องการใช้งานมีดังนี้</strong></p><p>Nginx<br>PHP version 7<br>Laravel Framework<br>MySQL Database<br>GIT</p><h3><strong>ขั้นตอนการติดตั้ง</strong></h3><p>Download Package มาไว้ที่เครื่องก่อน โดยการรันคำสั่งทีละบรรทัด ตามด้านล่าง</p><pre># yum update<br># yum install epel-release<br># rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm<br># rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm<br># rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm</pre><blockquote><strong>ติดตั้ง PHP และ Module ที่ต้องการใช้งาน</strong></blockquote><pre># yum install php70w<br># yum install php70w-mysql php70w-xml php70w-soap php70w-xmlrpc<br># yum install php70w-mbstring php70w-json php70w-gd php70w-mcrypt</pre><blockquote><strong>ติดตั้ง Nginx และทำการ Enable &amp; Start Service</strong></blockquote><pre># yum install nginx<br># systemctl enable nginx.service<br># systemctl start nginx.service</pre><blockquote><strong>ติดตั้ง MySql Server และ Start Service</strong></blockquote><pre># yum install mysql-server<br># systemctl start mysqld.service</pre><blockquote><strong>จากนั้นให้ Preconfig MySQL Service เป็น Mode Secure Installation</strong></blockquote><p>การกำหนดโหมดนี้ถ้าหากว่าเป็นบน Environment Test เราอาจจะไม่ต้องกำหนดก็ได้ หน้าตาหลังรันคำสั่งก็จะประมาณด้านล่างนี้</p><pre># mysql_secure_installation</pre><pre>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!</pre><pre>In order to log into MariaDB to secure it, we&#39;ll need the current<br>password for the root user.  If you&#39;ve just installed MariaDB, and<br>you haven&#39;t set the root password yet, the password will be blank,<br>so you should just press enter here.</pre><pre>Enter current password for root (enter for none): <br>OK, successfully used password, moving on...</pre><pre>Setting the root password ensures that nobody can log into the MariaDB<br>root user without the proper authorisation.</pre><pre>You already have a root password set, so you can safely answer &#39;n&#39;.</pre><pre>Change the root password? [Y/n] n<br> ... skipping.</pre><pre>By default, a MariaDB installation has an anonymous user, allowing anyone<br>to log into MariaDB without having to have a user account created for<br>them.  This is intended only for testing, and to make the installation<br>go a bit smoother.  You should remove them before moving into a<br>production environment.</pre><pre>Remove anonymous users? [Y/n] y<br> ... Success!</pre><pre>Normally, root should only be allowed to connect from &#39;localhost&#39;.  This<br>ensures that someone cannot guess at the root password from the network.</pre><pre>Disallow root login remotely? [Y/n] y<br> ... Success!</pre><pre>By default, MariaDB comes with a database named &#39;test&#39; that anyone can<br>access.  This is also intended only for testing, and should be removed<br>before moving into a production environment.</pre><pre>Remove test database and access to it? [Y/n] y<br> - Dropping test database...<br> ... Success!<br> - Removing privileges on test database...<br> ... Success!</pre><pre>Reloading the privilege tables will ensure that all changes made so far<br>will take effect immediately.</pre><pre>Reload privilege tables now? [Y/n] y<br> ... Success!</pre><pre>Cleaning up...</pre><pre>All done!  If you&#39;ve completed all of the above steps, your MariaDB<br>installation should now be secure.</pre><pre>Thanks for using MariaDB!</pre><p>Restart MySQL Service และกำหนดให้ Start อัตโนมัติเมื่อทำการ Reboot เครื่อง</p><pre># systemctl restart mysqld.service<br># systemctl enable mysqld.service</pre><blockquote><strong>ติดตั้ง PHP-FPM (PHP Fast Cgi Process Manager)</strong></blockquote><pre>yum install php70w-fpm</pre><blockquote><strong>Configure the PHP Processor</strong></blockquote><pre># sudo vi /etc/php.ini</pre><pre>## ค้นหา cgi.fix_pathinfo= เอา คอมเม้นออก และกำหนดค่าเป็น </pre><pre>cgi.fix_pathinfo=0</pre><p>จากนั้นให้แก้ไขไฟล์ <a href="http://www.conf/">www.conf</a> ใน php-fpm.d/</p><pre># sudo vi /etc/php-fpm.d/www.conf</pre><pre># แก้ไขจาก<br>#user = apache<br>#group = apache<br># เป็น<br>user = nginx<br>group = nginx</pre><pre># แก้ไขจาก<br>#listen.owner = nobody<br>#listen.group = nobody<br># เป็น<br>listen.owner = nginx<br>listen.group = nginx</pre><p>บันทึกและทำการ Restart PHP-FPM Service และ Enable Service ให้ Start เมื่อมีการ Reboot เครื่อง</p><pre># sudo systemctl start php-fpm<br># sudo systemctl enable php-fpm</pre><blockquote><strong>ปิด Service HTTPD ออกซะ<br></strong>เราไปใช้ Nginx แล้ว Apache Service จึงไม่มีความจำเป็นต้องใช้งาน</blockquote><pre># service httpd stop</pre><pre># systemctl disable httpd</pre><blockquote><strong>ทดสอบสร้างเว็บไซด์</strong></blockquote><pre># mkdir -p /var/www/yoursite.com/public_html</pre><pre># vi /var/www/yoursite.com/public_html/index.html</pre><p>แปะโค๊ดนี้เพื่อทดสอบว่า nginx ทำงานถูกต้อง</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;www.yoursite.com&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;h1&gt;Wow it&#39;s work great !!!&lt;/h1&gt;<br>Hello world.<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>เปลี่ยนสิทธิ์ Owner ให้เป็น nginx user</p><pre># chown -R nginx:nginx /var/www/yoursite.com/public_html</pre><blockquote><strong>สร้างโฟลเดอร์ที่เอาไว้กำหนดว่ามีเว็บไซด์ใดบ้างที่ต้องใช้งาน</strong></blockquote><pre># mkdir /etc/nginx/sites-available</pre><pre># mkdir /etc/nginx/sites-enabled</pre><blockquote>กำหนด Symbolic link ระหว่าง Folder sites-available กับ sites-enabled</blockquote><pre># ln -s /etc/nginx/sites-available/yoursite.com.conf /etc/nginx/sites-enabled/yoursite.com.conf</pre><blockquote><strong>แก้ config Nginx</strong></blockquote><pre># vi /etc/nginx/nginx.conf</pre><pre>#เพิ่ม สองบรรทัด ด้านล่างนี้ ภายใน block <em>http {} และ https {</em></pre><pre>include /etc/nginx/sites-enabled/*.conf;</pre><pre>server_names_hash_bucket_size 64;</pre><blockquote><strong>สร้าง Vitual Host</strong></blockquote><pre># vi /etc/nginx/sites-available/yoursite.com.conf</pre><pre>#แปะโค๊ดด้านล่างนี้ลงไป</pre><pre>server {<br>    listen       80;<br>    server_name youtsite.com www.yoursite.com;</pre><pre># note that these lines are originally from the &quot;location /&quot; block<br>    root   /var/www/yoursite.com/public;<br>    index index.php index.html index.htm;</pre><pre>location / {<br>        try_files $uri $uri/ =404;<br>    }<br>    error_page 404 /404.html;<br>    error_page 500 502 503 504 /50x.html;<br>    location = /50x.html {<br>        root /usr/share/nginx/html;<br>    }</pre><pre>location ~ \.php$ {<br>        try_files $uri =404;<br>        fastcgi_pass 127.0.0.1:9000;<br>        fastcgi_index index.php;<br>        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<br>        include fastcgi_params;<br>    }<br>}</pre><p>Restart Nginx Service</p><pre># systemctl restart nginx</pre><p>จากนั้นให้ลอง เรียกใช้งานจาก Local หรือ internet ถ้าหากมีการกำหนด DNS ถูกต้อง site ที่เรา config ไว้จะต้องแสดงผลครับ</p><p>ขอจบเท่านี้ก่อนนะครับ บทความน่าจะมาต่อเรื่องการ กำหนดให้สามารถรัน Laravel และทำเป็น GIT Hook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7hw9L-stTFuX7UHRV1lPQ.jpeg" /></figure><p><strong>Reference</strong><br>แหล่งข้อมูลอ้างอิง</p><p><a href="https://www.howtoforge.com/tutorial/how-to-install-laravel-5x-with-nginx-and-php-fpm-7-on-centos-7/">https://www.howtoforge.com/tutorial/how-to-install-laravel-5x-with-nginx-and-php-fpm-7-on-centos-7/</a></p><ul><li><a href="http://tecadmin.net/install-php-7-nginx-mysql-5-on-centos/">How to Install PHP 7, NGINX &amp; MySQL 5.6 on CentOS/RHEL 7.1 &amp; 6.7</a></li><li><a href="https://www.godaddy.com/garage/tech/config/how-to-install-and-configure-nginx-on-centos-7/">How to install and configure NGINX on CentOS 7 - The Garage</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7">How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7 | DigitalOcean</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd970fef889e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>