[原创]LEMP安装备忘录
超级快的鸟龟
|
1#
超级快的鸟龟 发表于 2008-03-12 23:30
[原创]LEMP安装备忘录LEMP安装备忘录 前言 这阵子上网溜达,看见很多高手都说nginx(阴精X,嘿嘿)很好、很强大,于是乎,我没能顶得住诱惑,便装了个玩玩,为了方便再次安装,便小记了下。本文安装的方法仅提供给“玩票”的兄弟姐妹们参考,工业环境请慎重!我这人计算机水平也不高,文中如有不正之处,请指正cmyf DOT name AT gmail DOT com. 零,准备工作 不知谁说过不打无准备之战来着,咱也要先把需要的东西都准备好。LEMP不外乎就是:Linux、nginx[Engine x]、MySQL、PHP。我使用的版本信息如下:
[Copy to clipboard] [ - ]
CODE:
Linux: Debian etch 2.6.18-5/gcc version 4.1.2/GNU Make 3.81/
Engine X: nginx-0.5.35 MySQL: mysql-5.0.45 PHP: php-5.2.5 由于是源码安装,所以在安装的过程中难免会遇到缺少xxx文件啊、xxx库之类的信息,所以我在安装的时候还用到了以下软件:
[Copy to clipboard] [ - ]
CODE:
freetype-2.3.5 libxml2-2.6.30 gd-2.0.35 lighttpd-1.4.19 jpegsrc.v6b mcrypt-2.6.6 pcre-7.2
libiconv-1.11 memcache-2.2.1 libmcrypt-2.5.8 mhash-0.9.9 libpng-1.2.20 libxml2-2.6.30 ncurses-5.6 当然了,由于我的debian linux系统是全新安装的基本系统,所以缺的包还比较多,你得根据实际情况添加,大部分的都能apt-get到,实在get不到,就上网搜一个,装上就欧了。将所有需要的软件我都全部放到了/home/alpha/lemp目录中,方便点! 好了,弹夹已经压好了,喝口茶,上膛,瞄准! 一、安装MySQL。
[Copy to clipboard] [ - ]
CODE:
#cd /home/alpha/lemp
#tar zxvf mysql-5.0.45.tar.gz #/sbin/groupadd mysql #/sbin/useradd msyql #cd mysql-5.0.45 # ./configure --prefix=/opt/webser/mysql/ --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=utf8,gb2312,gbk --with-pthread –enable-thread-safe-client 详细的configure信息可以参考: http://dev.mysql.com/doc/refman/5.0/en/configure-options.html
[Copy to clipboard] [ - ]
CODE:
#make && make install
安装mysql是个漫长的过程,需要点点时间,我测试用的机器还凑合着。再有,我所有的软件都是安装在/opt/webser/目录下,你可以根据实际情况选择。
[Copy to clipboard] [ - ]
CODE:
#chmod +w /opt/webser/mysql
#chown -R mysql:mysql /opt/webser/mysql #cp support-files/my-medium.cnf /opt/webser/mysql/my.cnf #cd ../ #/opt/webser/mysql/bin/mysql_install_db --defaults-file=/opt/webser/mysql/my.cnf --basedir=/opt/webser/mysql/ --datadir=/opt/webser/mysql/data --user=mysql --pid-file=/opt/webser/mysql.pid --skip-locking --port=3306 –socket=/tmp/mysql.sock 关于mysql_install_db的参数,可以参考下面这篇文章: http://dev.mysql.com/doc/refman/5.0/en/mysql-install-db.html
[Copy to clipboard] [ - ]
CODE:
#/bin/sh /opt/webser/mysql/bin/mysqld_safe --defaults-file=/opt/webser/mysql/my.cnf &
如果能顺利启动,那就ok了,剩下的关于mysql更多的配置,就参考mysql的手册吧。 二、PHP安装(FastCGI)
[Copy to clipboard] [ - ]
CODE:
#tar zxvf php-5.2.5.tar.gz
#cd php-5.2.5/ #./configure --prefix=/opt/webser/php --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --with-config-file-path=/opt/webser/php/conf --enable-zend-multibyte --with-mysql=/opt/webser/mysql/ --with-libxml-dir=/usr/local/bin/xml2-config --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-sysvsem --enable-inline-optimization --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif –disable-debug 我在configure的时候由于缺少很多文件,所以遇到很多郁闷问题,在config的时候一定不要忘了—enable-fastcgi,更多的configure参数,请参考: http://php.net/manual/zh/configure.php
[Copy to clipboard] [ - ]
CODE:
#make && make install
#cd ../ 接下来为了让php更爽,还要添加点有意思的插件: memcache这玩意儿还是有点用途的,呵呵,反正测试用装上玩呗!
[Copy to clipboard] [ - ]
CODE:
#tar zxvf memcache-2.2.1.tgz
#cd memcache-2.2.1 #/opt/webser/php/bin/phpize #./configure –with-php-config=/opt/webser/php/bin/php-config #make && make install #cd ../ gd呢是肯定用的上的!
[Copy to clipboard] [ - ]
CODE:
#cd php-5.2.5/ext/gd/
#/usr/local/webserver/php/bin/phpize #./configure --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir –with-php-config=/usr/local/webserver/php/bin/php-config #make #cd ../../../ 接下来需要稍微修改以下php.ini文件: 查找并替换extension_dir为:
[Copy to clipboard] [ - ]
CODE:
extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
具体的目录得根据你实际情况而定,然后增加以下内容:
[Copy to clipboard] [ - ]
CODE:
extension = "memcache.so"
extension = "gd.so" 三,安装fastcgi 看了下网上兄弟们的文章,lighttpd里面的spawn-fcgi可用,那就编译一下 lighttpd-1.4.19,不用安装,然后按照以下方法设置:
[Copy to clipboard] [ - ]
CODE:
#cp spawn-fcgi /opt/webser/php/bin/
#chmod +x /opt/webser/php/bin/spawn-fcgi 运行fastcgi:
[Copy to clipboard] [ - ]
CODE:
#/opt/webser/php/bin/spawn-fcgi -a 127.0.0.1 -p 8080 -C 64 -u www -f /opt/webser/php/bin/php-cgi
关于spawn-fcgi的运行参数,可以查看: http://linux.die.net/man/1/spawn-fcgi 四、安装nginx
[Copy to clipboard] [ - ]
CODE:
#/usr/sbin/groupadd www -g 68
#/usr/sbin/useradd -u 68 -g www www #mkdir -p /home/data/www #chmod +w /home/data/www #chown -R www:www /home/data/www 在测试过程中,服务目录是/home/data/www,挺别致的吧,呵呵,
[Copy to clipboard] [ - ]
CODE:
#tar zxvf pcre-7.2.tar.gz
#tar zxvf nginx-0.5.35.tar.gz #cd nginx-0.5.35 #./configure --user=www --group=www --prefix=/opt/webser/nginx --with-pcre=/home/alpha/nginx-php/pcre-7.2 --with-http_stub_status_module #make && make install 更多的关于nginx的configure参数可以查看: http://wiki.codemongers.com/NginxChsInstall 五,nginx配置 创建了个保存日志的目录,方便点,呵呵:
[Copy to clipboard] [ - ]
CODE:
#mkdir -p /home/data/logs
#chmod +w /home/data/logs #chown -R www:www /home/data/logs 接着咱就来配置配置:
[Copy to clipboard] [ - ]
CODE:
#cp /opt/webser/nginx/conf/nginx.conf /opt/webser/nginx/conf/nginx.conf.BACKUP
我的配置文件如下,
[Copy to clipboard] [ - ]
CODE:
#vi /opt/webser/nginx/conf/nginx.conf
QUOTE:
user www www;
worker_processes 5; error_log /home/data/logs/error.log; events { worker_connections 2048; } http { include conf/mime.types; include conf/fcgi.conf; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /home/data/logs/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name example.com; root /home/data/www; location / { index index.html index.htm index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:8080; } } } 接下来需要在/opt/webser/nginx/conf/中创建一个fcgi.conf文件,
[Copy to clipboard] [ - ]
CODE:
#vi /opt/webser/nginx/conf/fcgi.conf
内容如下:
QUOTE:
#fastcgi.conf
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; 我这就是简单配置,更多的关于nginx的配置信息请参考: http://wiki.codemongers.com/NginxConfiguration 六、启动并测试nginx.
[Copy to clipboard] [ - ]
CODE:
#/opt/webser/nginx/sbin/nginx -c /opt/webser/nginx/conf/nginx.conf
写个phpinfo()文件测试下,能正常显示,那就ok了。 七、参考资料 我已经在文章中注明了参考过的资料了,嘿嘿! 八、后记 LEMP到此就安装完成了,nginx是很强大的,要想让它更稳定、高效的为您服务,还是多看看它的官方文档吧。欢迎指正:cmyf DOT name AT gmail DOT com |