今天研究了一下CentOS 7的web环境(Apache+MySQL+PHP)的搭建,在网CentOS中文站上面看到了一篇教程,感觉不错,讲的很详细。就照搬过来稍微修改吧
原文来自:centoscn.com
一、配置防火墙,开启80端口、3306端口(注意这一步很重要,否则可能外网无法访问服务器)
1、关闭firewall:
#停止firewall服务
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
2、安装iptables防火墙(个人认为这个防火墙非常好用,已经可以取代firewall了)
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
二、关闭SELINUX(我也不知道这一步是干嘛用的)
#修改配置文件
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
#使配置立即生效
setenforce 0
三.安装apache
yum install httpd
可能会用到的:
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
restart一下,然后:
输入在浏览器输入localhost测试是否可以正常访问。
四、安装mysql
1.官网下载安装mysql-server
#wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
#rpm -ivh mysql-community-release-el7-5.noarch.rpm
#yum install mysql-community-server
安装成功后重启mysql服务。
#service mysqld restart
初次安装mysql,root账户没有密码。
直接输入
mysql -u root即可登陆
五.安装phpyum install php安装PHP组件,使PHP支持mysql
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
重启对应服务
- systemctl restart mysqld.service //重启mysql
- systemctl restart httpd.service //重启apache
到此为止基本服务全部安装完毕