linux如何使用yum安装php

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的详细内容,更多请关注其它相关文章!