2024年3月13日发(作者:)

讲稿12 CentOS 6.5安装配置LAMP服务器(Apache+PHP5+MySQL)

准备篇:

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端口通过防火墙

备注:不要把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,

正确的应该是添加到默认的22端口这条规则的下面

如下所示:

########################################################

# 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

########################################################

/etc/init.d/iptables restart #重启防火墙使配置生效

2、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq!#保存退出

shutdown -r now#重启系统

安装篇:

一、安装Apache

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

/etc/init.d/httpd start#启动Apache

备注:Apache启动之后会提示错误:

正在启动 httpd:httpd: Could not reliably determine the server's fully qualif domain name,

using ::1 for ServerName

解决办法:

vi /etc/httpd/conf/ #编辑

找到 #ServerName :80

修改为 ServerName :80 #这里设置为你自己的域名,如果没有域名,可以设置

为localhost

:wq! #保存退出

chkconfig httpd on #设为开机启动

/etc/init.d/httpd restart #重启Apache

二、安装MySQL

1、安装MySQL

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

/etc/init.d/mysqld start #启动MySQL

chkconfig mysqld on #设为开机启动

cp /usr/share/mysql/ /etc/ #拷贝配置文件(注意:如果/etc目录下面默

认有一个,直接覆盖即可)

2、为root账户设置密码

mysql_secure_installation

回车,根据提示输入Y

输入2次密码,回车

根据提示一路输入Y

最后出现:Thanks for using MySQL!

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLSERVERS IN

PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user. If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): <-- 输入系统root密码

OK, successfully used password,

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] <-- ENTER

New password: <-- 你的MySQL root密码

Re-enter new password: <-- 你的MySQL root密码

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

1. This is intended only for testing, and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.