搭建环境
虚拟机:VMware-workstation-full-8.0.3-703057.zip linux版本:CentOS-5.4-i386-bin-DVD.iso 一,VM,CentOS安装 略.... 二,centos基本配置 1,安装vim yum -y install vim-enhanced 2,配置vim显示行号 如果是用的普通用户的话在home目录下建一个.vimrc文件(记着,原来没有,要新创一个文件)里 面加一行setnu如果你想对所有用户都这样,那么在/etc/vimrc文件中加入这一行。/etc/vimrc是所有用户 启动vim时都会执行的。每个用户的home目录下的.vimrc是这个用户启动vim时会执行的 3,升级firefox,参见 4,解决firefox中文乱码 a.下载两个rpm包 fonts-chinese-3.02-9.6.e15.noarch.rpm fonts-ISO8859-2-75dpi-1.0-17.1.noarch.rpm 然后安装rmp rpm -zxf "xxx.rpm" 或yum install xxx.rpm 设置forefox:语言(中国) 然后重起计算机运行 fc-cache -fv清除下cache,这样firefox就可以显 示中文了 b.vi /etc/sysconfig/i18n配置 LANG="en_US.UTF-8" SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en" SYSFONT="latarcyrheb-sun16" 三,安装mysql [root@localhost]# yum install mysql mysql-server [root@localhost]# service mysqld restart [root@localhost]# chkconfig --level 3 mysqld on [root@localhost]# mysqladmin -u root password root [root@localhost]# netstat -alp | grep 'mysql' 四,安装lighttpd [root@localhost]# wget 1.el5.rf.i386.rpm [root@localhost]# rpm -ivh rpmforge-release-0.5.1-1.el5.rf.i386.rpm [root@localhost]# yum install lighttpd [root@localhost]# chkconfig --level 3 lighttpd on [root@localhost]# /etc/init.d/lighttpd start [root@localhost]# chown lighttpd:lighttpd /var/log/lighttpd 五,安装PHP5(fastcgi) [root@localhost]# yum install lighttpd-fastcgi php-cli 六,配置lighttpd与PHP 1,修改默认端口为8080,把80端口给nginx vi /etc/lighttpd/lighttpd.conf修改 server.port = 8080 2,vi /etc/lighttpd/modules.conf修改 server.modules = ( "mod_access", "mod_alias", # "mod_auth", # "mod_evasive", # "mod_redirect", "mod_rewrite", # "mod_setenv", # "mod_usertrack", ) 开启相关模块 alias.url = ( "/phpmyadmin" => "/usr/share/phpmyadmin") #配置phpmyadmin include "conf.d/fastcgi.conf" #打开fastcgi配置 ####配置虚拟主机 在/var/www/中建三个PHP项目,project1,project2,project3,分别输出 vim index.php echo "this is project x"; ####多域名配置多个项目 $HTTP["host"] == "www.project1.com" { server.name = "www.project1.com" server.document-root = "/var/www/project1" server.errorlog = "/var/www/project1/error.log" accesslog.filename = "/var/www/project1/access.log" } else $HTTP["host"] == "www.project2.com" { server.name = "www.project2.com" server.document-root = "/var/www/project2" server.errorlog = "/var/www/project2/error.log" accesslog.filename = "/var/www/project2/access.log" } else $HTTP["host"] == "www.project3.com" { server.name = "www.project3.com" server.document-root = "/var/www/project3" server.errorlog = "/var/www/project3/error.log" accesslog.filename = "/var/www/project3/access.log" } ####多端口配置 $SERVER["socket"] == ":8001" { server.document-root = "/var/www/project1" } else $SERVER["socket"] == ":8002" { server.document-root = "/var/www/project2" } else $SERVER["socket"] == ":8003" { server.document-root = "/var/www/project3" } 3,fastcgi配置 vi /etc/lighttpd/conf.d/fastcgi.conf 填加如下内容 fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi", ) ) ) 4,配置PHP vim /etc/php.ini #增加如下两行: cgi.fix_pathinfo = 1 extension=mysql.so #用于phpmyadmin来管理mysql数据库 [root@localhost]# chown lighttpd:lighttpd /var/lib/php/session #因为修改了lighttpd.conf配置文件,所以得重新启动服务 [root@localhost]# service lighttpd restart 5,重启lighttpd service lighttpd restart 重启报错 Starting lighttpd: 2012-05-22 22:21:52: (server.c.722)couldn't set 'max filedescriptors' Operation not permitted 先执行setenforce 0 临时关闭selinux (修改selinux:vi /etc/selinux/config) 重新启动成功 6,测试 访问 http://localhost:8080输出phpinfo信息,成功 分别访问 http://localhost:8001 http://localhost:8002 http://localhost:8003 得到正确显示分别为 this is project 1 this is project 2 this is project 3 七,让PHP支持MYSQL模块 #查看有哪些PHP支持且可安装的模块 [root@localhost]# yum search php | grep '^php' [root@localhost]# yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-tidy php-snmp php-mhash php-mcrypt php-mbstring [root@localhost]# service lighttpd restart 八,安装phpmyadmin与配置 (1),安装phpmyadmin [root@localhost]# yum install phpmyadmin 注意:使用phpmyadmin的RPM包软件时,默认是安装在/usr/share目录下 (2)、配置phpmyadmin [root@localhost]# cd /usr/share/phpmyadmin [root@example phpmyadmin]# cp config.sample.inc.php config.inc.php [root@example phpmyadmin]# vi config.inc.php $cfg['Servers'][$i]['auth_type'] = 'http'; #把cookie方式改为http方式即可 $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; $cfg['Servers'][$i]['extension'] = 'mysql'; (3),测试,访问登录成功 九,安装memcache服务 1.分别把memcached和libevent下载回来,放到 /tmp 目录下: # cd /tmp # wget # wget 2.先安装libevent: # tar zxvf libevent-1.2.tar.gz # cd libevent-1.2 # ./configure --prefix=/usr # make # make install 3.测试libevent是否安装成功: # ls -al /usr/lib | grep libevent lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent-1.2.so.1 -> libevent-1.2.so.1.0.3 -rwxr-xr-x 1 root root 263546 11?? 12 17:38 libevent-1.2.so.1.0.3 -rw-r--r-- 1 root root 454156 11?? 12 17:38 libevent.a -rwxr-xr-x 1 root root 811 11?? 12 17:38 libevent.la lrwxrwxrwx 1 root root 21 11?? 12 17:38 libevent.so -> libevent-1.2.so.1.0.3 还不错,都安装上了。 4.安装memcached,同时需要安装中指定libevent的安装位置: # cd /tmp # tar zxvf memcached-1.2.0.tar.gz # cd memcached-1.2.0 # ./configure --with-libevent=/usr # make # make install 如果中间出现报错,请仔细检查错误信息,按照错误信息来配置或者增加相应的库或者路径。 安装完成后会把memcached放到 /usr/local/bin/memcached , 5.测试是否成功安装memcached: # ls -al /usr/local/bin/mem* -rwxr-xr-x 1 root root 137986 11?? 12 17:39 /usr/local/bin/memcached -rwxr-xr-x 1 root root 140179 11?? 12 17:39 /usr/local/bin/memcached-debug 6,安装php memcache扩展 先安装php的扩展:yum -y install php-devel 再安装memcache的php扩展:pecl install memcache 7,启动memcached memcached -d -u root -m 64 -c 1024 8,测试,在默认根目录/srv/www/lighttpd/index.php中加入 echo "test memcache..."; $mem = new Memcache; $mem->connect("127.0.0.1", 11211); $mem->set("key", "This is a test!", 0, 60); $val = $mem->get("key"); echo $val; 访问localhost:8080 输出test memcache...This is a test! 十,安装nginx,配置负载匀衡 1, nginx安装略.... 2,nginx配置 vim nginx.conf