温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS使用本地yum源搭建LAMP环境的方法

发布时间:2022-05-07 16:22:20 来源:亿速云 阅读:106 作者:iii 栏目:大数据

今天小编给大家分享一下CentOS使用本地yum源搭建LAMP环境的方法的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

【准备工作】

配置防火墙,开启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端口通过防火墙

CentOS使用本地yum源搭建LAMP环境的方法

重启防火墙使配置生效

/etc/init.d/iptables restart

关闭selinux

vi /etc/selinux/config
#selinux=enforcing #注释掉
#selinuxtype=targeted #注释掉
selinux=disabled #增加
:wq! #保存退出

重启系统

shutdown -r now

【安装apache】

执行安装

yum -y install httpd

启动apache

service httpd restart

或:

/etc/init.d/httpd start

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!#保存退出

设为开机启动

chkconfig httpd on

检查安装 访问主机地址 如图所示安装成功

CentOS使用本地yum源搭建LAMP环境的方法

修改apache配置

vi /etc/httpd/conf/httpd.conf #建议使用ftp工具 修改之前做好备份

修改如下:

servertokens os  #在44行 修改为:servertokens prod (在出现错误页的时候不显示服务器操作系统的名称)
serversignature on  #在536行修改为:serversignature off (在错误页中不显示apache的版本)
options indexes followsymlinks  #在331行修改为:options includes execcgi followsymlinks(允许服务器执行cgi及ssi,禁止列出目录)
#addhandler cgi-script .cgi #在796行 修改为:addhandler cgi-script .cgi .pl (允许扩展名为.pl的cgi脚本运行)
allowoverride none  #在338行修改为:allowoverride all (允许.htaccess)
adddefaultcharset utf-8 #在759行 修改为:adddefaultcharset gb2312 (添加gb2312为默认编码)
options indexes multiviews followsymlinks #在554行 修改为options multiviews followsymlinks(不在浏览器上显示树状目录结构)
directoryindex index.html index.html.var #在402行 修改为:directoryindexindex.html index.htm default.html default.htm index.php default.phpindex.html.var (设置默认首页文件,增加index.php)
keepalive off #在76行 修改为:keepalive on (允许程序性联机)
maxkeepaliverequests 100 #在83行 修改为:maxkeepaliverequests1000 (增加同时连接数)

删除两个默认测试页

rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html

重启apache

service httpd restart

/etc/init.d/httpd restart

【安装mysql

执行安装

yum -y install mysql mysql-server

启动mysql

/etc/init.d/mysqld start

设为开机启动

chkconfig mysqld on

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

cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

为root账户设置密码

mysql_secure_installation
#回车,根据提示输入y,输入2次密码,回车,根据提示一路输入y最后出现:thanks for using mysql设置完成

或者

mysqladmin -u root password '密码'

允许远程登录

mysql -u root -p

输入密码
输入mysql命令:

grant all privileges on *.* to 'root'@'%' identified by '密码' with grant option;

退出mysql:exit

重启mysql

service mysqld restart

【安装php5】

执行安装

yum -y install php

安装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

service mysqld restart
service httpd restart

(到此完成yum源搭建lamp环境,我们可以查看一下各部分的安装版本)

查看apache版本

httpd -v

CentOS使用本地yum源搭建LAMP环境的方法

查看php版本

php –v

CentOS使用本地yum源搭建LAMP环境的方法

查看mysql版本

mysql -v

(注意大写)

CentOS使用本地yum源搭建LAMP环境的方法

以上就是“CentOS使用本地yum源搭建LAMP环境的方法”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI