lnmp 原始碼搭建
=========================================================
所需原始碼以及元件軟體如下:
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
可以從以下載所需軟體 ^_^
————————————————————————————
1 .安裝 mysql
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.5.3-m3.tar.gz
cd mysql-5.5.3-m3/
./configure –prefix=/usr/local/lnmp/mysql/
–with-client-ldflags=-all-static
–with-mysql-ldflags=-all-static
–enable-assembler
–with-extra-charsets=utf8,gbk,gb2312
–with-charset=utf8
–enable-thread-safe-client
–with-big-tables
–with-readline
–with-ssl
–with-embedded-server
–enable-local-infile
–with-plugins=partition,innobase,myisammrg
–with-unix-socket-path=/tmp/mysql.sock
—
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql
執行bin/mysql_install_db //建立初始化資料庫
chown -R root .
chgrp -R mysql .
chown -R mysql var
啟動mysql : /usr/local/mysql/bin/mysqld_safe &
——————mysql安裝完成——————————————————–
安裝php(FastCGI模式)和相關的支援庫
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure –prefix=/usr/local
make
make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure –enable-ltdl-install
make
make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
——————————支援庫安裝完成 ————————–
安裝php(fastcgi)
首先為php(fastcgi)安裝補丁 php-fpm
tar zxvf php-5.2.14.tar.gz //首先解壓php 再打補丁
—————————————————————————————-
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
—————————————————————————————–
這一步就可以打上補丁了
接下來安裝Php
./configure –prefix=/usr/local/lnmp/php
–with-config-file-path=/usr/local/lnmp/php/etc
–with-mysql=/usr/local/lnmp/mysql
–with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config
–with-iconv-dir=/usr/local
–with-freetype-dir
–with-jpeg-dir
–with-png-dir
–with-zlib
–with-libxml-dir=/usr
–enable-xml
–disable-rpath
–enable-discard-path
–enable-safe-mode
–enable-bcmath
–enable-shmop
–enable-sysvsem
–enable-inline-optimization
–with-curl
–with-curlwrappers
–enable-mbregex
–enable-fastcgi
–enable-fpm
–enable-force-cgi-redirect
–enable-mbstring
–with-mcrypt
–with-gd
–enable-gd-native-ttf
–with-openssl
–with-mhash
–enable-pcntl
–enable-sockets
–with-ldap
–with-ldap-sasl
–with-xmlrpc
–enable-zip
–enable-soap
make ZEND_EXTRA_LIBS=`-liconv`
make install
cp php.ini-dist /usr/local/lnmp/php/etc/php.ini
————————————————————————完成
配置eAccelerator或zend加速PHP:
這裡我用的是zend加速PHP安裝 這用的是Zend-3.3.9
注意安裝zend 要切記版本的問題
tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
mkdir -p /usr/local/zend/
cp -r ZendOptimizer-3.3.9-linux-glibc23-i386/ /usr/local/zend
cp /usr/local/zend/data/5_2_x_comp/ZendOptimizer.so /usr/local/zend/
接下來:在php.ini 檔案最後加入以下二句 ,如下:
zend_optimizer.optimization_level=15
zend_extension=/usr/local/Zend//ZendOptimizer.so
——————————————————————————-啟動php(fastcgi模式)——
安裝nginx
groupadd www
useradd -g www www
注:前提要安裝PCRE ————nginx重寫規則時用到 支援perl指令碼
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../
tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure –user=www
–group=www
–prefix=/usr/local/webserver/nginx
make && make install
cd ../
———————————————————————————————————
到此 安裝基本完成,還要做一些配置如下:
1.首先啟動mysql
2. 對nginx.conf做更改 , 貼下配置檔案:
user www www;
worker_processes 8;
error_log /data1/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name blog.s135.com;
index index.html index.htm index.php;
root /data0/htdocs/blog;
#limit_conn crawler 20;
************************************
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcig_params;
}
***********************************
注:以上是開啟Nginx支援php(fast-cgi)模式,
在該Location裡的include裡包含的檔案裡新增一句
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
ok 現在啟動nginx和php-fpm
*************************************************************************
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
log_format access `$remote_addr – $remote_user [$time_local] “$request” `
`$status $body_bytes_sent “$http_referer” `
`”$http_user_agent” $http_x_forwarded_for`;
access_log /data1/logs/access.log access;
}
server
{
listen 80;
server_name www.s135.com;
index index.html index.htm index.php;
root /data0/htdocs/www;
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
log_format wwwlogs `$remote_addr – $remote_user [$time_local] “$request” `
`$status $body_bytes_sent “$http_referer” `
`”$http_user_agent” $http_x_forwarded_for`;
access_log /data1/logs/wwwlogs.log wwwlogs;
}
server
{
listen 80;
server_name status.blog.s135.com;
location / {
stub_status on;
access_log off;
}
}
}
3.啟動nginx
/usr/local/lnmp/nginx/sbin/nginx
4. 啟動php-fpm
如果啟動失敗,常見的原因是要需要改/usr/local/lnmp/php/etc/php-fpm.conf檔案
把裡面的啟動使用者和組註釋取消掉 即可……
/usr/local/lnmp/php/sbin/php-fpm start
————————–到此基本上就可以執行了 OK !!! ————————————
接下來我們安裝個discuz論壇 看看……
下載DISCUZ 7.2
這個安裝首先要安裝ucenter ,裡面都有教程 ,ok 環境基本上行了。
******************************************************************
最重要的就是優化和負載情況 其實這才是我們真正要乾的事了
就到這裡了^_^