前言
LAMP 是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写
L:Linux 操作系统
A:Apache(httpd) 网页服务
M:MysqL(mariadb) 数据库服务
P:PHP/perl/python/ruby 脚本编程语言
本文主要以centos 7的环境下进行安装,centos 6兼带部分说明
一、http2.4的安装
Centos 7默认安装httpd 2.4,Centos 6默认安装httpd2.2
Centos 7:如果未安装http2.4,则通过yum安装
yum-yinstallhttpd
Centos 6:只能通过编译安装
事先须安装Development Tools和Server Platform Development两个包组,同时还需要安装prce-devel程序包,prce包可通过yum安装
yum-ygroupinstall"Developmenttools"
yum-ygroupinstall"ServerPlatformDevelopment"
yum-yprce-devel
httpd2.4需要1.4以上的版本apr和apr-util,故先get两者的源码包
apr的编译安装
tarxfapr-1.4.6.tar.bz2-C/usr/local//将源码包tar至/usr/local目录之下
cd/usr/local/apr-1.4.6
./configure--prefix=/usr/local/apr//对源码进行配置,指定安装目录
make&&makeinstall//对源码进行编译安装
apr-util的编译安装
tarxfapr-util-1.4.1.tar.bz2-C/usr/local
cd/usr/local/apr-util-1.4.1/
./configure--prefix=/usr/local/apr-util
make&&makeinstall
httpd的编译安装
tarxfhttpd-2.4.10.tar.bz2-C/usr/local
cd/usr/local/httpd-2.4.10
./configure--prefix=/usr/local/apache//指定安装目录
--sysconfdir=/etc/httpd24//指定配置文件目录
--enable-so//启用模块功能
--enable-ssl//启用ssl加密功能
--enable-cgi//启用cgi功能
--enable-rewrite//可重载
--with-zlib//使用zlib数据
--with-pcre/使用pcre数据
--with-apr=/usr/local/apr//所关联程序apr及目录
--with-apr-util=/usr/local/apr-util//所关联程序apr-util及目录
--enable-modules=most//最大程度启用所有模块
--enable-mpms-shared=all//分离列出所有MPM模块
--with-mpm=perfork//使用perfork模式
make&&makeinstall
其中./configure的相关参数可以使用./configure --help查看
以上为分列出各参数意义,故在排版上进行了分割,在配置中相关参数用空格分隔
二、mariadb的安装
Centos 6中默认使用的为MysqL,在Centos 7中默认使用的mariadb
mariadb的安装
yum-yinstallmariadb-server.x86_64
systemctlstartmariadb//启动mariadb服务
yum-yinstallMysqL-server
serviceMysqLdstart
mariadb配置文件:/etc/my.cnf,/etc/my.cnf.d/*.cnf
修改/etc/my.cnf文件
加入以下值
innodb_file_per_table=ON//生成数据库列表
skip_name_resolve=ON//禁止反解
安装完成后,运行一次MysqL_secure_installation,对mariadb进行配置。
[root@chunlanyy~]#MysqL_secure_installation
NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMysqL
SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!
InordertologintoMysqLtosecureit,we'llneedthecurrent
passwordfortherootuser.Ifyou'vejustinstalledMysqL,and
youhaven'tsettherootpasswordyet,thepasswordwillbeblank,soyoushouldjustpressenterhere.
Entercurrentpasswordforroot(enterfornone)://初次运行直接回车
OK,successfullyusedpassword,movingon…
SettingtherootpasswordensuresthatnobodycanlogintotheMysqL
rootuserwithouttheproperauthorisation.
Setrootpassword?[Y/n]//是否设置root用户密码,输入y并回车
Newpassword://设置root用户的密码
Re-enternewpassword://重复输入密码
Passwordupdatedsuccessfully!
Reloadingprivilegetables..
…Success!
Bydefault,aMysqLinstallationhasananonymoususer,allowinganyone
tologintoMysqLwithouthavingtohaveauseraccountcreatedfor
them.Thisisintendedonlyfortesting,andtomaketheinstallation
goabitsmoother.Youshouldremovethembeforemovingintoa
productionenvironment.
Removeanonymoususers?[Y/n]//是否删除匿名用户,删除
…Success!
Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This
ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.
Disallowrootloginremotely?[Y/n]//是否禁止root远程登录,禁止
…Success!
Bydefault,MysqLcomeswithadatabasenamed'test'thatanyonecan
access.Thisisalsointendedonlyfortesting,andshouldberemoved
beforemovingintoaproductionenvironment.
Removetestdatabaseandaccesstoit?[Y/n]//是否删除test数据库,删除
-Droppingtestdatabase…
…Success!
-Removingprivilegesontestdatabase…
…Success!
Reloadingtheprivilegetableswillensurethatallchangesmadesofar
willtakeeffectimmediately.
Reloadprivilegetablesnow?[Y/n]//是否重新加载权限表,重新加载
…Success!
Cleaningup…
Alldone!Ifyou'vecompletedalloftheabovesteps,yourMysqL
installationshouldnowbesecure.
ThanksforusingMysqL!
进入MysqL进行配置
相关格式:
MysqL>GRANT ALL ON db_name.tbl_name To username@'host'IDENTIFIED BY "password"
GRANTALLONtestdb.*TO'root'@'172.16.%.%'IDENTIFIEDBY"chunlanyy";
设置用户及密码
FLUSHPRIVILEGES;//清除权限
CREATEDATABASEtestab;//创建testab数据表单
三、PHP的安装
yum-yinstallPHP
编译安装:
四、LAMP环境测试:
因为httpd作为http协议实现的服务器,只能静态的响应和处理客户端的请求,为了使得服务器能动态的响应客户端的请求,有三种方法实现:
1)使用CGI协议:httpd服务器通过CGI协议将请求转发至程序的解释器,解释器将运行结果返回httpd服务器,随后解释器销毁
2)使用module,把PHP编译成httpd的扩展模块,通过httpd动态调用模块来实现
3)fastCGI:通过fpm(fastcgi process manager)让PHP单独运行一个类型apache的模型服务,监听某个套接字,并生成多个子进程来处理响应,而主进程只负责管理请求和控制子进程的运行状况,此时http变成fastCGI的客户端,而fastCGI变成一个简化版的http协议使PHP和http进行通信使用。
PHP和http常用的结合方式通过编译httpd的PHP处理模块,让httpd自己处理PHP程序,或者使用专门的PHP应用程序服务器PHP-fpm,由它来负责处理PHP程序。
a.PHP与httpd结合的测试
修改之前配置好的虚拟主机的数据文件
将/data/virhost/www1/index.html更改为/data/virhost/www1/index.PHP
vim/data/virhost/www1/index.PHP
PHPinfo();
?>
重启httpd服务
systemctl restart httpd
通过浏览器访问172.16.45.21,即可看到PHPinfo页面
其中虚拟主机的配置文件/etc/httpd/conf.d/virhost1.conf内容如下:
servernamewww1.chunlanyy.com
documentroot"/data/virhost/www1"
optionsnone
allowoverridenone
requireallgranted
[root@chunlanyymodules]#ifconfig
eno16777736:flags=4163mtu1500
inet172.16.45.21netmask255.255.0.0broadcast172.16.255.255
在前文已经配置好mariadb的情况下
将上述文件vim/data/virhost/www1/index.PHP内容修改如下:
$conn=MysqL_connect('172.16.45.21','root','chunlanyy');
if($conn)
echo"OK";
else
echo"Failure";
?>
当启动PHP服务时,通过浏览器访问172.16.45.21时,显示ok表明连接正常
systemctl stop PHP显示Failure
总结
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
小编个人微信号 jb51ccc
喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!