5----CentOS6.5源码搭建LAMP--基于module方式实现php(单台机器)

源码搭建LAMP


软件包下载源:

搜狐镜像源:http://mirrors.sohu.com/

apache下载网:http://mirror.bit.edu.cn/apache/

pcre官网:http://www.pcre.org/

apr官网:http://apr.apache.org/

apache官网:http://httpd.apache.org/

mysql官网:https://www.mysql.com/

php官网:http://php.net/

freetds:http://download.csdn.net/download/xhu_eternalcc/7457555

官网:http://www.freetds.org/


实验环境:

CentOS6.5-x86_64 单台机器

IP 192.168.9.168

版本:

apr-1.5.2

apr-util-1.5.4

httpd-2.4.20

php-5.6.22

mysql-5.6.32


说明,因为php要连接mysql,所以安装顺序为apache,mysql,php      

注:httpd2.4版本需要较新的apr和apr-util



注:新机器要初始化:参考http://wupengfei.blog.51cto.com/7174803/1955545

注:(生产环境一般包放内网ftp下载比较快,一般前端用nginx反向代理至后端apache+php机器,mysql独立并做集群)


1
一、编译安装apache
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
1、 #yum安装httpd依赖软件
[root@192-168-9-168 ~] # yum install -y gcc gcc-c++ libtool libtool-ltdl-devel \
make  gd-devel freetype-devel libxml2-devel \
libjpeg-devel libpng-devel openssl-devel patch  
[root@192-168-9-168 ~] # yum install -y curl-devel bzip2 pcre-devel zip2-devel bzip2-devel 
[root@192-168-9-168 ~] # yum install -y mcrypt-devel zlib-devel wget
 
2、 #编译安装apr
[root@192-168-9-168 ~] # cd /usr/local/src/
[root@192-168-9-168 src] # wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.bz2
[root@192-168-9-168 src] # tar xf apr-1.5.2.tar.bz2 
[root@192-168-9-168 src] # cd apr-1.5.2
[root@192-168-9-168 apr-1.5.2] # ./configure --prefix=/usr/local/apr
[root@192-168-9-168 apr-1.5.2] # make && make install
 
3、编译安装apr-util
[root@192-168-9-168 apr-1.5.2] # cd /usr/local/src/
[root@192-168-9-168 src] # wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2
[root@192-168-9-168 src] # tar xf apr-util-1.5.4.tar.bz2
[root@192-168-9-168 src] # cd apr-util-1.5.4
[root@192-168-9-168 apr-util-1.5.4] # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@192-168-9-168 apr-util-1.5.4] # make && make install
 
4、编译安装httpd
[root@192-168-9-168 apr-util-1.5.4] # useradd -s /sbin/nologin www
[root@192-168-9-168 apr-util-1.5.4] # cd /usr/local/src/
[root@192-168-9-168 src] # wget http://apache.fayea.com//httpd/httpd-2.4.20.tar.bz2 
[root@192-168-9-168  src] # tar xf httpd-2.4.20.tar.bz2 
[root@192-168-9-168  src] # cd httpd-2.4.20 
[root@192-168-9-168 httpd-2.4.20] # ./configure --prefix=/usr/local/apache \
--with-apr= /usr/local/apr  \
--with-apr-util= /usr/local/apr-util/  \
-- enable -so \
-- enable -ssl \
-- enable -cgi \
-- enable -rewrite \
--with-zlib \
--with-pcre \
-- enable -modules=most \
-- enable -mpms-shared=all \
--with-mpm=prefork
[root@192-168-9-168 httpd-2.4.20] # make
[root@192-168-9-168 httpd-2.4.20] # make install
[root@192-168-9-168 httpd-2.4.20] # sed -i 's/User daemon/User www/g' /usr/local/apache/conf/httpd.conf
[root@192-168-9-168 httpd-2.4.20] # sed -i 's/Group daemon/Group www/g' /usr/local/apache/conf/httpd.conf
[root@192-168-9-168 httpd-2.4.20] # sed -i "/ServerName/s/#ServerName.*/ServerName localhost/g" /usr/local/apache/conf/httpd.conf
 
 
6、启动方法
[root@192-168-9-168 httpd-2.4.20] #/usr/local/apache/bin/apachectl -k start|reload|restart|stop
 
7、测试验证
[root@192-168-9-168 httpd-2.4.20] # curl -I http://192.168.9.168
HTTP /1 .1 200 OK
Date: Fri, 11 Aug 2017 15:22:43 GMT
Server: Apache /2 .4.20 (Unix)
Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT
ETag:  "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45
Content-Type: text /html


二、编译安装MySQL

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
1、 #下载安装包
[root@192-168-9-168 httpd-2.4.20] # cd /usr/local/src/
[root@192-168-9-168 src] # wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
 
2、 #建立运行mysql用户和组为系统账号  
[root@192-168-9-168 src] # groupadd -r mysql
[root@192-168-9-168 src] # useradd -r -g mysql -s /sbin/nologin mysql
 
3、 #编译安装
[root@192-168-9-168 src] # yum install -y libaio libaio-devel numactl numactl-devel cmake ncurses-devel libxml2-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel
[root@192-168-9-168 src] # tar xf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz
[root@192-168-9-168 src] # mv mysql-5.6.37-linux-glibc2.12-x86_64 /usr/local/mysql
#建议mysql使用独立设备独立目录,本实验只建立目录,独立设备请参考磁盘分区与挂载
[root@192-168-9-168 src] # mkdir -p /data0/mysql
#更改属主属组
[root@192-168-9-168 src] # chown -R mysql.mysql /usr/local/mysql
#初始化数据库
[root@192-168-9-168 src] # cd /usr/local/mysql
[root@192-168-9-168 mysql] # ./scripts/mysql_install_db --datadir=/data0/mysql --user=mysql
[root@192-168-9-168 mysql] # cp ./support-files/my-default.cnf /data0/mysql/my.cnf
[root@192-168-9-168 mysql] # echo "basedir = /usr/local/mysql
datadir =  /data0/mysql
port = 3306
server_id = 1000
socket =  /tmp/mysql .sock" >> /data0/mysql/my .cnf
[root@192-168-9-168 mysql] # chown -R mysql.mysql /data0/mysql/
4,启动:
[root@192-168-9-168 mysql] # /usr/local/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/my.cnf &
[root@192-168-9-168 mysql] # echo "/usr/local/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/my.cnf &" >> /etc/rc.d/rc.local
 
6、 #安全初始化
#安全验证初始化,设置root用户密码,删除匿名用户,禁止root用户远程连接,删除test库
[root@192-168-9-168 mysql] # ./bin/mysql_secure_installation
#导出头文件
[root@192-168-9-168 mysql] # ln -sv /usr/local/mysql/include/ /usr/include/mysql
#加载库文件
[root@192-168-9-168 mysql] # echo "/usr/local/mysql/lib/mysql/" >>/etc/ld.so.conf
[root@192-168-9-168 mysql] # ldconfig
[root@192-168-9-168 mysql] # echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile


三、编译安装PHP

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
1、 #编译安装libmcrypt扩展
[root@192-168-9-168 src] # cd /usr/local/src/
[root@192-168-9-168 src] # wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
[root@192-168-9-168 src] # tar xf libmcrypt-2.5.7.tar.gz 
[root@192-168-9-168 src] # cd libmcrypt-2.5.7
[root@192-168-9-168 libmcrypt-2.5.7] # ./configure
[root@192-168-9-168 libmcrypt-2.5.7] # make && make install
 
2、 #编译安装freetds扩展
[root@c  local ] # cd /usr/local/src/
[root@c src] # wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
[root@192-168-9-168 src] # tar xf freetds-patched.tar.gz 
[root@192-168-9-168 src] # cd freetds-1.00.53/
[root@192-168-9-168 freetds-1.00.53] # ./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib 
[root@192-168-9-168 freetds-1.00.53] # make && make install
[root@192-168-9-168 freetds-1.00.53] # export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/
 
4、 #下载安装包
[root@192-168-9-168 src] # cd /usr/local/src/
[root@192-168-9-168 src] # wget http://cn2.php.net/distributions/php-5.6.22.tar.bz2
[root@192-168-9-168 src] # tar xf php-5.6.22.tar.bz2 
[root@192-168-9-168 src] # cd php-5.6.22
[root@192-168-9-168 php-5.6.22] #  ./configure --prefix=/usr/local/php \
--with-mysql= /usr/local/mysql/  \
--with-openssl \
--with-mysqli= /usr/local/mysql/bin/mysql_config  \
-- enable -mbstring \
--with-freetype- dir  \
--with-jpeg- dir  \
--with-png- dir  \
--with-zlib \
--with-libxml- dir = /usr/  \
-- enable -xml \
-- enable -sockets \
--with-apxs2= /usr/local/apache/bin/apxs  \
--with-mcrypt \
--with-mssql= /usr/local/freetds  \
--with-bz2 \
-- enable -maintainer-zts \
--with-curl \
-- enable - ftp  \
-- enable -bcmath \
--with-gd \
--with-freetype- dir  \
-- enable -gd-native-ttf \
--with-iconv- dir  \
-- enable -mbstring \
-- enable -calendar \
--with-gettext \
-- enable -dom \
-- enable -fpm
#说明:如果php5.3以上的版本,为了链接数据库,可以指定mysqlnd,这样本机就可以不用安装mysql和mysql开发包。5.4已经是默认设置。
如: --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
[root@192-168-9-168 php-5.6.22] # make
[root@192-168-9-168 php-5.6.22] # make install
 
#为php提供配置文件
[root@192-168-9-168 php-5.6.22] # cp php.ini-development /usr/local/php/etc/php.ini
 
5、编辑apache配置文件httpd.conf,apache支持php
[root@192-168-9-168 php-5.6.22] # sed -i '/LoadModule php5_module/ aAddType application/x-httpd-php-source .phps' /usr/local/apache/conf/httpd.conf
[root@192-168-9-168 php-5.6.22] # sed -i '/LoadModule php5_module/ aAddType application/x-httpd-php .php .php5' /usr/local/apache/conf/httpd.conf
[root@192-168-9-168 php-5.6.22] # sed -i '/DirectoryIndex/ s/index.html/index.php index.html/' /usr/local/apache/conf/httpd.conf
 
#重启httpd
[root@192-168-9-168 php-5.6.22] # /usr/local/apache/bin/apachectl -k restart
4、测试验证php
  "<?php
         phpinfo();
?>" >  /usr/local/apache/htdocs/index .php
5、浏览器访问:
http: //192 .168.9.168
5、测试验证php连接数据库
[root@192-168-9-168 php-5.6.22] # vim index.php 
 
<?php
         $link = mysql_connect( '127.0.0.1' , 'root' , '123456' );
         if  ($link)
              echo  "Success..." ;
         else
              echo  "Failure..." ;
         mysql_close()
?>
#浏览器访问
http: //192 .168.9.168
 
6、 #ab压力测试
[root@192-168-9-168 php-5.6.22] # ab -c 100 -n 10000 
 
四、测试Xcache为php加速
1、 #编译安装
[root@192-168-9-168 htdocs] # cd /usr/local/src/
[root@192-168-9-168 src] # tar xf xcache-3.2.0.tar.bz2 
[root@192-168-9-168 src] # cd xcache-3.2.0
[root@192-168-9-168 xcache-3.2.0] # /usr/local/php/bin/phpize
[root@192-168-9-168 xcache-3.2.0] # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config 
[root@192-168-9-168 xcache-3.2.0] # make && make install
2、 #编辑php.ini,整合php和xcache
[root@192-168-9-168 xcache-3.2.0] # mkdir -p /etc/php.d
[root@192-168-9-168 xcache-3.2.0] # cp xcache.ini /etc/php.d
 
 
#重启apache
[root@192-168-9-168 xcache-3.2.0] # apachectl -k restart
#压力测试,看效果









本文转自 wpf926 51CTO博客,原文链接:http://blog.51cto.com/wupengfei/1955720,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值