centos7 Apache + php5.6 + MariaDB环境配置

ByWhat'sUs

centos7 Apache + php5.6 + MariaDB环境配置

首先使用xshell连接主机,这个就不在赘述.

运行命令:# yum update     #更新服务器

一.关闭防火墙

# systemctl stop firewalld.service  #停止firewall

# systemctl disable firewalld.service #禁止firewall开机启动

centos7以前使用的是iptables防火墙,想要换掉的童鞋可以更换,安装命令如下:

# yum install iptables-services #安装

# vi /etc/sysconfig/iptables #编辑防火墙配置文件

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

-A INPUT -j REJECT –reject-with icmp-host-prohibited

-A FORWARD -j REJECT –reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

# systemctl restart iptables.service #最后重启防火墙使配置生效

# systemctl enable iptables.service #设置防火墙开机启动

 

二.安装Apache

# yum install httpd #根据提示,输入Y安装即可成功安装

# systemctl start httpd.service #启动apache

# systemctl stop httpd.service #停止apache

# systemctl restart httpd.service #重启apache

# systemctl enable httpd.service #设置apache开机启动

安装完成后在客户端浏览器中打开服务器IP地址,出现apache的相关界面则说明apache安装成功

 

三.安装MariaDB

CentOS 7中,已经使用MariaDB替代了MySQL数据库

# yum install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成

# systemctl start mariadb.service #启动MariaDB

# systemctl stop mariadb.service #停止MariaDB

# systemctl restart mariadb.service #重启MariaDB

# systemctl enable mariadb.service #设置开机启动

然后为root账号设置密码

# mysql_secure_installation

回车,根据提示输入Y

输入2次密码,回车

根据提示一路输入Y

最后出现:Thanks for using MySQL!

MySql密码设置完成,重新启动 MySQL:

# systemctl restart mariadb.service #重启MariaDB

 

四.安装PHP

centos7系统自带的php一般是5.4的版本,如要安装5.4的版本可以使用如下命令:

# yum install php #根据提示输入Y直到安装完成

安装PHP组件,使PHP支持 MariaDB

# yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

#这里选择以上安装包进行安装,根据提示输入Y回车

systemctl restart mariadb.service #重启MariaDB

systemctl restart httpd.service #重启apache

如要安装php5.6版本,则要按照如下操作

配置yum源

以下是CentOS 7.0的源

# yum install epel-release

# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)

# yum list enablerepo=remi enablerepo=remiphp56 | grep php

安装php5.6

# yum install enablerepo=remi enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

# php –version
PHP 5.6.0 (cli) (built: Sep 3 2014 19:51:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

我们可以看到php5.6版本已经安装成功了!

 

 

About the author

What'sUs administrator

Leave a Reply

PHP Code Snippets Powered By : XYZScripts.com