文章出處

準備工作
安裝make
yum -y install gcc automake autoconf libtool make
安裝g++
yum install gcc gcc-c++
下面正式開始
---------------------------------------------------------------------------
一般我們都需要先裝pcre, zlib,前者為了重寫rewrite,后者為了gzip壓縮。
可以是任何目錄,本文選定的是/data/soft/src
一:Nginx安裝
cd /data/soft/src
1.安裝PCRE庫
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下載最新的 PCRE 源碼包,使用下面命令下載編譯和安裝 PCRE 包:
cd /data/soft/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure
make
make install
2.安裝zlib庫
http://zlib.net/zlib-1.2.8.tar.gz 下載最新的 zlib 源碼包,使用下面命令下載編譯和安裝 zlib包:
cd /data/soft/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
3.安裝ssl(某些vps默認沒裝ssl)
cd /data/soft/src
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
yum -y install openssl openssl-devel
4.安裝nginx
Nginx 一般有兩個版本,分別是穩定版和開發版,您可以根據您的目的來選擇這兩個版本的其中一個,下面是把 Nginx 安裝到 /data/soft/nginx 目錄下的詳細步驟:
cd /data/soft/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/data/soft/nginx/nginx \--conf-path=/data/soft/nginx/nginx.conf \--pid-path=/data/soft/nginx/nginx.pid \--with-http_ssl_module \--with-pcre=/data/src/pcre-8.34 \--with-zlib=/data/src/zlib-1.2.8 \--with-openssl=/data/src/openssl-1.0.1c
make
make install
安裝成功后 /data/soft/nginx 目錄下如下:
fastcgi.conf koi-win nginx.conf.default
fastcgi.conf.default logs scgi_params
fastcgi_params mime.types scgi_params.default
fastcgi_params.default mime.types.default uwsgi_params
html nginx uwsgi_params.default
koi-utf nginx.conf win-utf
5.啟動
確保系統的 80 端口沒被其他程序占用,運行/data/soft/nginx/nginx 命令來啟動 Nginx,
netstat -ano|grep 80
如果查不到結果后執行,有結果則忽略此步驟
sudo /usr/local/nginx/nginx
打開瀏覽器訪問此機器的 IP,如果瀏覽器出現 Welcome to nginx! 則表示 Nginx 已經安裝并運行成功。
到這里nginx就安裝完成了,如果只是處理靜態html就不用繼續安裝了,如果你需要處理php腳本的話,還需要安裝php-fpm。
6.Nginx開機啟動
echo "/data/soft/nginx/sbin/nginx" >> /etc/rc.local
二:編譯安裝php-fpm
PHP-FPM是一個PHP FastCGI管理器,是只用于PHP的,可以在 http://php-fpm.org/download下載得到.
PHP-FPM其實是PHP源代碼的一個補丁,旨在將FastCGI進程管理整合進PHP包中。必須將它patch到你的PHP源代碼中,在編譯安裝PHP后才可以使用。
新版PHP已經集成php-fpm了,不再是第三方的包了,推薦使用。PHP-FPM提供了更好的PHP進程管理方式,可以有效控制內存和進程、可以平滑重載PHP配置,比spawn-fcgi具有更多優點,所以被PHP官方收錄了。在./configure的時候帶 –enable-fpm參數即可開啟PHP-FPM,其它參數都是配置php的,具體選項含義可以到這里查看:http://www.php.net/manual/en/configure.about.php。
安裝前準備
centos下執行(自動安裝gcc)
yum -y install gcc automake autoconf libtool make
yum -y install gcc gcc-c++ glibc
yum -y install libmcrypt-devel mhash-devel 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 krb5-devel libidn libidn-devel openssl openssl-devel
1.php-fpm安裝(推薦安裝方式)
cd /data/soft/src
wget http://museum.php.net/php5/php-5.4.7.tar.gz
tar zvxf php-5.4.7.tar.gz
cd php-5.4.7
./configure --prefix=/data/soft/php --enable-fpm --with-mcrypt \--enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath \--enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \--with-gd --with-jpeg-dir
make all install
2.以上就完成了php-fpm的安裝。
下面是對php-fpm運行用戶進行設置
cd /data/soft/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/php-fpm.conf
修改
user = www
group = www
如果www用戶不存在,那么先添加www用戶
groupadd www
useradd -g www www
3.修改nginx配置文件以支持php-fpm
修改nginx配置文件為,nginx.conf
其中server段增加如下配置:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /data/www; #項目根目錄
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4.創建測試php文件
創建php文件
在/data/www下創建index.php文件,輸入如下內容:
<?php
echo phpinfo();
?>
5.啟動php-fpm服務
/data/soft/php/sbin/php-fpm
重啟nginx服務器:
/data/nginx/nginx -s reload
6.php-fpm關閉與重啟
php-fpm 關閉:
kill -INT `cat /data/soft/php/var/run/php-fpm.pid`
php-fpm 重啟:
kill -USR2 `cat /data/soft/php/var/run/php-fpm.pid`
7.php-fpm開機啟動
echo "/data/soft/php/sbin/php-fpm" >> /etc/rc.local
三:mysql安裝
cd /data/soft/src
wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.70.tar.gz
tar -zxvf mysql-5.1.70.tar.gz
cd mysql-5.1.70
yum install ncurses ncurses-devel
./configure '--prefix=/data/soft/mysql' '--without-debug' '--with-charset=utf8' '--with-extra-charsets=all' '--enable-assembler' '--with-pthread' '--enable-thread-safe-client' '--with-mysqld-ldflags=-all-static' '--with-client-ldflags=-all-static' '--with-big-tables' '--with-readline' '--with-ssl' '--with-embedded-server' '--enable-local-infile' '--with-plugins=innobase' make
make install
到此mysql就安裝到了/data/soft/mysql路徑下,下面開始mysql的配置工作
------------------------------------
安裝mysql選項文件
cp support-files/my-medium.cnf /etc/my.cnf
mysql設置開機自啟動
cp -r support-files/mysql.server /etc/init.d/mysqld
/sbin/chkconfig --del mysqld
/sbin/chkconfig --add mysqld
配置權限表
chown -R mysql:mysql /data/soft/mysql
/data/soft/mysql/bin/mysql_install_db --user=mysql
啟動mysql
/etc/init.d/mysqld start
mysql初始化配置:
export PATH=/data/soft/mysql/bin:$PATH
/data/soft/mysql/bin/mysql_secure_installation
注:這里根據提示設置mysql的root密碼
到這里mysql安裝完成了, 我們開始使用客戶端連接mysql
如果報錯:
SQL Error (1130): Host '192.168.1.100' is not allowed to connect to this MySQL server
首先按下面的步驟登錄Mysql服務器
登錄mysql需要切換到dos下的mysql的bin目錄,進行如下操作:
#mysql -uroot -ppassword
mysql>use mysql;
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host','user' from user where user='root';
mysql>quit
OK。遠程連接成功!


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜

    大師兄 發表在 痞客邦 留言(0) 人氣()