拓扑图
Apache+php的搭建:
httpd-2.4.4.tar.bz2
apr-1.4.6.tar.gz
apr-1.4.6.tar.gz 需要这3个软件包
[[email protected] ~]# tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/ 解压apr软件包
[[email protected] ~]# tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/ 解压aprutil软件包
[[email protected] ~]# tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ 解压httpd软件包
[[email protected] ~]# cd /usr/local/src/apr-1.4.6/ 进入apr目录
[[email protected] apr-1.4.6]# ./configure --prefix=/usr/local/apr 进行编译
[[email protected] apr-1.4.6]# make && make install 安装
[[email protected] apr-1.4.6]# cd ../apr-util-1.5.1/ 切换到apr-util目录
[[email protected] apr-util-1.5.1]# ./configure --prefix=/usr/local/apr-utils --with-apr=/usr/local/apr/bin/apr-1-config 编译,指定工具安装路径,指定apr的路径
[[email protected] apr-util-1.5.1]# make && make install 进行编译安装
[[email protected] apr-util-1.5.1]# cd ../httpd-2.4.4/ 配置httpd
./configure \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-ssl \
--enable-rewrite \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr-util/bin/apu-1-config \
--with-pcre \
--with-z \
--enable-mpms-shared=all 进行编译配置
出现错误提示,需要安装pcre-devel包
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install pcre-devel -y 安装包
然后再进行编译配置
出现这个错误提示,需要安装[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install openssl-devel -y
再进行编译配置通过后
[[email protected] httpd-2.4.4]# make && make install 配置安装
完成后
[[email protected] httpd-2.4.4]# cd /usr/local/apache/ 进入apache目录
[[email protected] apache]# vim /etc/profile 编辑profile文件
/usr/local/apache/bin 增加新的路径
[[email protected] apache]# . /etc/profile 进行更新
[[email protected] apache]# httpd -k start 测试是否能启动
[[email protected] apache]# netstat -tupln |grep 80 查看80端口是否开启
[[email protected] apache]# vim /etc/man.config 编辑man配置文件
加入MANPATH /usr/local/apache/man
[[email protected] apache]# man ab 尝试下是否生效
[[email protected] apache]# cd /usr/include/ 进入include目录
[[email protected] include]# ln -s /usr/local/apache/include/ apache 做个链接
[[email protected] ~]# cd /etc/init.d/ 进入目录
[[email protected] init.d]# touch httpd 创建httpd文件
[[email protected] init.d]# chmod a+x httpd 加入可执行权限
[[email protected] init.d]# vim httpd 进行编辑
#!/bin/bash
2 prog=/usr/local/apache/bin/httpd
3 lockfile=/var/lock/subsys/httpd
4 # description: the apache service
5 # chkconfig: 2345 88 44
6 start(){
7 if [ -e $lockfile ];then
8 echo "the apache service is started"
9 else
10 echo -n "the apache service is starting ...."
11 sleep 1
12 $prog -k start && echo "ok" && touch $lockfile || echo "failer"
13 fi
14
15 }
16
17 stop(){
18 if [ !e $lockfile ];then
19 echo "the apache service is stopped"
20 else
21 echo "the apache service is stoping..."
22 $prog -k stop && echo "ok" && rm -rf $lockfile || echo "failer"
23 fi
24
25 }
26
27
28 case "$1" in
29 start)
30 start
31 ;;
32 stop)
33 stop
34 ;;
35 restart)
36 stop
37 start
38 ;;
39 *)
40 echo "Usage: start|stop|restart"
41 ;;
42 esac
添加此代码来实现httpd启动关闭动态效果
[[email protected] init.d]# chkconfig --add httpd 加入httpd服务
[[email protected] init.d]# chkconfig --list |grep httpd 查看服务启动
PHP源码安装
[[email protected] ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ 解压软件包
[[email protected] ~]# cd /usr/local/src/php-5.5.8/ 进入目录
[[email protected] php-5.5.8]# ./configure \
./configure \
--prefix=/usr/local/php \
--enable-fpm \
--enable-sockets \
--with-mysql=mysqlnd \ (使用mysqlnd模块调用另外主机的mysql)
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--enable-xml \
--with-png-dir \
--with-jpeg-dir \
--with-zlib \
--with-freetype-dir \
--with-config-file-path=/etc/php \
--with-config-file-scan-dir=/etc/php5.d 配置编译
接下来需要make && make isntall 因为时间比较长,睡眠的时候可能连接断开所以需要screen来实现安装
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install screen -y 安装screen
[[email protected] php-5.5.8]# screen 使用screen
又打开了一个窗口 ctrl+a+d可以离开 screen -ls可以查看
恢复的话 screen -r 编号
[[email protected] php-5.5.8]# make && make install 然后进行后台配置安装
安装完成后:
[[email protected] php-5.5.8]# cd /usr/local/apache/modules/ 进入模块目录
[[email protected] modules]# ll |grep php
-rwxr-xr-x. 1 root root 23450184 Aug 24 06:41 libphp5.so 查看是否有php模块
[[email protected] modules]# vim /etc/httpd/httpd.conf 进入配置文件
加入此语句 AddType application/x-httpd-php .php
加入 index.php
[[email protected] modules]# service httpd restart 重启httpd
进行测试apache是否能与php进行结合
[[email protected] modules]# cd ../htdocs/
[[email protected] htdocs]# vim index.php 创建一个网页文件
写入此函数
[[email protected] htdocs]# mkdir /etc/php /etc/php5.d 创建2个目录
[[email protected] htdocs]# cd /usr/local/src/php-5.5.8/
[[email protected] php-5.5.8]# cp php.ini-production /etc/php/php.ini 拷贝文件到php.ini
[[email protected] php-5.5.8]# service httpd restart 重启httpd
然后输入网页查看下
成功与php进行了关联
memcached的搭建
在开一台虚拟机,将ip地址设为仅主机模式并将ip地址设置为192.168.3.101
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media install lftp telnet -y 安装常用的软件包
下载这memecached软件包
还有libevent软件
[[email protected] ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/
[[email protected] ~]# tar -zxvf memcached-1.4.13.tar.gz -C /usr/local/src/ 拆解包
[[email protected] ~]# cd /usr/local/src/libevent-2.0.16-stable/ 进入目录
[[email protected] libevent-2.0.16-stable]# ./configure --prefix=/usr/local/libevent 进行配置(需要安装开发包)
[[email protected] libevent-2.0.16-stable]# make && make install
[[email protected] libevent-2.0.16-stable]# cd /usr/local/libevent/ 切换到目录
[[email protected] libevent]# vim /etc/ld.so.conf.d/libevent.conf 编辑配置文件导出库
/usr/local/libevent/lib
编辑为此
[[email protected] libevent]# ldconfig 刷新缓存
[[email protected] libevent]# ldconfig -pv |grep libevent 查看是否成功
[[email protected] libevent]# cd /usr/local/src/memcached-1.4.13/ 切换到此目录
[[email protected] memcached-1.4.13]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/ 进行配置
[[email protected] memcached-1.4.13]# make && make install 进行安装
[[email protected] memcached-1.4.13]# cd /usr/local/memcached/ 进入目录
[[email protected] memcached]# vim /etc/profile
加入path路径
[[email protected] memcached]# . /etc/profile 刷新缓存
[[email protected] memcached]# memcached -h 查看memcached的帮助
[[email protected] memcached]# memcached -d -m 64 -p 11211 -u nobody -vv 开启memcached
[[email protected] memcached]# telnet 127.0.0.1 11211 登录进去进行测试
stats 查看状态
set foo 0 0 3 设置一个键值
bar 存储值
get foo 取键值查看
quit 退出
[[email protected] memcached]# service iptables stop 关闭防火墙
[[email protected] memcached]# chkconfig iptables off
[[email protected] memcached]# setenforce 0
Apache+php主机
下载memcache软件
[[email protected] ~]# tar -zxvf memcache-2.2.5.tgz -C /usr/local/src/ 进行解压
[[email protected] ~]# cd /usr/local/src/memcache-2.2.5/
[[email protected] memcache-2.2.5]# /usr/local/php/bin/phpize 执行php扩展
[[email protected] memcache-2.2.5]# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config 进行memechache配置
[[email protected] memcache-2.2.5]# make && make install 进行安装
[[email protected] memcache-2.2.5]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/ 进入目录
[[email protected] no-debug-non-zts-20121212]# ll
total 1348
-rwxr-xr-x. 1 root root 216204 Sep 13 07:22 memcache.so
-rwxr-xr-x. 1 root root 687720 Sep 12 18:44 opcache.a
-rwxr-xr-x. 1 root root 472259 Sep 12 18:44 opcache.so 可以查看到相应的模块
[[email protected] no-debug-non-zts-20121212]# cp memcache.so /etc/php 将模块拷贝到/etc/php目录下
[[email protected] no-debug-non-zts-20121212]# vim /etc/php/php.ini 编辑php.ini文件
将模块进行如上改变
[[email protected] no-debug-non-zts-20121212]# service php-fpm restart 重启php
进入页面查看是否有memcache模块
有该模块
进行测试
[[email protected] no-debug-non-zts-20121212]# cd /usr/local/apache/htdocs/ 进入目录
[[email protected] htdocs]# vim index2.php
<?php
error_reporting(E_ALL & ~E_NOTICE);
$mc = new memcache;
$mc->addServer("192.168.3.101", 11211);
$mc->set("foo", "Hello!");
$mc->set("bar", "Memcached...");
$arr = array(
$mc->get("foo"),
$mc->get("bar")
);
var_dump($arr);
?>
编辑此测试页面
[[email protected] memcached]# tenlent 127.0.0.1 11211 telnet进入memachaed
stats 查看状态
get2次 set 1次
访问此页面
出现此更新
set get 变化了