一、安装组件和依赖包
yum install �Cy gcc gcc-c++ make cmake ncurses-devel libxml2-devel perl-devel libcurl-devel libgcrypt libgcrypt-devel libxslt libxslt-devel pcre-devel openssl-devel 1.安装apr tar zxvf apr-1.4.6.tar.gz cd apr-1.4.6 ./configure --prefix=/usr/local/apr make && make install 2.安装apr-utils tar zxvf apr-util-1.4.1.tar.gz cd apr-util-1.4.1 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install
二、安装httpd
tar zxvf httpd-2.4.3.tar.gz cd httpd-2.4.3 ./configure -prefix=/usr/local/apache -enable-so -enable-rewrite -enable-modules=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util make && make install /usr/local/apache/bin/apachectl start cp /usr/local/apache/bin/apachectl /etc/init.d/httpd chmod +x /etc/init.d/httpd service httpd start echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.local #开机启动
http://127 .0.0.1访问测试,会显示it works页面!
提示:apr、apr-util还有依赖包一定要安装好,要不然会各种报错!
二、安装mysql
下载:http://dev.mysql.com/downloads/mysql/5.5.html
1、创建组和用户
groupadd mysql useradd -g mysql -s /sbin/nologin mysql
2、安装mysql
tar zxvf mysql-5.5.34.tar.gz cd mysql-5.5.34 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DSYSCONFDIR=/usr/local/mysql/etc -DMYSQL_DATADIR=/usr/local/mysql/data make && make install
3、初始化并配置
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql #初始化数据库 mkdir /usr/local/mysql/etc cp support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile #添加执行命令环境变量 source /etc/profile #生效环境变量 chown -R root.mysql /usr/local/mysql/ chown -R mysql:mysql mysql/data/ #赋予数据存放目录权限 mysqld_safe --user=mysql& #启动mysql rm -rf /etc/my.cnf #***mysql以前的配置文件,否则有时会起不来 service mysqld start mysqladmin -u root password '123456'#设置root登录密码 chkconfig mysqld on
三、安装php
1、yum安装gd库
yum install �Cy gd freetype freetype-devel libpng libpng-devel zlib zlib-devel libjpeg*
补充:编译安装gd库(需要安装php时候指定gd、zlib、jpeg、png和freetype安装目录)
1>.安装zlib
tar zxvf zlib-1.2.5.1.tar.gz cd zlib-1.2.5.1 ./configure �Cprefix=/usr/local/gd/zlib make && make install
2>.安装jpeg
mkdir-P /usr/local/gd/jpeg/include mkdir-P /usr/local/gd/jpeg/lib mkdir-P /usr/local/gd/jpeg/bin mkdir-P /usr/local/gd/jpeg/man/man1 tarzxvf jpegsrc.v6b.tar.gz cd jpegsrc.v6b ./configure �Cprefix=/usr/local/gd/jpeg make && make install
编译中可能报错:make: ./libtool:命令未找到 make: *** [cjpeg.lo] 错误 127
解决:
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
3>.安装libpng
tar zxvf libpng-1.5.6.tar.gz cd libpng-1.5.6 ./configure �Cprefix=/usr/local/gd/libpng make && make install
编译中可能报错:configure: error: zlib not installed
进入zlib-1.2.6的源文件目录,执行命令 make clean,清除zlib;
重新配置 ./configure,后面不要加�Cprefix参数;
再make && make install;
4>.安装freetype
tar zxvf freetype-2.4.6.tar.gz cdfreetype-2.4.6 ./configure �Cprefix=/usr/local/gd/freetype make && make install
5>.安装gd
tar zxvf gd-2.0.33.tar.gz cd gd-2.0.33 ./configure �Cprefix=/usr/local/gd/gd2 �Cwith-zlib=/usr/local/gd/zlib �Cwith-jpeg=/usr/local/gd/jpeg �Cwith-png=/usr/local/gd/libpng �Cwith-freetype=/usr/local/gd/freetype make && make install
编译中可能报错:gd_png.c:92: error: expected ‘)’ before ‘png_ptr’
解决:vi gd_png.c
将#include “png.h” 替换成:#include “/usr/local/gd/libpng/include/png.h”
安装成功后,/usr/local/gd/gd2/include生成gd.h和libgd.a的文件
安装加密算法扩展库libmcrypt
下载:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
tar zxvf libmcrypt-2.5.3.tar.gz cd libmcrypt-2.5.3 ./configure --prefix=/usr/local/libmcrypt make && make install ldconfig -v cd libltdl ./configure --with-gmetad --enable-gexec --enable-ltdl-install make && make install ln -sv /usr/local/lib/libmcrypt* /usr/lib #链接到默认搜索库目录
2、安装php
tar zxvf php-5.4.4.tar.gz cd php-5.4.4 ./configure -prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-apxs2=/usr/local/apache/bin/apxs \ --with-mysql=/usr/local/mysql \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --enable-soap --enable-bcmath --enable-zip --enable-ftp \ --enable-mbstring --with-gd --with-libxml-dir --with-jpeg-dir \ --with-png-dir --with-freetype-dir --with-zlib \ --with-curl --with-xsl --with-openssl make && make install cp php.ini-production /usr/local/php/etc/php.ini vi /usr/local/php/etc/php.ini date.timezone = Asia/Shanghai #设置时区 expose_php = OFF #禁止显示版本信息
注:如果mysql是rpm安装的则--with-mysql即可!
参考基本完整的php配置:
./configure报错:./configure: /usr/local/apache/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
解决:vi /usr/local/apache/bin/apxs把第一行改为#!/usr/bin/perl -w即可!
3、添加apache支持php
vi /usr/local/apache/conf/httpd.conf ServerName 本地ip:80 #在AddType application/x-gzip .gz .tgz下面添加php页面支持 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps LoadModule php5_module modules/libphp5.so #编译php时候加--with-apxs2参数才会自动生成 DirectoryIndex index.html index.php #找到这一行,添加index.php索引页
4、测试
chown apache.apache /usr/local/apache/htdocs -R #设置目录所有者 chmod 774 /usr/local/apache/htdocs -R #设置目录权限 service httpd restart service mysqld restart vi index.php <?php phpinfo();?>
输入:http://127.0.0.1 #可以看到相关的配置信息!
四、安装memcached
Memcache缓存数据库:减少数据库压力。高性能的分布式内存缓存服务器,用于动态Web应用,减少I/O,提高web访问速度以减轻数据库负载,以提高动态Web应用的速度、提高可扩展性。利用 Memcached 处理实时数据读写;MySQL是影响性能的最大瓶颈,可以用一台MySQL主库(只写)+多台MySQL辅库(只读)的主辅库集群来解决。另外,访问计数等实时性很强的东西用Memcache做缓存。基于c#语言写的调用libevent库事件来实现。
http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz
http://pecl.php.net/get/memcache-3.0.6.tgz
1、安装libevent
yum install -y libevent libevent-devel
2、安装memcached
tar zxvf memcached-1.4.15.tar.gz cd memcached-1.4.15 ./configure make && make install
3、安装Memcache客户端PHP扩展
tar vxzf memcache-3.0.6.tgz cd memcache-3.0.6 /usr/local/php/bin/phpize ./configure �Cwith-php-config=/usr/local/php/bin/php-config make && make install
4、在php.ini添加memcache模块
vi /etc/php.ini extension=memcache.so
5、启动memcached服务端
/usr/local/bin/memcached -d -m 128 -l 192.168.0.10 -p 11211 killall -9 memcached #关闭memcached
-d:选项是启动一个守护进程,
-m:是分配给Memcache使用的内存数量,单位是MB
-u:是运行Memcache的用户
-l:是监听的服务器IP地址
-p:是设置Memcache监听的端口,最好是1024以上的端口
-c:选项是最大运行的并发连接数,默认是1024,根据你服务器的负载量来设定
-P:是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
客户端测试
telnet 192.168.0.202 11211
或phpinfo查看是否被加载模块
常用命令:status、version、flush_all、quit、get、add、set等