[Ubuntu8.04 server]下建構nginx+php+mysql+zend ubuntu8.04 server的下載下傳位址可以去 www.ubuntu.org.cn去找。安裝采用預設安裝,不選擇任何的服務。
一、設定root權限。
設定root權限,這樣下面安裝的過程中,不用總sudo了。 複制内容到剪貼闆代碼:sudo passwd root 設定好root的密碼以後。 複制内容到剪貼闆代碼:su - 輸入密碼,換成root權限。
二、設定apt源。
ubuntu安裝完畢以後,預設的apt源速度可能會很慢。是以,首先是修改一下apt的源,提高軟體的下載下傳速度。建議大家可以選擇ubuntu官方的源,中國台灣省的源和cn99的源。 複制内容到剪貼闆代碼:
cp /etc/apt/sources.list /etc/apt/sources.list.bak
nano /etc/apt/sources.list 删除裡面所有的内容,修改成(白天速度快,晚上速度比較慢。電信和網通都可以) 複制内容到剪貼闆代碼:deb http://archive.ubuntu.com/ubuntu/ hardy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-updates main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ hardy-backports main restricted universe multiverse (下面的源,推薦電信使用者使用。有的時候網通的使用者通路速度也非常的快) 複制内容到剪貼闆代碼:deb http://ubuntu.cn99.com/ubuntu/ hardy main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-updates main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu/ hardy-backports main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-security main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-updates main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb-src http://ubuntu.cn99.com/ubuntu/ hardy-backports main restricted universe multiverse (中國台灣省的源,晚上的速度非常的好) 複制内容到剪貼闆代碼:deb http://tw.archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse
deb http://tw.archive.ubuntu.com/ubuntu hardy-proposed main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse
deb-src http://tw.archive.ubuntu.com/ubuntu hardy-proposed main restricted universe multiverse 上面的三個源,大家可以根據自己的需要來設定。
儲存,退出nano。 複制内容到剪貼闆代碼:apt-get update 三、安裝一些必要的軟體。
ubuntu安裝以後,有一些包是沒有安裝上的。我們需要安裝上,否則下面的編譯将會出現問題。 複制内容到剪貼闆代碼:apt-get install binutils cpp fetchmail flex gcc libarchive-zip-perl libc6-dev libcompress-zlib-perl libdb4.3-dev libpcre3 libpopt-dev lynx m4 make ncftp nmap perl perl-modules unzip zip zlib1g-dev autoconf automake1.9 libtool bison autotools-dev g++ build-essential libpcre3-dev libncurses5-dev libcurl4-openssl-dev openssh-server openssh-client 四、設定安裝目錄,下載下傳必要的軟體。
安裝完畢以後,我們建立幾個目錄,用來進行下一步的安裝。 複制内容到剪貼闆代碼:mkdir /var/software (用來存放安裝軟體)
mkdir /usr/local/webserver (安裝目錄,nginx,php等都安裝在這個目錄下)
mkdir /usr/local/webserver/webdata (釋出目錄)
mkdir /usr/local/webserver/log (存放nginx的日志檔案) 下載下傳編譯需要的各種軟體,全部放到/var/software下
mysql-5.0.51a
http://dev.mysql.com/get/Downloads/M...rloo.ca/mysql/
php-5.2.6
http://cn.php.net/distributions/php-5.2.6.tar.bz2
nginx-0.5.35
http://sysoev.ru/nginx/nginx-0.5.35.tar.gz
libiconv-1.11
http://download.chyangwa.com/linux/l...nv-1.11.tar.gz
freetype-2.3.5
http://download.savannah.gnu.org/rel...e-2.3.5.tar.gz
libpng-1.2.29(注意,大家不要使用1.2.28這個版本,似乎有很多問題)
http://jaist.dl.sourceforge.net/sour...-1.2.29.tar.gz
jpegsrc.v6b
http://down1.chinaunix.net/distfiles/jpegsrc.v6b.tar.gz
libxml2-2.6.30
http://ftp.gnome.org/pub/GNOME/sourc...-2.6.30.tar.gz
libmcrypt-2.5.8
http://nchc.dl.sourceforge.net/sourc...t-2.5.8.tar.gz
mhash-0.9.9
http://jaist.dl.sourceforge.net/sour...h-0.9.9.tar.gz
mcrypt-2.6.7
http://jaist.dl.sourceforge.net/sour...t-2.6.7.tar.gz
memcache-2.2.3
http://pecl.php.net/get/memcache-2.2.3.tgz
pcre-7.6
http://nchc.dl.sourceforge.net/sourc...cre-7.6.tar.gz
zend
http://www.phpchina.com/download/sho...=ZendOptimizer
為了友善大家,已将上面所有的軟體包下載下傳後打包,提供本地下載下傳,這樣就不用擔心死鍊了
http://www.ubuntuchina.com/Download/2659/soft/nginxall.zip
五、編譯安裝PHP所需的支援庫。 複制内容到剪貼闆代碼:cd /var/software
tar zxvf libiconv-1.11.tar.gz
cd libiconv-1.11/
./configure --prefix=/usr/local
make
make install
cd ../
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5/
./configure
make
make install
cd ../
tar zxvf libpng-1.2.29.tar.gz
cd libpng-1.2.29/
./configure
###mv scripts/makefile.linux ./makefile
make
make install
cd ../
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-static --enable-shared
make
make install
make install-lib
cd ../
tar zxvf libxml2-2.6.30.tar.gz
cd libxml2-2.6.30/
./configure
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.tar.gz
cd mhash-0.9.9/
./configure
make
make install
cd ../
cp /usr/local/lib/libmcrypt.* /usr/lib
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
tar zxvf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7/
./configure
make
make install
cd ../ 六、編譯安裝MySQL 複制内容到剪貼闆代碼:tar zxvf mysql-5.0.51b.tar.gz
cd mysql-5.0.51b
./configure --prefix=/usr/local/webserver/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-big-tables --with-extra-charsets=gbk,latin1,utf8 --with-pthread --enable-static --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-innodb --without-ndb-debug --without-isam --enable-local-infile --with-readline --with-raid --enable-thread-safe-client
make
make install
groupadd mysql
useradd -g mysql mysql
cd /usr/local/webserver/mysql
bin/mysql_install_db --user=mysql
chown -R root:mysql . (設定權限,注意後面有一個 ".")
chown -R mysql /var/lib/mysql (設定 mysql 目錄權限。資料庫就放在這裡了)
chgrp -R mysql . (注意後面有一個 ".")
cp share/mysql/my-medium.cnf /etc/my.cnf
cp share/mysql/mysql.server /etc/init.d/mysqld (為了開機可以自動啟動 mysql。)
chmod 755 /etc/init.d/mysqld
echo "/usr/local/webserver/mysql/lib" >> /etc/ld.so.conf (添加LIB PATH)
運作以下指令即可啟動 MySQL 伺服器:
/etc/init.d/mysqld start (啟動 MySQL)
bin/mysqladmin -u root password "password_for_root"(設定mysql的root密碼)
/etc/init.d/mysqld stop (關閉 MySQL)
nano /etc/rc.local
在最後加入:/etc/init.d/mysqld start(這樣開機的時候,mysql就可以自動啟動了。) 七、編譯安裝PHP(FastCGI模式) 複制内容到剪貼闆代碼:
cd /var/software
tar zxvf php-5.2.6.tar.gz
cd php-5.2.6
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-debug --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --disable-ipv6 --enable-soap --with-openssl --with-gettext --disable-rpath
sed -i 's#-lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt#& -liconv#' Makefile
make
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../ 八、編譯安裝PHP5擴充子產品 複制内容到剪貼闆代碼:tar zxvf memcache-2.2.3.tgz
cd memcache-2.2.3/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
cd php-5.2.6/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
make install
cd ../../../ 九、對php進行一些設定,并且為安裝nginx做一些準備工作。
1、修改php.ini檔案
手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = "./"
修改為extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行後增加以下幾行,然後儲存。 複制内容到剪貼闆代碼:extension = "memcache.so"
extension = "gd.so" 自動修改:若嫌手工修改麻煩,可執行以下shell指令,自動完成對php.ini檔案的修改: 複制内容到剪貼闆代碼:
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/"/nextension = "memcache.so"/nextension = "gd.so"/n#' /usr/local/webserver/php/etc/php.ini 2、建立www使用者群組,以及其使用的目錄。 複制内容到剪貼闆代碼:/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
chmod +w /usr/local/webserver/webdata/
chown -R www:www /usr/local/webserver/webdata/ 3、安裝lighttpd中附帶的spawn-fcgi,用來啟動php-cgi 複制内容到剪貼闆代碼:cp spawn-fcgi /usr/local/webserver/php/bin
chmod +x /usr/local/webserver/php/bin/spawn-fcgi 4、啟動php-cgi程序,監聽127.0.0.1的10080端口,程序數為64(可以根據自己的情況來設定。如果伺服器記憶體小于3GB,可以隻開啟25個程序。),使用者為www。 複制内容到剪貼闆代碼:
/usr/local/webserver/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/webserver/php/bin/php-cgi 十、安裝Nginx 0.5.33
1、安裝Nginx所需的pcre庫。 複制内容到剪貼闆代碼:tar zxvf pcre-7.6.tar.gz
cd pcre-7.6/
./configure
make && make install
cd ../ 2、安裝Nginx。 複制内容到剪貼闆代碼:
tar zxvf nginx-0.5.35.tar.gz
cd nginx-0.5.35/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module
make
make install
cd ../ 3、建立Nginx日志目錄。 複制内容到剪貼闆代碼:
chmod +w /usr/local/webserver/logs
chown -R www:www /usr/local/webserver/logs 4、建立Nginx配置檔案。
在/usr/local/webserver/nginx/conf/目錄中建立nginx.conf檔案。 複制内容到剪貼闆代碼:rm -f /usr/local/webserver/nginx/conf/nginx.conf
nano /usr/local/webserver/nginx/conf/nginx.conf 輸入以下内容。 複制内容到剪貼闆代碼:user www www;
worker_processes 10;
error_log /usr/local/webserver/logs/nginx_error.log crit;
#pid logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include conf/mime.types;
default_type application/octet-stream;
charset gb2312;
server_names_hash_bucket_size 128;
#sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/html application/xml;
server
{
listen 80;
server_name servername.com;
index index.html index.htm index.php;
root /usr/local/webserver/webdata;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location ~ .*.php?$
{
include conf/fcgi.conf;
fastcgi_pass 127.0.0.1:10080;
fastcgi_index index.php;
}
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 /usr/local/webserver/logs/access.log access;
}
server
{
listen 80;
server_name status.servername.com;
location / {
stub_status on;
access_log off;
}
}
} 儲存,退出nano。
5、在/usr/local/webserver/nginx/conf/目錄中建立fcgi.conf檔案。 複制内容到剪貼闆代碼:nano /usr/local/webserver/nginx/conf/fcgi.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; 6、啟動Nginx 複制内容到剪貼闆代碼:
ulimit -SHn 51200
/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf 7、配置開機自動啟動Nginx + PHP 複制内容到剪貼闆代碼:
nano /etc/rc.local 在末尾增加以下内容: 複制内容到剪貼闆代碼:ulimit -SHn 51200
/usr/local/webserver/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/webserver/php/bin/php-cgi
/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf 十一、優化Linux核心參數 複制内容到剪貼闆代碼:nano /etc/sysctl.conf 在末尾增加以下内容. 複制内容到剪貼闆代碼:net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000 使配置立即生效: 複制内容到剪貼闆代碼:/sbin/sysctl -p 十二、在不停止Nginx服務的情況下平滑變更Nginx配置
修改/usr/local/webserver/nginx/conf/nginx.conf配置檔案後,請執行以下指令檢查配置檔案是否正确. 複制内容到剪貼闆代碼:/usr/local/webserver/nginx/sbin/nginx -t 如果螢幕顯示以下兩行資訊,說明配置檔案正确。 複制内容到剪貼闆代碼:the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully 這時,輸入以下指令檢視Nginx主程序号。 複制内容到剪貼闆代碼:ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}' 螢幕顯示的即為Nginx主程序号,例如:
4343
這時,執行以下指令即可使修改過的Nginx配置檔案生效. 複制内容到剪貼闆代碼:kill -HUP 4343 十三、安裝zend 複制内容到剪貼闆代碼:cd /var/software
tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-i386
./install 在詢問php.ini的路徑的時候,填入. 複制内容到剪貼闆代碼:/usr/local/webserver/php/etc web伺服器選擇不是apache
十四、reboot你的機器。