Centos7Yum安裝PHP7.2
1、安裝源
安裝php72w,是需要配置額外的yum源地址的,否則會報錯不能找到相關軟件包。
php高版本的yum源地址,有兩部分,其中一部分是epel-release,另外一部分來自webtatic。如果跳過epel-release的話,安裝webtatic的時候,會有錯誤爆出。
所以,這裏需要的命令是:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
當然,您也可以選擇下面的這個命令,也是一樣的效果。
yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2、清除歷史版本
爲了防止centos上面發生php衝突,所以,這個命令還是先執行一下更好些。
yum -y remove php*
3、安裝擴展包
事實上,這裏面的對應擴展庫很多,這裏大家一定要注意cli和fpm這兩個包,而其它的相關包就看您需要了。
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel
還有比較豪華的版本
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
4、安裝完成以後,啓動服務
systemctl enable php-fpm.service
systemctl start php-fpm.service
5、安裝成功
通過命令查看是否成功
php -v
swoole安裝
1、安裝pecl
用pecl安裝swoole。默認安裝 php7.2 沒有pecl
yum install php72w-devel
yum install php72w-pear
2、安裝 swoole
pecl install swoole
錯誤處理
1.C++ preprocessor “/lib/cpp” fails sanity check
沒有c++庫
yum install glibc-headers
yum install gcc-c++
2.fatal error: openssl/ssl.h: No such file or directory
yum install openssl-devel
3.#error “Enable http2 support, require nghttp2 library.”
wget https://github.com/nghttp2/nghttp2/releases/download/v1.34.0/nghttp2-1.34.0.tar.bz2
tar -xjf nghttp2-1.34.0.tar.bz2
如果解壓報錯
bzip2:無法 exec: 沒有那個文件或目錄
執行
yum install -y bzip2
cd nghttp2-1.34.0
./configure
make
make install
4.fatal error: hiredis/hiredis.h: No such file or directory
wget https://github.com/redis/hiredis/archive/v0.14.0.tar.gz
tar xzvf v0.14.0.tar.gz
cd hiredis-0.14.0/
make && make install
執行
vi ~/.bash_profile
[最後加上這句]export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
[退出來]
source ~/.bash_profile
不修改.bash_profile文件,擴展添加會報錯
3、修改配置
如何找到php.ini文件
php -i | grep "Loaded Configuration File"
php.ini 中加入
extension=swoole.so
php -m
如果有swoole 擴展就大功告成。
測試:
php -m|grep swoole
如所示就表示成功安裝:
[root@txw etc]# php -m|grep swoole
swoole
[root@txw etc]#
附加:
我在supervisor 中運行swoole程序,報錯
PHP Startup: Unable to load dynamic library ‘swoole.so’ (tried: /usr/lib64/php/modules/swoole.so (libhiredis.so.0.14: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/swoole.so.so (/usr/lib64/php/modules/swoole.so.so: cannot open shared object file: No such file or directory))
困擾了我很久,然後找到解決辦法
echo '/usr/local/lib' >>/etc/ld.so.conf
ldconfig
原文鏈接:https://www.jianshu.com/p/b211d11b7a95