Skip to main content

Posts

Showing posts with the label PHP

CURL SSL error in WAMP

I facing problem about certificate error when I using curl to request HTTPS domain. I find cause of problem is there is no certificate configuration in PHP. Below is how to solve my problem. Here is sample of error: * About to connect() to notify-api.line.me port 443 (#0) * Trying {IP Address}... * connected * Connected to notify-api.line.me ({IP Address}) port 443 (#0) * SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed * Closing connection #0 Step to solve this problem Download  Certificate Bundle Extract and put PEM file to your web server folder or other folder. Enable mod_ssl in Apache and php_openssl.dll in php.ini Add configuration into php.ini curl.cainfo="C:/wamp/cacert.pem" openssl.cafile="C:/wamp/cacert.pem" Restart Apache Service

ไม่สามารถสร้างไฟล์ หรือโฟลเดอร์ที่มี Permission 777 ได้ใน Linux

หลายคนอาจเคยประสบปัญหาเกี่ยวกับการสร้างไฟล์ หรือโฟลเดอร์บน Linux ด้วยคำสั่ง PHP เช่น mkdir ซึ่งถึงแม้จะกำหนด Permission ในขั้นตอนการสร้างให้เป็น 0777 แล้ว แต่พอไปดูที่ Folder จริงจะไม่เป็นไปตามที่กำหนดอาจจะเห็นเป็น rwxr-xr-x หรือ 0755 นั่นเอง ปัญหาที่เกิดขึ้นนี้มักสร้างปัญหาในกรณีที่มีการสร้าง Folder ที่ใช้ร่วมกันในหลาย Server ซึ่งอาจทำให้ Server อื่นไม่สามารถเขียนไฟล์ทับ หรือเขียนลงใน Folder ได้นั่นเอง ปัญหานี้เกิดจากใน Linux จะมี umask ซึ่งเป้นเครื่องมือในการ mask permission ก่อนการเขียนไฟล์หรือโฟลเดอร์ใน Linux นั่นเอง ซึ่งเราสามารถดูได้ว่าปัจจุบัน umask ในเครื่องเป็นเท่าไรเพียงรันคำสั่ง umask ก็จะเห็น โดยส่วนใหญ่จะเป็น 022 ซึ่งเมื่อนำไป mask กับ 777 ก็จะได้เป็น 777 - 022 = 755 นั่นเอง วิธีการแก้ไขสามารถทำได้โดยก่อนสร้างไฟล์หรือโฟลเดอร์ให้ทำการเปลี่ยน umask ให้เป็น 0  แล้วจึงใช้คำสั่งเขียนไฟล์หรือโฟลเดอร์นั่นเอง เช่น 1 2 3 4 5 6 7 8 9 10 <?php $old = umask ( 0 ); chmod ( "/path/some_dir/some_file.txt" , 0777 ); umask ( $old ); // Checking ...

การทำให้ Laravel รองรับ Primary Key แบบหลาย Columns (Composite Keys)

ปัจจุบัน Eloquent ของ Laravel Framework ยังไม่รองรับการบันทึกข้อมูลที่มี Primary Key แบบหลาย Columns ได้ ผมได้ค้นหาจากอินเตอร์เน็ต และพบว่ามีคนที่แนะนำแนวทางแก้ไข โดยใช้วิธีการ Overide method save ของ Eloquent ขึ้นมาแทน ซึ่งผมได้ทดลองใช้แล้วสามารถทำงานได้อย่างถูกต้อง จึงขอแนะนำการนำ Method save ที่ถูกปรับปรุงมาเขียนเป็น Base Class ของ Model ดังตัวอย่าง 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use DB; class BaseModel extends Model { public function save ( array $options = []) { if...