小编给大家分享一下CentOS使用本地yum源搭建LAMP环境的案例,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
配置防火墙,开启80端口、3306端口
vi/etc/sysconfig/iptables
如图,添加下面两条:
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT#允许80端口通过防火墙 -AINPUT-mstate--stateNEW-mtcp-ptcp--dport3306-jACCEPT#允许3306端口通过防火墙
重启防火墙使配置生效
/etc/init.d/iptablesrestart
关闭SELINUX
vi/etc/selinux/config
#SELINUX=enforcing#注释掉 #SELINUXTYPE=targeted#注释掉 SELINUX=disabled#增加 :wq!#保存退出
重启系统
shutdown-rnow
【安装Apache】
执行安装
yum-yinstallhttpd
启动Apache
servicehttpdrestart
或:
/etc/init.d/httpdstart
Apache启动之后会提示错误Could not reliably determine the server's fully qualifdomain name, using ::1 for ServerName,解决方法:
vi/etc/httpd/conf/httpd.conf
找到 #ServerName www.example.com:80
修改为 ServerName www.lws.com:80
(设置为自己的域名 或 ServerName localhost:80
):wq!#保存退出
设为开机启动
chkconfighttpdon
检查安装 访问主机地址 如图所示安装成功
修改Apache配置
vi/etc/httpd/conf/httpd.conf#建议使用ftp工具修改之前做好备份
修改如下:
ServerTokensOS #在44行修改为:ServerTokensProd(在出现错误页的时候不显示服务器操作系统的名称) ServerSignatureOn #在536行修改为:ServerSignatureOff(在错误页中不显示Apache的版本) OptionsIndexesFollowSymLinks #在331行修改为:OptionsIncludesExecCGIFollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录) #AddHandlercgi-script.cgi #在796行修改为:AddHandlercgi-script.cgi.pl(允许扩展名为.pl的CGI脚本运行) AllowOverrideNone #在338行修改为:AllowOverrideAll(允许.htaccess) AddDefaultCharsetUTF-8 #在759行修改为:AddDefaultCharsetGB2312 (添加GB2312为默认编码) OptionsIndexesMultiViewsFollowSymLinks#在554行修改为OptionsMultiViewsFollowSymLinks(不在浏览器上显示树状目录结构) DirectoryIndexindex.htmlindex.html.var#在402行修改为:DirectoryIndexindex.htmlindex.htmDefault.htmlDefault.htmindex.phpDefault.phpindex.html.var(设置默认首页文件,增加index.php) KeepAliveOff#在76行修改为:KeepAliveOn(允许程序性联机) MaxKeepAliveRequests100#在83行修改为:MaxKeepAliveRequests1000(增加同时连接数)
删除两个默认测试页
rm-f/etc/httpd/conf.d/welcome.conf/var/www/error/noindex.html
重启Apache
servicehttpdrestart
或
/etc/init.d/httpdrestart
【安装MySQL】
执行安装
yum-yinstallmysqlmysql-server
启动MySQL
/etc/init.d/mysqldstart
设为开机启动
chkconfigmysqldon
拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)
cp/usr/share/mysql/my-medium.cnf/etc/my.cnf
为root账户设置密码
mysql_secure_installation #回车,根据提示输入Y,输入2次密码,回车,根据提示一路输入Y最后出现:ThanksforusingMySQL设置完成
或者
mysqladmin-urootpassword'密码'
允许远程登录
mysql-uroot-p
输入密码输入mysql命令:
GRANTALLPRIVILEGESON*.*TO'root'@'%'IDENTIFIEDBY'密码'WITHGRANTOPTION;
退出mysql:exit
重启MySQL
servicemysqldrestart
【安装PHP5】
执行安装
yum-yinstallphp
安装PHP组件(这里选择以下安装包,根据提示输入Y回车安装)
复制代码 代码如下:
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
修改PHP配置
vi/etc/php.ini#建议使用ftp工具修改之前做好备份
修改如下:
date.timezone=PRC#在946行把前面的分号去掉,改为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 #在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
expose_php=Off#在432行禁止显示php版本的信息
magic_quotes_gpc=On#在745行打开magic_quotes_gpc来防止SQL注入
short_open_tag=On#在229行支持php短标签
open_basedir=.:/tmp/ #在380行设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php木马跨站,如果改了之后安装程序有问题,可以注销此行,或者直接写上程序的目录/data/www.osyunwei.com/:/tmp/
重启MySQL、Apahe
servicemysqldrestart servicehttpdrestart
(到此完成yum源搭建LAMP环境,我们可以查看一下各部分的安装版本)
查看Apache版本
httpd-v
查看PHP版本
php–v
查看MySQL版本
mysql-V
(注意大写)
以上是“CentOS使用本地yum源搭建LAMP环境的案例”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注恰卡编程网行业资讯频道!
相关文章
本站已关闭游客评论,请登录或者注册后再评论吧~