设为首页 收藏本站
查看: 1024|回复: 0

Centos 7编译安装 LAMP 环境

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-18 10:22:35 | 显示全部楼层 |阅读模式
                      前言
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安装
1
yum -y install httpd



    Centos 6:只能通过编译安装
     事先须安装Development Tools和Server Platform Development两个包组,同时还需要安装prce-devel程序包,prce包可通过yum安装
1
2
3
yum -y groupinstall "Development tools"
yum -y groupinstall "Server Platform Development"
yum -y prce-devel




httpd2.4需要1.4以上的版本apr和apr-util,故先get两者的源码包

apr的编译安装
1
2
3
4
tar xf apr-1.4.6.tar.bz2 -C /usr/local  //将源码包tar至/usr/local目录之下
cd /usr/local/apr-1.4.6                     
./configure  --prefix=/usr/local/apr     //对源码进行配置,指定安装目录
make && make install            //对源码进行编译安装



apr-util的编译安装
1
2
3
4
tar xf apr-util-1.4.1.tar.bz2 -C /usr/local
cd /usr/local/apr-util-1.4.1/
./configure --prefix=/usr/local/apr-util
make && make install



httpd的编译安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
tar xf httpd-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 && make install



其中./configure的相关参数可以使用./configure --help查看
以上为分列出各参数意义,故在排版上进行了分割,在配置中相关参数用空格分隔




二、mariadb的安装
Centos 6中默认使用的为MySQL,在Centos 7中默认使用的mariadb

mariadb的安装
1
2
yum -y install mariadb-server.x86_64
systemctl start mariadb         //启动mariadb服务



MySQL的安装
1
2
yum -y install mysql-server
service mysqld start



mariadb配置文件:/etc/my.cnf,/etc/my.cnf.d/*.cnf
修改/etc/my.cnf文件
加入以下值
1
2
innodb_file_per_table = ON            //生成数据库列表
skip_name_resolve = ON                //禁止反解



安装完成后,运行一次mysql_secure_installation,对mariadb进行配置。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[iyunv@chunlanyy ~]#  mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):              //初次运行直接回车
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n]                        //是否设置root用户密码,输入y并回车
New password:                                   //设置root用户的密码
Re-enter new password:                          //重复输入密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users?[Y/n]                    //是否删除匿名用户,删除
… Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]             //是否禁止root远程登录,禁止
… Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]     //是否删除test数据库,删除
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]              //是否重新加载权限表,重新加载
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!



进入mysql进行配置
相关格式:
mysql>GRANT ALL ON db_name.tbl_name To username@'host'IDENTIFIED BY "password"
1
GRANT ALL ON testdb.* TO 'root'@'172.16.%.%' IDENTIFIED BY "chunlanyy";



设置用户及密码
1
2
FLUSH PRIVILEGES;                  //清除权限
CREATE DATABASE testab;            //创建testab数据表单




三、php的安装
1
yum -y install php



编译安装:


四、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
将内容修改如下php测试代码
1
2
3
<php?
    phpinfo();
?>



重启httpd服务
systemctl restart httpd
通过浏览器访问172.16.45.21,即可看到phpinfo页面
其中虚拟主机的配置文件/etc/httpd/conf.d/virhost1.conf内容如下:
1
2
3
4
5
6
7
8
9
<VirtualHost *:80>
servername www1.chunlanyy.com
documentroot "/data/virhost/www1"
<Directory "/data/virhost/www1">
options none
allowoverride none
require all granted
</Directory>
</VirtualHost>



1
2
3
[iyunv@chunlanyy modules]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.45.21  netmask 255.255.0.0  broadcast 172.16.255.255




b.php连接mysql的测试
在前文已经配置好mariadb的情况下
将上述文件vim /data/virhost/www1/index.php内容修改如下:
1
2
3
4
5
6
7
<?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
                   


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-245716-1-1.html 上篇帖子: CentOS7下安装部署LAMP环境 下篇帖子: 基于RPM包的LAMP搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表