准备篇:
配置防火墙,开启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端口通过防火墙)
重启防火墙使配置生效
/etc/init.d/iptables restart
service
iptables restart
安装篇:
一、安装Apache
1、检查是否已安装Apache
rpm -qa|grep httpd
httpd-2.2.15-5.el6.centos.i686
httpd-tools-2.2.15-5.el6.centos.i686
如果看到上面的信息,说明系统已经安装了Apache
2、安装Apache
yum install httpd
Package httpd-2.2.15-5.el6.centos.i686 already installed and latest
version
Nothing to do
如果看到上面的信息,说明系统已经安装了Apache
启动Apache /etc/init.d/httpd
start
重启Apache /etc/init.d/httpd
restart
设为开机启动 chkconfig httpd
on
chkconfig –levels 3 httpd on(设置在运行级别3,即使命令行模式下自动启动)
chkconfig --list httpd (查看当前 httpd service
被配置在哪几个运行级别自启动)
备注:Apache启动之后会提示错误:
正在启动 httpd:httpd: Could not reliably determine
the server's fully qualif
domain name, using ::1 for ServerName
解决办法:是因为DNS没配置好. 如果不想配置DNS, 就在httpd.conf , 修改 ServerName
localhost:80 即可
特别说明:CentOS 6.0
如果是默认Desktop安装的话,系统已经默认安装了Apache,只需要设置为开机启动即可。
二、安装MySQL
1、检查是否已安装MySQL
rpm -qa|grep mysql
2、安装MySQL
yum install mysql mysql-server
询问是否要安装,输入Y即可自动安装,直到安装完成。
启动MySQL /etc/init.d/mysqld start
设为开机启动 chkconfig mysqld on
cp
/usr/share/mysql/my-medium.cnf
/etc/my.cnf
#拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
3、为root账户设置密码
mysql_secure_installation
根据提示输入Y,回车
输入2次密码,回车
最后出现:Thanks for using MySQL!
MySql密码设置完成
重新正常启动 MySQL:
/etc/init.d/mysqld stop
/etc/init.d/mysqld start
/etc/init.d/mysqld restart
三、安装PHP5
1、检查是否已安装PHP5
rpm -q php
出现 package php is not installed
说明系统没有安装PHP5
2、安装PHP5
yum install php
根据提示输入Y直到安装完成
重启Apache /etc/init.d/httpd restart
说明:Apache 网站的默认文档的路径是 /var/www/html,在这个目录里新建一个php探针文件,http://localhost/浏览会显示很多
PHP5 的安装信息
cd /var/www/html
touch index.php
vi index.php
<?php
phpinfo();
?>
保存退出
ls -1显示出index.php文件
PHP5 正在工作,你会看到很多模块都可以在 PHP5 中使用了,而 MySQL 并没有在这里被列出来,
这意味着 PHP5 并不支持MySQL,你还需要安装 php-mysql 这个包。
3、安装PHP组件,使
PHP5 支持 MySQL
系统运维 www.osyunwei.com
温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链接
yum search php 搜索php模块,挑选那些你需要的模块,安装。
yum
install 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
这里选择以上安装包进行安装
根据提示输入Y回车
重启MySql /etc/init.d/mysqld restart
重启Apche /etc/init.d/httpd restart
配置篇:
一、Apache配置
1
|
cp /etc/httpd/conf/httpd.conf
/etc/httpd/conf/httpd.confbak
修改之前先备份原文件 |
2
|
cp /etc/httpd/conf/httpd.confbak
/etc/httpd/conf/httpd.conf
恢复备份文件 |
3
|
vi /etc/httpd/conf/httpd.conf 编辑文件 |
4
|
ServerTokens
OS
← 找到这一行,将“OS”改为“ProductOnly”(在出现错误页的时候不显示服务器操作系统的名称) |
5
|
ServerTokens ProductOnly ← 变为此状态 |
6
|
ServerSignature
On ←
找到这一行,将“On”改为“Off” |
7
|
ServerSignature Off ← 在错误页中不显示Apache的版本 |
8
|
Options Indexes
FollowSymLinks
← 找到这一行,删除“Indexes”,并添加“Includes”、“ExecCGI”,禁止列出目录 |
9
|
Options Includes ExecCGI FollowSymLinks ←
允许服务器执行CGI及SSI |
10
|
AddHandler cgi-script .cgi ←
找到这一行,去掉行首的“#”,并在行尾添加“.pl” |
11
|
AddHandler cgi-script .cgi .pl ←
允许扩展名为.pl的CGI脚本运行 |
12
|
AllowOverride None ← 找到这一行,将“None”改为“All” |
13
|
AllowOverride All ←
变为此状态,允许.htaccess |
14
|
LogFormat "%h %l %u %t
\"%r\" %>s %b
\"%{Referer}i\"
\"%{User-Agent}i\"" combined ← 找到这一行 |
15
|
LogFormat "%h %l %u %t
\"%!414r\" %>s %b
\"%{Referer}i\"
\"%{User-Agent}i\"" combined ←
改为此状态(添加“!414”到规则中,对于过长的日志不记录) |
16
|
AddDefaultCharset
UTF-8 ←
修改UTF-8为GB2312 |
17
|
AddDefaultCharset GB2312 ←
(添加GB2312为默认编码) |
18
|
Options Indexes MultiViews FollowSymLinks ←
找到这一行,将“Indexes”删除 |
19
|
Options MultiViews
FollowSymLinks
← 变为此状态(不在浏览器上显示树状目录结构) |
20
|
DirectoryIndex index.html
index.html. var ← 找到这一行,修改默认首页文件 |
21
|
DirectoryIndex index.html index.htm Default.html
Default.htm index.php Default.php index.html. var ← 变为此状态(设置默认首页文件,增加index.php) |
22
|
KeepAlive Off
#修改为On 允许程序性联机 |
24
|
MaxKeepAliveRequests
100 #修改为1000
一次联机最大传输数量,0为不限制 |
25
|
MaxKeepAliveRequests 500 |
/etc/init.d/httpd
restart
#保存配置后重启
rm -f
/etc/httpd/conf.d/welcome.conf
/var/www/error/noindex.html 删除默认测试页
二、php配置
cp /etc/php.ini /etc/php.inibak
#编辑之前先备份
vi /etc/php.ini
date.timezone =
PRC
#把前面的分号去掉,改为date.timezone = PRC
disable_functions =
passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,
posix_getegid,posix_geteuid,posix_getgid,
posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,
posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,
posix_getsid,posix_getuid,posix_isatty,
posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,
posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
expose_php =
Off
#禁止显示php版本的信息
display_errors =
OFF
#关闭错误提示
register_globals = OFF
#关闭注册全局变量
magic_quotes_gpc =
On
#打开magic_quotes_gpc来防止SQL注入
log_errors =
On
#记录错误日志
error_log =
/var/log/php/error_log.log
#设置错误日志存放目录,文件必须允许apache用户的和组具有写的权限
#(chown apache.apache /var/log/php/error_log.log)
open_basedir =
.:/tmp/
#设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站
至此,CentOS 6.0 LAMP服务器(Apache+PHP5+MySQL)安装配置完成。