以CentOS5.6爲平臺編譯安裝。確保系統已經安裝gcc/gcc-c++編譯器!php
1.Nginx-1.0.14
2.PHP-5.3.10
3.MySql-5.1.61css
安裝相關依賴開發庫:
autoconf curl freetype gd jpegsrc libiconv libmcrypt libpng libxml2
mhash ncurses openssl opensll-devel pcre pcre-devel zlib zlib-develhtml
1.Nginx 編譯安裝
# groupadd www 建立www用戶組
# useradd -g www -s /sbin/nologin -M www 建立www用戶並將其添加到www用戶組
# mkdir /www 建立/www網站目錄
# chmod +w /www 給/www目錄寫權限
# chown -R www:www /www 將網站根目錄/www全部者和所屬組設置爲www用戶和組mysql
[./configure 編譯參數]
--prefix=/usr/local/nginx Nginx安裝路徑
--user=www nginx啓動運行所使用的用戶,該用戶必須已經存在。
--group=www nginx啓動運行所使用的用戶組,該用戶組必須已經存在。
--with-http_realip_module
--with-http_addition_module
--with-http_gzip_static_module 開啓gzip壓縮功能,對頁面進行壓縮。
--with-http_random_index_module
--with-http_stub_status_module
--with-http_sub_module
--with-http_dav_modulenginx
配置 Nginx.conf 配置文件修改或添加下列內容: c++
user www www; //nginx默認以用戶www和用戶組www身份啓動 worker_processes 8; //默認啓動時開啓的進程數 gzip on; //開啓gzip的壓縮功能 gzip_min_length 1100; gzip_buffers 4 8k; gzip_types text/plain; server { listen 80; //默認nginx服務器使用的端口爲80端口 server_name localhost; //服務器名稱,例如www.baidu.com location / { root /www; //web服務器網站跟目錄 index index.php index.html index.htm; //網站默認主頁 } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /www; //默認全部php腳本文件所在目錄 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } //開啓對靜態圖片和flash本地瀏覽器緩存1天。 location ~* ^.+\.(gif|jpg|jpeg|png|bmp|swf)$ { root /www; access_log off; expires 1d; } //開啓對CSS樣式表的本地緩存1小時。 location ~* ^.+\.(js|css)?$ { root /www; access_log off; expires 1h; }
建立nginx啓動腳本。添加爲系統服務,並設置爲開機自動啓動。腳本內容以下:web
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # this script create it by jackbillow at 2007.10.15. # it is v.0.0.2 version. # if you find any errors on this scripts,please contact jackbillow. # and send mail to jackbillow at gmail dot com. # # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /usr/local/nginx/logs/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
將以上腳本保存爲nginx文件並複製到 /etc/init.d 目錄下。執行下列命令:
# chmod 755 /etc/init.d/nginx 設置nginx啓動腳本可執行權限
# chkconfig --add nginx 添加nginx爲系統服務
# chkconfig nginx on 開啓nginx服務隨系統自動啓動
# chown -R www:www /usr/local/nginx 設置nginx安裝目錄權限全部者和所屬組爲wwwsql
[手動啓動 Nginx 命令]
# service nginx startshell
2.MySql 編譯安裝數據庫
# groupadd mysql 建立mysql用戶組
# useradd -g mysql -s /sbin/nologin -M mysql 建立mysql用戶並將其添加到mysql用戶組
[./configure 編譯參數]
--prefix=/usr/local/mysql mysql安裝路徑。
--localstatedir=/var/data DATA數據庫位置。
--with-mysqld-user=mysql 以mysql用戶身份運行mysql數據庫。
--enable-assembler 使用一些字符函數的彙編模式(優化性能)
--with-big-tables 啓用對大於4G的數據庫的支持。
--with-charset=utf8 數據庫編碼字符集。多種編碼字符集之間用逗號隔開。
--enable-static 靜態編譯,以靜態方式編譯客戶端和服務端,能提升13%性能。
--with-client-ldflags=-all-static
--with-mysqld-ldflags=-all-static
--with-ssl 開啓對SSL安全傳輸協議的支持。、
--with-embedded-server 構建嵌入式服務器
--enable-local-infile
# chown -R mysql:mysql /usr/local/mysql 設置MySql相關目錄的權限
# cp /usr/local/mysql/share/mysql/my-medium.cnf /usr/local/mysql/my.cnf 複製建立MySql的配置文件
# /usr/local/mysql/bin/mysql_install_db --user=mysql 以mysql用戶身份創建初始化數據庫
# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql 建立 Mysql 開機啓動腳本,並設置可執行權限
# chmod 755 /etc/init.d/mysql
# chkconfig --add mysql 添加 MySql 爲系統服務,並設置爲開機自動啓動
# chkconfig mysql on
# service mysql start 啓動 Mysql
# /usr/local/mysql/bin/mysqladmin -u root password 123456 設置 MySql 的root密碼爲123456
3.PHP 編譯安裝
[./configure配置參數]
--prefix=/usr/local/php PHP安裝路徑
--with-config-file-path=/etc PHP配置文件路徑
--with-mysql=/usr/local/mysql MySql安裝路徑
--with-mysqli=/usr/local/mysql/bin/mysql_config 開啓對mysqli的支持
--enable-fpm
--with-fpm-user=www 以www用戶身份運行PHP
--with-fpm-group=www 以www用戶組身份運行PHP
--with-iconv-dir
--with-freetype-dir
--with-jpeg-dir
--with-png-dir
--with-zlib
--with-gd
--enable-gd-native-ttf
--with-libxml-dir
--with-curl
--enable-safe-mode
--with-xmlrpc
--with-openssl
--with-mhash
--with-mcrypt
--enable-bcmath
--enable-shmop
--enable-sysvsem
--with-curlwrappers
--enable-mbstring
--enable-sockets
--enable-magic-quotes
--with-pear
--enable-sysvshm
--enable-zip
[編譯並安裝PHP]
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# cp php.ini-production /etc/php.ini 複製並修改php.ini配置文件
[修改php.ini配置文件內容:]
register_globals=Off 改成 register_globals=On //使傳遞全局變量有效 date.timezone = Asia/Shanghai //設置當前服務器的時區 zend_optimizer.optimization_level=15 //加載Zend加速器 zend_extension="/usr/local/Zend/ZendGuardLoader.so" //Zend加速器安裝目錄
[建立並修改php-fpm的配置文件]
修改內容:
pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = error emergency_restart_interval = 3d user = www group = www listen = 127.0.0.1:9000
[建立並添加php-fpm開機啓動服務腳本]
# vi /etc/init.d/php-fpm
#!/bin/sh #chkconfig: - 85 15 #description: php-fpm is PHP FastCGI Process Manage. #processname:php-fpm ### BEGIN INIT INFO # Provides: php-fpm # Required-Start: $remote_fs $network # Required-Stop: $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts php-fpm # Description: starts the PHP FastCGI Process Manager daemon ### END INIT INFO prefix=/usr/local/php exec_prefix=${prefix} php_fpm_BIN=${exec_prefix}/sbin/php-fpm php_fpm_CONF=${prefix}/etc/php-fpm.conf php_fpm_PID=${prefix}/var/run/php-fpm.pid php_opts="--fpm-config $php_fpm_CONF" wait_for_pid () { try=0 while test $try -lt 35 ; do case "$1" in 'created') if [ -f "$2" ] ; then try='' break fi ;; 'removed') if [ ! -f "$2" ] ; then try='' break fi ;; esac echo -n . try=`expr $try + 1` sleep 1 done } case "$1" in start) echo -n "Starting php-fpm " $php_fpm_BIN $php_opts if [ "$?" != 0 ] ; then echo " failed" exit 1 fi wait_for_pid created $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Gracefully shutting down php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -QUIT `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; force-quit) echo -n "Terminating php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -TERM `cat $php_fpm_PID` wait_for_pid removed $php_fpm_PID if [ -n "$try" ] ; then echo " failed" exit 1 else echo " done" fi ;; restart) $0 stop $0 start ;; reload) echo -n "Reload service php-fpm " if [ ! -r $php_fpm_PID ] ; then echo "warning, no pid file found - php-fpm is not running ?" exit 1 fi kill -USR2 `cat $php_fpm_PID` echo " done" ;; *) echo "Usage: $0 {start|stop|force-quit|restart|reload}" exit 1 ;; esac
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add php-fpm 添加 PHP 爲系統服務,並設置爲開機自動啓動
# chkconfig php-fpm on
# chown -R www:www /usr/local/php 給PHP相關文件目錄設置權限
[手動啓動 PHP 命令]
# service php-fpm start
!若是某個服務沒法啓動關閉系統防火牆。