php編譯openssl模組的步驟
最近我們打算在php架構中使用composer來管理依賴關係,但是在執行composer的安裝命令時(如下),發現系統提示沒有安裝openssl擴充類庫。
安裝composer命令:
sudocurl -s https://getcomposer.org/installer | sudo php
異常如下:
| Some settings onyour machine make Composer unable to work properly. Make sure thatyou fix the issues listed below and run this script again: The opensslextension is missing, which means that secure HTTPS transfers areimpossible. If possible youshould enable it or recompile php with --with-openssl |
看到這個異常,應該是我的php在編譯的過程中沒有增加-with-openssl選項造成的。但是在網上搜尋相關問題時,發現我們不需要重新編譯php環境,可以藉助phpize來只編譯openssl.so檔案,並把該檔案添加到php.ini檔案中的。
1.環境
1)作業系統:
Linuxubuntu 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014x86_64 x86_64 x86_64 GNU/Linux
2)php源碼目錄:
/home/wuguowei/software/php-5.5.14_source
3)php編譯後的目錄:
/home/wuguowei/software/php5.5
2.步驟
#從源碼目錄拷貝openssl目錄到編譯後的目錄檔案中
sudocp -r /home/wuguowei/software/php-5.5.14_source/ext/openssl /home/wuguowei/software/php5.5/include/php/ext
#進入php編譯後的目標檔案中
cd/home/wuguowei/software/php5.5/include/php/ext
#依次執行如下代碼
/home/wuguowei/software/php5.5/bin/phpize
./configure--with-openssl–with-php-config=/home/wuguowei/software/php5.5/bin/php-config
make&& make install
#找到php.ini檔案(通常在/etc/php.in)中的“DynamicExtensions”的內容,在末尾添加上“extension= openssl.so”
#重啟php伺服器即可
#查看編譯後的openssl的方法
php-i |grep 'openssl'
正確的結果如下:
| root@ubuntu:/home/wuguowei/software/composer#php -i |grep openssl openssl OLDPWD=> /home/wuguowei/software/php5.5/include/php/ext/openssl _SERVER["OLDPWD"]=> /home/wuguowei/software/php5.5/include/php/ext/openssl |
#查看php命令在哪兒的命令
whereis php
which php