不知道你問的linux,是哪個發行版本,常用的如 ubntu,centos,debian等。
我列一個centos7(伺服器常用這個版本)的安裝方法吧
centos7默認使用yum install 來安裝程序,但默認源安裝的php是5.4的,版本比較低,
要安裝高版本的,要麼下載源代碼手動編譯安裝,但對不熟悉的,萬一出點錯誤,會越搞越亂。我一般使用epel源安裝php,裡面各個版本都有,最新的php7.3
首先安裝epel
rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
這裡面的url是目前我用的,如果提示出錯,就是換url了,可以在電腦上手動打開epel源列表去檢查 epel-release是哪個版本,換上對應的名字
按版本安裝php
rpm-Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yuminstallphp56wphp56w-mysqlphp56w-pdophp56w-gdphp56w-sslphp56w-mbstringphp56w-cliphp56w-xmlphp56w-bcmath
我這里列的是一些常用的php擴展,如果需要其它的,手動加上即可
如果需要安裝php其它版本,把包名里的56改成對應版本即可 ,如
yuminstallphp71wphp71w-mysqlphp71w-pdophp71w-gdphp71w-sslphp71w-mbstringphp71w-cliphp71w-xmlphp71w-bcmath
yuminstallphp72wphp72w-mysqlphp72w-pdophp72w-gdphp72w-sslphp72w-mbstringphp72w-cliphp72w-xmlphp72w-bcmath
可對應安裝php7.1和php7.2,這種安裝方法,會默認配置好對應的設置,php.ini在/etc/中查找,命令行也默認啟用了 (php-cli)
❷ php常用擴展有哪些
php基本使用到的擴展有如下:
bcmath(精確數值處理)
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
igbinaryinotify 文件監控
json
libxml
mbstring
mhash
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis Redis緩存
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshmswoole 通信引擎
tokenizer
wddx
xml
xmlreader
xmlwriter
xslyaf YAF框架必須
zip
zlib
其中最常用的擴展有:curl date json mysql mysqli openssl pdo_mysql redis session zip等
查看當前php安裝了哪些擴展,可以使用命令:php -m
❸ 如何安裝php的擴展bcmath
下載或編譯擴展到插件目錄,在php.ini 中啟用,然後重啟web服務