Hermes le Messager Breton Quiétiste | Bweezy a écrit :
Les blogs en 2000-2007 fournissaient tonnes d'informations pour un univers encore relativement limité sur les questions Linux.
Et Google n'avait pas encore un algorithme calqué sur le profil gmail.
En 2003, en tapant les bons mots dans le moteur, et à force de répétition, j'ai trouvé LE blog qui décrivait point par point ce que je voulais réaliser, les astuces, etc.
(Oracle 9i sur Debian 3, serveur LAMP avec libs ora oci8 pour PhP). Ca a pris du temps et de la sueur quand même.
Je doute que l'IA me donne l'exacte marche à suivre aujourd'hui (tant elle est faite de pièges et d'exceptions).
|
C'est marrant ton exemple, parce que j'ai du moi aussi interfacer une base oracle avec PHP dans mon ancienne boite il y a douze ou treize ans.
Mais je pense sincèrement que tu te trompes. J'avais bcp galéré aussi à l'époque pour reprendre ton exemple et c'est en prenant diverse infos sur différents sites que j'avais fini par réussir. C'était si je me souviens bien une pure question de versions plus ou moins compatibles entre le driver oci8, la version de PHP, le fait d'avoir le module correctement compilé etc...
De nos jours, je te garantis que c'est bcp plus simple si tu sais prompter correctement, que tu donnes le bon contexte, les versions exactes de PHP etc... C'est si tu poses la question sans donner aucun contexte ni aucun détail que tu iras dans le mur (ou pas si tu as de la chance). Par exemple, tu devras demander de vérifier si les infos sont up-to-date, que le LLM se réfère aux documentations etc...
En reprenant ton example:
Un exemple de prompt (avec Claude.ai (Sonnet 4.6)) :
Citation :
I need to have Oracle working with PHP on an AWS EC2 m6.large. PHP version is 8.3, Oracle 26ai, Nginx 1.28.2
Make sure you only use up-to-date information and do not assume it will work without checking up-to-date documentation. Please provide me with a step by step procedure.
|
Code :
- PHP 8.3 + Oracle Instant Client 26ai + Nginx 1.28.2 on AWS EC2 (Ubuntu 24.04)
- > **Assumptions:** You are running Ubuntu 24.04 LTS (Noble Numbat) on your EC2 m6.large. Commands assume `sudo` access. PHP 8.3 and Nginx are already installed, or will be installed in the steps below.
- ---
- ## Important Notes Before You Start
- **Oracle 26ai and libaio:** Oracle Instant Client ships compiled against `libaio.so.1`, but Ubuntu 24.04 ships `libaio1t64` instead of `libaio1`. Without a symlink workaround you will get a "No such file or directory" error at runtime.
- **OCI8 version for PHP 8.3:** OCI8 version 3.4.0 is required for PHP 8.3 and 8.4.
- **Oracle 26ai connectivity:** Oracle Call Interface 26ai can connect to Oracle Database 19c or later.
- ---
- ## Step 1 — Update the System
- ```bash
- sudo apt update && sudo apt upgrade -y
- sudo apt install -y unzip wget build-essential libaio1t64
- ```
- ---
- ## Step 2 — Fix the libaio Symlink (Ubuntu 24.04 Specific)
- This is required for Oracle Instant Client to find its shared library:
- ```bash
- sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1
- ```
- ---
- ## Step 3 — Download Oracle Instant Client 26ai
- Oracle requires a free account to download the ZIP files. Do this on your **local machine** first, then upload to the EC2 instance.
- Download page: https://www.oracle.com/database/tec [...] loads.html
- Download these two packages from the **Version 23.26.x / 26ai** section:
- - `instantclient-basic-linux.x64-23.26.x.x.x.zip`
- - `instantclient-sdk-linux.x64-23.26.x.x.x.zip`
- Upload them to your EC2 instance:
- ```bash
- scp -i your-key.pem instantclient-basic-*.zip instantclient-sdk-*.zip ubuntu@:/tmp/
- ```
- ---
- ## Step 4 — Install Oracle Instant Client
- ```bash
- sudo mkdir -p /opt/oracle
- cd /tmp
- sudo unzip instantclient-basic-linux.x64-23.26.*.zip -d /opt/oracle/
- sudo unzip instantclient-sdk-linux.x64-23.26.*.zip -d /opt/oracle/
- # Verify the extracted directory name (will be something like instantclient_23_26)
- ls /opt/oracle/
- ```
- Set a shell variable for convenience (adjust the version number to match what was extracted):
- ```bash
- ORACLE_IC=/opt/oracle/instantclient_23_26
- ```
- ---
- ## Step 5 — Configure the Dynamic Linker
- ```bash
- echo $ORACLE_IC | sudo tee /etc/ld.so.conf.d/oracle-instantclient.conf
- sudo ldconfig
- ```
- Verify the libraries are found:
- ```bash
- ldconfig -p | grep libclntsh
- # Should return output pointing to your instantclient path
- ```
- ---
- ## Step 6 — Install PHP 8.3 and Required Packages
- If PHP 8.3 is not yet installed, add Ondřej's PPA (the standard method on Ubuntu):
- ```bash
- sudo apt install -y software-properties-common
- sudo add-apt-repository ppa:ondrej/php -y
- sudo apt update
- sudo apt install -y php8.3 php8.3-fpm php8.3-dev php8.3-cli \
- php8.3-xml php8.3-mbstring php8.3-curl php-pear
- ```
- If PHP is already installed, you need at minimum:
- ```bash
- sudo apt install -y php8.3-dev php-pear
- ```
- ---
- ## Step 7 — Compile and Install the OCI8 Extension
- Compile OCI8 manually from PECL source (version 3.4.0 for PHP 8.3):
- ```bash
- cd /tmp
- wget https://pecl.php.net/get/oci8-3.4.0.tgz
- tar xzf oci8-3.4.0.tgz
- cd oci8-3.4.0
- phpize8.3
- ./configure --with-oci8=instantclient,$ORACLE_IC --with-php-config=/usr/bin/php-config8.3
- make
- sudo make install
- ```
- This installs `oci8.so` into the PHP 8.3 extension directory.
- ---
- ## Step 8 — Enable the OCI8 Extension in PHP
- ```bash
- # Create the oci8 ini file
- echo '; priority=20' | sudo tee /etc/php/8.3/mods-available/oci8.ini
- echo 'extension=oci8.so' | sudo tee -a /etc/php/8.3/mods-available/oci8.ini
- # Enable it for both CLI and FPM
- sudo phpenmod -v 8.3 oci8
- ```
- ---
- ## Step 9 — Configure Oracle Environment for PHP-FPM
- PHP-FPM runs as a daemon and does **not** inherit your shell environment. You must inject Oracle environment variables directly into the FPM pool config.
- ```bash
- sudo nano /etc/php/8.3/fpm/pool.d/www.conf
- ```
- Add the following lines inside the `[www]` section (near other `env[]` directives):
- ```ini
- env[ORACLE_HOME] = /opt/oracle/instantclient_23_26
- env[LD_LIBRARY_PATH] = /opt/oracle/instantclient_23_26
- env[NLS_LANG] = AMERICAN_AMERICA.AL32UTF8
- ```
- Also add them to the system environment so CLI scripts work too:
- ```bash
- echo 'ORACLE_HOME=/opt/oracle/instantclient_23_26' | sudo tee -a /etc/environment
- echo 'LD_LIBRARY_PATH=/opt/oracle/instantclient_23_26' | sudo tee -a /etc/environment
- ```
- ---
- ## Step 10 — Restart PHP-FPM
- ```bash
- sudo systemctl restart php8.3-fpm
- sudo systemctl status php8.3-fpm
- ```
- ---
- ## Step 11 — Configure Nginx 1.28.2 to Use PHP-FPM
- Edit or create your Nginx server block:
- ```bash
- sudo nano /etc/nginx/sites-available/your-site.conf
- ```
- ```nginx
- server {
- listen 80;
- server_name your-domain-or-ip;
- root /var/www/html;
- index index.php index.html;
- location / {
- try_files $uri $uri/ =404;
- }
- location ~ \.php$ {
- include snippets/fastcgi-php.conf;
- fastcgi_pass unix:/run/php/php8.3-fpm.sock;
- fastcgi_param ORACLE_HOME /opt/oracle/instantclient_23_26;
- fastcgi_param LD_LIBRARY_PATH /opt/oracle/instantclient_23_26;
- }
- location ~ /\.ht {
- deny all;
- }
- }
- ```
- Enable the site and reload Nginx:
- ```bash
- sudo ln -s /etc/nginx/sites-available/your-site.conf /etc/nginx/sites-enabled/
- sudo nginx -t
- sudo systemctl reload nginx
- ```
- ---
- ## Step 12 — Verify the Installation
- **Check OCI8 is loaded in CLI:**
- ```bash
- php8.3 -m | grep oci8
- # Expected output: oci8
- ```
- **Check the extension details:**
- ```bash
- php8.3 --ri oci8
- ```
- Expected output:
- ```
- OCI8 Support => enabled
- OCI8 Version => 3.4.0
- Oracle Run-time Client Library Version => 23.26.x.x.x
- ```
- **Create a temporary PHP info test page:**
- ```bash
- echo '' | sudo tee /var/www/html/info.php
- ```
- Visit `http://<your-ec2-ip>/info.php` and search for "oci8" in the output.
- > ⚠️ **Remove this file immediately after testing:**
- > ```bash
- > sudo rm /var/www/html/info.php
- > ```
- ---
- ## Step 13 — Test a Database Connection
- Create a test PHP script:
- ```php
- <?php
- $conn = oci_connect('username', 'password', '//your-oracle-host:1521/service_name');
- if (!$conn) {
- $e = oci_error();
- trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
- }
- echo "Connected to Oracle successfully!";
- oci_close($conn);
- ?>
- ```
- ---
- ## Troubleshooting
- | Problem | Likely Cause | Fix |
- |---|---|---|
- | `libaio.so.1: cannot open shared object file` | Ubuntu 24.04 renamed the library | Re-do Step 2 |
- | `OCIEnvNlsCreate() failed` | `LD_LIBRARY_PATH` not visible to FPM | Re-check Step 9 env vars and restart FPM |
- | `oci8.so: cannot open shared object file` | `extension_dir` mismatch | Run `php8.3 -i \| grep extension_dir` and confirm `oci8.so` is present there |
- | `oci8_dtrace_gen.h: No such file or directory` | DTrace compiled into PHP | Set `export PHP_DTRACE=yes` before running `phpize8.3` and `./configure` |
- | Connection timeout to Oracle | AWS Security Group blocking port | Ensure outbound TCP on port **1521** is allowed in your EC2 security group |
- | `pecl install oci8` installs wrong version | pecl defaults to wrong PHP version | Always compile manually from source as shown in Step 7 |
- ---
- ## AWS Security Group Reminder
- Ensure your EC2 instance's security group allows **outbound TCP traffic on port 1521** (or whichever port your Oracle database listens on). This is especially relevant when connecting to an external or on-premise Oracle instance.
- If your Oracle DB is in another AWS VPC, also verify VPC peering or Transit Gateway routing is in place, and that the target security group allows inbound on port 1521 from your EC2's security group.
- ---
- *Guide based on Oracle Instant Client 26ai (package version 23.26.x), PHP OCI8 PECL extension 3.4.0, PHP 8.3, Nginx 1.28.2, and Ubuntu 24.04 LTS (Noble Numbat) — verified February 2026.*
|
PS : Je lui ai demandé de générer un fichier .md
Message édité par Hermes le Messager le 27-02-2026 à 08:35:33 ---------------
Expert en expertises
|