準備工作,安裝依賴庫
//檢查并安裝組件
yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake
查看linux版本:
幾點說明:
pcre、openssl、zlib是安裝nginx時需要的
cmake是安裝MySQL時需要的 二、編譯安裝nginx 1、下載nginx(stable版本) P指定下載文件目錄
wget -P /tmp http://nginx.org/download/nginx-1.8.1.tar.gz
或者默認下載到當前目錄下
[root@centos /]# cd /usr/local/src
[root@centos src]# wget http:///download/nginx-1.8.1.tar.gz
2、解壓nginx
[root@centos src]# tar xf nginx-1.8.1.tar.gz
[root@centos src]# cd nginx-1.8.1
[root@centos nginx-1.8.1]# ./configure --help(查看參數(shù))
3、編譯nginx
./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module
make && make install
//啟動nginx
**第一種方式 指定--sbin-path=/usr/sbin/nginx**
nginx //啟動
nginx -s stop// 停止
nginx -s reload // 重新加載
**第二種方式 不指定--sbin-path**
cd /usr/local/nginx
./sbin/nginx
重啟nginx /usr/local/nginx/sbin/nginx -s reload
**第三種方式**
配置開機啟動
首先寫一個shell腳本,腳本名稱:nginx
vi /etc/rc.d/init.d/nginx
#! /bin/bash
# chkconfig: 35 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME (這里是nginx安裝是 --sbin-path指定的路徑)
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
d_start(){
$DAEMON || echo -n " already running"
}
d_stop() {
$DAEMON -s quit || echo -n " not running"
}
d_reload() {
$DAEMON -s reload || echo -n " counld not reload"
}
case "$1" in
start)
echo -n "Starting $DESC:$NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC:$NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
//將shell腳本放入到 /etc/rc.d/init.d/中,并執(zhí)行下列命令
chmod +x /etc/rc.d/init.d/nginx (設(shè)置可執(zhí)行權(quán)限)
chkconfig --add nginx (添加系統(tǒng)服務(wù))
service nginx start
service nginx stop
service nginx restart
service nginx reload
瀏覽器訪問:http://localhost如能出現(xiàn)nginx頁面則表示成功
// 查看nginx進程
ps -ef | grep nginx
// 查看進程個數(shù) 去掉首位的
ps -ef | grep nginx | wc -l
// 查看80端口
netstat -anpt
4、安裝PHP
//php下載
cd /usr/local/src/
//如果下載文件的文件是mirror,直接解壓mirror即可
wget http://cn2.php.net/get/php-5.6.13.tar.gz/from/this/mirror
tar zxvf php-5.6.13.tar.gz
cd php-5.6.13
首先查看安裝幫助 # ./configure --help # ./configure --prefix=/usr/local/php \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip
如果配置錯誤,需要安裝需要的模塊,直接yum一并安裝依賴庫 # yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel 注意:安裝php7beta3的時候有幾處配置不過去,需要yum一下,現(xiàn)在php-7.0.2已經(jīng)不用這樣了。 # yum -y install curl-devel # yum -y install libxslt-devel
編譯安裝 # make && make install 配置文件 # cp php.ini-development /usr/local/php/lib/php.ini # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf # cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
需要注意的是php7中www.conf這個配置文件配置phpfpm的端口號等信息,如果你修改默認的9000端口號需在這里改,再改nginx的配置 啟動 # /etc/init.d/php-fpm
查看phpinfo()
php7和php5性能分析比較 - <?php
- //time /usr/local/php5/bin/php search_by_key.php
- $a = array();
- for($i=0;$i<600000;$i++){
- $a[$i] = $i;
- }
-
- foreach($a as $i)
- {
- array_key_exists($i, $a);
- }
- ?>
生成一個 60 萬元素的數(shù)組,通過查找key 的方式,來確定key是否存在。PHP 5.4.44 版 [root@localhost www5.4.44]# time /usr/local/php5.4.44/bin/php search_by_key.php
real 0m0.351s user 0m0.300s sys 0m0.050s PHP 5.5.28 版 [root@localhost www]# time /usr/local/php/bin/php search_by_key.php real 0m0.361s user 0m0.304s sys 0m0.057s
PHP 7.0.0 版 [root@localhost www7]# time /usr/local/php7/bin/php search_by_key.php real 0m0.114s user 0m0.097s sys 0m0.017s
很明顯php7的性能是php5的3倍!
|