CentOS7 yum方式配置LAMP环境 ( Apache+MariaDB+PHP )
1、安装Apache
yum install httpd //默认情况下,选择Y,进行安装
# 安装成功后,默认情况下,是禁止外部IP访问的,需要进行设置
vi /etc/httpd/conf/httpd.conf//进入配置文件
<Directory />
AllowOverride none
Require all granted #修改 denied
</ Directory>
一些跟 httpd 服务相关的命令
systemctl start httpd.service//启动
systemctl stop httpd.service//停止
systemctl status httpd.service//查看状态
systemctl restart httpd.service//重启
systemctl enable httpd.service//开机启动
访问服务器IP/127.0.0.1,如果显示测试界面,则安装成功:
安装nginx
yum install -y nginx
2、安装PHP
yum install -y php //默认安装
在Apche的目录下面新建一文件test.php
cd/var/www/html
vi test.php
<?php
phpinfo();
?>
访问网站http://127.0.0.1/test.php,如果正常解析,则说明PHP环境完成。
CentOS7默认安装的php5.4
需要安装高版本,如下操作
1.检查当前安装的PHP包
yumlistinstalled | grep php
如果有安装的PHP包,先删除他们
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64
2.添加源Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
CentOs 6.x
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
如果想删除上面安装的包,重新安装
rpm -qa | grep webstatic
rpm -e 上面搜索到的包即可
3.运行yum install
yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64
yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64
php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64
php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64
注:如果想升级到5.6把上面的55w换成56w就可以了。
yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
4.安装PHP FPM
yum install php55w-fpm
yum install php56w-fpm
yum install php70w-fpm
3、安装Mysql
#yum install mariadb maridb-server//默认安装 ---此安装可能不完整导致失败,最好用下面的命令
yum -y install mariadb*
如果失败,可以尝试 : sudo yum search mariadb
yum install mariadb-embedded mariadb-libs mariadb-bench mariadb mariadb-sever
#安装缺少的依赖包
systemctl start mariadb.service #启动服务
systemctl enable mariadb.service #加入系统启动
mysql_secure_installation #运行安全配置向导,设置密码,删除不用的所有
测试DB
mysql -u root -p
网友评论