linux使用yum安裝php的方法:1、執行「mkdir /usr/local/php」指令;2、下載yum來源的更新安裝套件;3、安裝相關yum來源安裝包;4、透過「yum install」指令安裝php即可。
一、yum安裝php
1、mkdir /usr/local/php
2、cd /usr/local/php
# 3、下載yum來源的更新安裝包
centOS 6.x來源
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm wget https://mirror.webtatic.com/yum/el6/latest.rpm
centOS 7.x來源
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
4、安裝相關yum來源安裝套件(這裡以centOS 7.x的為例)
rpm -Uvh epel-release-latest-7.noarch.rpm rpm -Uvh webtatic-release.rpm
5、查看該來源對應的php安裝套件指令(以PHP 為例)
yum list --enablerepo=webtatic | grep php
6、尋找php 5.6版本的安裝套件
yum search php56w
7、安裝Apache
yum install httpd httpd-devel
8、關閉firewalld防火牆
systemctl stop firewalld.service systemctl disable firewalld.service systemctl status firewalld
9、啟動apache
/bin/systemctl start httpd.service
此時用瀏覽器存取你伺服器IP位址 應該是Testing 123文件頁面。
10、安裝mysql【這裡因為之前使用tar套件安裝了mysql,所以不安裝】
11、啟動mysql
systetcl start mysql
***如果啟動mysql時報錯
Failed to start mysql.service: Unit mysql.service failed to load: No such file or directory.
或
Failed to start mysqld.service: Unit not found
則需要安裝mariadb-server並啟動,加入到開機自啟動
yum install -y mariadb-server systemctl start mariadb.service systemctl enable mariadb.service
12、安裝PHP
yum install php56w
13、重啟apache使php生效
/bin/systemctl restart httpd.service
14、查看PHP的版本
php -v
15、php的簡單使用
進入目錄/var/www/html
# vi index.php(必須是index.php【首頁】才會在瀏覽器顯示)
內容如下:
<!DOCTYPE html> <html> <body> <?php echo "Hello World!"; ?> </body> </html>
以上是linux如何使用yum安裝php的詳細內容。更多資訊請關注PHP中文網其他相關文章!