1、配置防火墙,开启80、3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT #允许80端口通过防火墙
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT #允许3306端口通过防火墙
[root@VM_90_202_centos ~]# 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
重启iptables,使配置生效
/etc/init.d/iptables restart
2、关闭SELINUX
vi /etc/selinux/config #编辑SELINUX的配置文件
#SELINUX=enforcing
#SELINUXTYPE=targeted
SELINUX=disabled
#This file controls the state of SELinux on the system.
#SELINUX= can take one of these three values:
#enforcing - SELinux security policy is enforced.
#permissive - SELinux prints warnings instead of enforcing.
#disabled - No SELinux policy is loaded.
SELINUX=disabled
#SELINUXTYPE= can take one of these two values:
#targeted - Targeted processes are protected,
#mls - Multi Level Security protection.
#SELINUXTYPE=targeted
保存退出后重启系统
reboot
3、安装Apache
yum -y install httpd #yum安装Apache
/etc/init.d/httpd start #启动Apache
[root@VM_90_202_centos ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
这里系统会提示你无法可靠地确定服务器限定的网络域名
解决方法:找到Apache的配置文件,更改为自己的域名,如果没有域名则设置为localhost
vi /etc/httpd/conf/httpd.conf #编辑Apache配置文件
找到#ServerName www.example.com:80
更改为 #ServerName www.自己的域名.com:80 #没有域名则更改为localhost:80
保存退出后,将Apache设置为开机启动
chkconfig httpd on #将Apache设置为开机启动
/etc/init.d/httpd restart #重启Apache
4、安装MySQL
yum install -y mysql mysql-server #安装MySQL
/etc/init.d/mysqld start #启动MySQL
chkconfig mysqld on #设为开机启动
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷贝配置文件
注意:如果/etc目录下有默认一个默认的my.cnf文件,直接回车覆盖掉即可
[root@VM_90_202_centos ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'?
设置root密码
mysql_secure_installation
根据提示输入y
其中要输入2次密码
MySQL密码设置完成后重启MySQL
/etc/init.d/mysqld restart #重启MySQL
5、安装PHP5
yum install -y php #安装PHP
安装PHP组件,使 PHP支持 MySQL
yum install -y php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt
安装完成后重启Apache、MySQL
/etc/init.d/mysqld restart
/etc/init.d/httpd restart