SlideShare ist ein Scribd-Unternehmen logo
1 von 3
Downloaden Sie, um offline zu lesen
การติดตั้ง PHP (OCI8) กับ Oracle Instant Client บน Apache HTTP Server
ขอบเขตเนื ้อหา:
    การติดตัง Apache HTTP Server
                ้
    การติดตัง PHP ให้ ใช้ งาน OCI8
                  ้

การติดตัง Apache HTTP Server
        ้
Apache HTTP Server เป็ นโปรเจกส์ HTTP Server ที่เป็ น open-source เราสามารถดาวน์โหลด HTTP Server ได้ ที่
http://httpd.apache.org และสามารถติดตังได้ ตงระบบปฏิบติการที่เป็ น Unix และ Windows
                                      ้ ั้           ั




ตัวอย่างการติดตัง้ Apache HTTP Server บน Linux (x86_64):
# tar zxf httpd-2.2.16.tar.gz
# cd httpd-2.2.16
# ./configure --prefix=/usr/local/apache
# make && make install
# ls /usr/local/apache
bin build cgi-bin conf error htdocs icons include lib logs man manual modules

การ start/stop Apache HTTP Server
# /usr/local/apache/bin/apachectl start
# ps -aef | grep http
root 4460 1 0 15:59 ?         00:00:00 /usr/local/apache/bin/httpd -k start
# /usr/local/apache/bin/apachectl stop

การคอนฟิ ค Apache HTTP Server ทาได้ โดยการแก้ ไข httpd.conf ไฟล์ ที่ conf/ ไดเร็ กทอรี่
การติดตัง PHP ให้ ใช้ งาน OCI8
           ้
ก่อนอื่นต้ องติดตัง้ Oracle Instant Client ดาวน์โหลดได้ ที่ http://download.oracle.com




กรณีนี ้ติดตังบน Linux (x86_64)
             ้
# ls oracle-instantclient11.2-*rpm
oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm
# rpm -ivh oracle-instantclient11.2-*rpm
Preparing...          ########################################### [100%]
 1:oracle-instantclient11.########################################### [ 50%]
 2:oracle-instantclient11.########################################### [100%]
# ls /usr/lib/oracle/11.2/client64
bin lib

การติดตังด้ วย rpm จะได้ ไดเร็ กทอรี่ /usr/lib/oracle/11.2/client64 หลังจากนันติดตัง้ PHP เพื่อใช้ งาน OCI8 (เรา
        ้                                                                    ้
สามารถดาวน์โหลด PHP ได้ ที่ http://www.php.net)




หลังจากนันเริ่ มติดตัง้
          ้
# tar zxf php-5.3.3.tar.gz
# cd php-5.3.3
# ./configure --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib --with-
apxs2=/usr/local/apache/bin/apxs --libdir=/usr/local/apache
# make && make install
# cp php.ini-development /usr/local/apache/conf/php.ini
*กรณี นี้ ใช้ php.ini-development เพือการทดสอบ บนโปรดักชันควรใช้ php.ini-production
                                     ่
# ls /usr/local/apache/modules
httpd.exp libphp5.so

เราจะพบไฟล์ libphp5.so ซึงเป็ นโมดูลสาหรับ PHP หลังจากนัน แก้ ไขไฟล์ httpd.conf
                         ่                              ้
# vi /usr/local/apache/conf/httpd.conf


ตัวอย่างในไฟล์ httpd.conf เพือให้ สามารถใช้ งาน PHP
                             ่
LoadModule php5_module       modules/libphp5.so
AddType application/x-httpd-php .php .phtml
หลังจากนันรี สตาร์ ท HTTP Server
         ้
# /usr/local/apache/bin/apachectl restart

จากนันเริ่ มทดสอบโปรแกรม โดยว่าไฟล์ไว้ ที่ “DocumentRoot”
     ้
# grep DocumentRoot /usr/local/apache/conf/httpd.conf | grep -v #
DocumentRoot "/usr/local/apache/htdocs"


ตัวอย่างโปรแกรม : (info.php)
<?php
echo phpinfo();
?>

จากนันเรี ยก http://localhost/info.php ผลลัพธ์ที่ได้ เราควรพบว่า PHP สามารถใช้ งาน OCI8 ได้
     ้




จากผลลัพธ์เราสามารถรู้วา PHP สามารถใช้ OCI8 ได้ จากนันทดสอบติดต่อฐานข้ อมูล (อ่านเพิ่มเติม PHP กับ Oracle
                       ่                             ้
OCI8 - http://php.net/manual/en/book.oci8.php)
ตัวอย่างโปรแกรม :
<?php
$conn = oci_connect('demo', 'demo', '127.0.0.1/orcl');
?>

ถ้ าทุกอย่างไม่มีปัญหาเราควรสามารถติดต่อฐานข้ อมูลได้ หากพลาสเวิร์ดผิดจะพบ Error
Warning: oci_connect() [function.oci-connect]: ORA-01017: invalid username/password; logon
denied in /usr/local/apache/htdocs/index.php on line 2

อย่างน้ อยก็ทาให้ ทราบว่าเราสามารถใช้ ฟังก์ชน OCI8 บน PHP ได้
                                            ั

Weitere ähnliche Inhalte

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Php + Oracle(Oci8) การติดตั้ง Php (Oci8) กับ Oracle Instant Client บน Apache Http Server

  • 1. การติดตั้ง PHP (OCI8) กับ Oracle Instant Client บน Apache HTTP Server ขอบเขตเนื ้อหา:  การติดตัง Apache HTTP Server ้  การติดตัง PHP ให้ ใช้ งาน OCI8 ้ การติดตัง Apache HTTP Server ้ Apache HTTP Server เป็ นโปรเจกส์ HTTP Server ที่เป็ น open-source เราสามารถดาวน์โหลด HTTP Server ได้ ที่ http://httpd.apache.org และสามารถติดตังได้ ตงระบบปฏิบติการที่เป็ น Unix และ Windows ้ ั้ ั ตัวอย่างการติดตัง้ Apache HTTP Server บน Linux (x86_64): # tar zxf httpd-2.2.16.tar.gz # cd httpd-2.2.16 # ./configure --prefix=/usr/local/apache # make && make install # ls /usr/local/apache bin build cgi-bin conf error htdocs icons include lib logs man manual modules การ start/stop Apache HTTP Server # /usr/local/apache/bin/apachectl start # ps -aef | grep http root 4460 1 0 15:59 ? 00:00:00 /usr/local/apache/bin/httpd -k start # /usr/local/apache/bin/apachectl stop การคอนฟิ ค Apache HTTP Server ทาได้ โดยการแก้ ไข httpd.conf ไฟล์ ที่ conf/ ไดเร็ กทอรี่
  • 2. การติดตัง PHP ให้ ใช้ งาน OCI8 ้ ก่อนอื่นต้ องติดตัง้ Oracle Instant Client ดาวน์โหลดได้ ที่ http://download.oracle.com กรณีนี ้ติดตังบน Linux (x86_64) ้ # ls oracle-instantclient11.2-*rpm oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm # rpm -ivh oracle-instantclient11.2-*rpm Preparing... ########################################### [100%] 1:oracle-instantclient11.########################################### [ 50%] 2:oracle-instantclient11.########################################### [100%] # ls /usr/lib/oracle/11.2/client64 bin lib การติดตังด้ วย rpm จะได้ ไดเร็ กทอรี่ /usr/lib/oracle/11.2/client64 หลังจากนันติดตัง้ PHP เพื่อใช้ งาน OCI8 (เรา ้ ้ สามารถดาวน์โหลด PHP ได้ ที่ http://www.php.net) หลังจากนันเริ่ มติดตัง้ ้ # tar zxf php-5.3.3.tar.gz # cd php-5.3.3 # ./configure --with-oci8=instantclient,/usr/lib/oracle/11.2/client64/lib --with- apxs2=/usr/local/apache/bin/apxs --libdir=/usr/local/apache # make && make install # cp php.ini-development /usr/local/apache/conf/php.ini *กรณี นี้ ใช้ php.ini-development เพือการทดสอบ บนโปรดักชันควรใช้ php.ini-production ่ # ls /usr/local/apache/modules httpd.exp libphp5.so เราจะพบไฟล์ libphp5.so ซึงเป็ นโมดูลสาหรับ PHP หลังจากนัน แก้ ไขไฟล์ httpd.conf ่ ้ # vi /usr/local/apache/conf/httpd.conf ตัวอย่างในไฟล์ httpd.conf เพือให้ สามารถใช้ งาน PHP ่ LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml
  • 3. หลังจากนันรี สตาร์ ท HTTP Server ้ # /usr/local/apache/bin/apachectl restart จากนันเริ่ มทดสอบโปรแกรม โดยว่าไฟล์ไว้ ที่ “DocumentRoot” ้ # grep DocumentRoot /usr/local/apache/conf/httpd.conf | grep -v # DocumentRoot "/usr/local/apache/htdocs" ตัวอย่างโปรแกรม : (info.php) <?php echo phpinfo(); ?> จากนันเรี ยก http://localhost/info.php ผลลัพธ์ที่ได้ เราควรพบว่า PHP สามารถใช้ งาน OCI8 ได้ ้ จากผลลัพธ์เราสามารถรู้วา PHP สามารถใช้ OCI8 ได้ จากนันทดสอบติดต่อฐานข้ อมูล (อ่านเพิ่มเติม PHP กับ Oracle ่ ้ OCI8 - http://php.net/manual/en/book.oci8.php) ตัวอย่างโปรแกรม : <?php $conn = oci_connect('demo', 'demo', '127.0.0.1/orcl'); ?> ถ้ าทุกอย่างไม่มีปัญหาเราควรสามารถติดต่อฐานข้ อมูลได้ หากพลาสเวิร์ดผิดจะพบ Error Warning: oci_connect() [function.oci-connect]: ORA-01017: invalid username/password; logon denied in /usr/local/apache/htdocs/index.php on line 2 อย่างน้ อยก็ทาให้ ทราบว่าเราสามารถใช้ ฟังก์ชน OCI8 บน PHP ได้ ั