CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

准备篇:

CentOS 5.x系统安装配置图解教程

http://www.js-code.net/os/128754.html

1、配置火墙,开启80端口、3306端口

vi /etc/Sysconfig/iptables
-A RH-Firewall-1-iNPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

:wq! #保存退出

添加好规则后的防火墙配置文件如下图所示:

CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)

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

2、关闭SELINUX

vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加

:wq! #保存退出
setenforce 0 #使配置立即生效

3、添加第三方yum

CentOS认yum源软件版本太低了,要安装最新版本的LamP,这里使用第三方yum源
wget http://www.atomicorp.COM/installers/atomic #下载,首先使用认yum源安装wget命令 yum install wget
sh ./atomic #安装
yum clean all #清除当前yum缓存
yum makecache #缓存yum源中的软件包信息
yum repolist #列出yum源中可用的软件包

安装篇:

一、安装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/httpd.conf #编辑
ServerName www.example.com:80 #去掉前面的注释

:wq! #保存退出
chkconfig httpd on #设为开机启动
/etc/init.d/httpd restart #重启Apache

在浏览器中打开服务器IP地址,会看到下面的界面,说明安装成功。

CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)

二、安装MysqL

1、安装MysqL

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

CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)

/etc/init.d/MysqLd start #启动MysqL

chkconfig MysqLd on #设为开机启动

cp /usr/share/MysqL/my-medium.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面认有一个my.cnf,直接覆盖即可)

/etc/init.d/MysqLd start #启动

2、为root账户设置密码

MysqL_secure_installation

回车,根据提示输入Y

输入2次密码,回车

根据提示一路输入Y

最后出现:Thanks for using MysqL!

MysqL密码设置完成,重新启动 MysqL

/etc/init.d/MysqLd stop #停止

/etc/init.d/MysqLd restart #重启

三、安装PHP

1、安装PHP

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

CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)

2、安装PHP组件,使PHP支持MysqL

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回车

/etc/init.d/MysqLd restart #重启MysqL

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

配置篇

一、Apache配置

vi /etc/httpd/conf/httpd.conf #编辑文件
ServerTokens OS  #修改为:ServerTokens PRod (在出现错误页的时候不显示服务器操作系统名称)
ServerSignature On  #修改为:ServerSignature Off (在错误页中不显示Apache的版本)
Options Indexes FollowSymLinks  #修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)
#AddHandler cgi-script .cgi #修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)
Allowoverride None  #修改为:AllowOverride All (允许.htaccess)
AddDefaultCharset UTF-8 #修改为:AddDefaultCharset GB2312 (添加GB2312为认编码)
Options Indexes MultiViews FollowSymLinks #修改为 Options MultiViews FollowSymLinks(不在浏览器上显示树状目录结构)
DirectoryIndex index.html index.html.VAR #修改为:DirectoryIndex index.html index.htm Default.html Default.htm
index.PHP Default.PHP index.html.var #设置首页文件增加index.PHP
KeepAlive Off #修改为:KeepAlive On (允许程序性联机)
MaxKeepAliveRequests 100 #修改为:MaxKeepAliveRequests 1000 (增加同时连接数)
:wq! #保存退出
/etc/init.d/httpd restart #重启
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除认测试页

二、PHP配置

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_reStore,dl,openLOG,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,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版本的信息
short_open_tag = ON #在229行支持PHP标签
open_basedir = .:/tmp/ #在380行 设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止PHP木马跨站,如果改了之后安装程序有问题(例如:织梦内容理系统),可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/
:wq! #保存退出

/etc/init.d/MysqLd restart #重启MysqL
/etc/init.d/httpd restart #重启Apche

测试篇

cd /var/www/html
vi index.PHP #输入下面内容

<?PHP
PHPinfo();
?>

:wq! #保存退出

在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息!

CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)

注意:apache认的程序目录是/var/www/html

权限设置:chown apache.apache -R /var/www/html

至此,CentOS 5.11安装配置LAMP服务器(Apache+PHP5+MysqL)教程完成!

脚本宝典总结

以上是脚本宝典为你收集整理的CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)全部内容,希望文章能够帮你解决CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:CentOSCentOS