轉(zhuǎn)載自:http://ggt8702.com/?p=146
本篇參考http://hi.baidu.com/%D3%CE%CF%B7%B3%C8%D7%D3/blog/item/a8f35f34f684db5f241f14e8.html,做了些整理和修改。本篇中nginx、mysql、php都會被安裝在/opt/目錄下,它們的配置文件和日志等都在它們的安裝目錄下;mysql的數(shù)據(jù)庫數(shù)據(jù)放在/data/mysql下,網(wǎng)站數(shù)據(jù)放在/data/www下。
系統(tǒng)準(zhǔn)備和依賴程序庫安裝
yum -y install gcc gcc-c++ autoconf 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 openldap openldap-devel nss_ldap openldap-clients openldap-servers
yum -y update
下載安裝包
cd /tmp/
wget http://nginx.org/download/nginx-0.8.54.tar.gz
wget http://www.php.net/get/php-5.3.5.tar.gz/from/this/mirror
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.8.tar.gz/from/http://mysql.he.net/
wget “http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0″
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
wget “http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0″
wget http://pecl.php.net/get/memcache-2.2.6.tgz
wget “http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0″
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.11.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
wget http://ftp.gnu.org/gnu/bison/bison-2.4.3.tar.gz
安裝libiconv、libmcrypt、libltdl、mhash、mcrypt
cd /tmp/
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure –prefix=/usr/local
make
make install
cd /tmp/
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 /tmp/
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
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
cd /tmp/
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
安裝cmake
cd /tmp/
tar zxvf cmake-2.8.3.tar.gz
cd cmake-2.8.3/
./configure –prefix=/usr
gmake
gmake install
cd ../
tar zxvf bison-2.4.3.tar.gz
cd cd bison-2.4.3
./configure
make
make install
準(zhǔn)備用戶、目錄
groupadd mysql
useradd -g mysql mysql
groupadd www
useradd -g www www
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
mkdir -p /data/www
chown -R www:www /data/www
安裝mysql
編譯
cd /tmp/
tar zxvf mysql-5.5.8.tar.gz
cd mysql-5.5.8
cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DSYSCONFDIR=/etc/ -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on
make
make install
ln -s /opt/mysql/lib/lib* /usr/lib/
配置
/opt/mysql/scripts/mysql_install_db –basedir=/opt/mysql/ –datadir=/data/mysql –user=mysql
cd /opt/mysql/support-files
ls一下你會看到有下面的文件: my-huge.cnf 【對應(yīng)1-2G內(nèi)存】、my-large.cnf 【對應(yīng)512M內(nèi)存】、my-medium.cnf 【對應(yīng)128M內(nèi)存】、my-small.cnf 【對應(yīng)64M或更低】,你可以查看這些文件,參照你的電腦配置,選擇一個文件
cp my-xxx.cnf /etc/my.cnf
你可以再編輯my.cnf,自己調(diào)整下參數(shù),也可以保持不變
初始化和啟動
cp /opt/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig –add mysqld
chkconfig mysqld on
/etc/rc.d/init.d/mysqld start
cd /opt/mysql/
bin/mysql_secure_installation
按照提示設(shè)置root密碼等
安裝php
編譯
cd /tmp/
tar zxvf php-5.3.5.tar.gz
cd php-5.3.5
./configure –prefix=/opt/php –with-config-file-path=/opt/php/etc –with-mysql=/opt/mysql –with-mysqli=/opt/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 –disable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fpm –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
mkdir /opt/mysql/include/mysql
ln -s /opt/mysql/include/* /opt/mysql/include/mysql/
make ZEND_EXTRA_LIBS=’-liconv’
make install
cp php.ini-production /opt/php/etc/php.ini
安裝擴(kuò)展
cd /tmp/
tar zxvf memcache-2.2.6.tgz
cd memcache-2.2.6
/opt/php/bin/phpize
./configure –with-php-config=/opt/php/bin/php-config
make
make install
cd /tmp/
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/opt/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-config=/opt/php/bin/php-config
make
make install
vi /opt/php/etc/php.ini
配置eaccelerator,在文件末尾添加
[eaccelerator]
zend_extension=”/opt/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/tmp/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.log_file = “/opt/php/var/log/eaccelerator_log”
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”3600″
eaccelerator.shm_prune_period=”3600″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″
mkdir -p /tmp/eaccelerator
配置memcache,在文件中搜索extension_dir、extension ,在相應(yīng)位置添加下面兩行
extension_dir = “/opt/php/lib/php/extensions/no-debug-non-zts-20090626/”
extension = “memcache.so”
配置php-fpm
cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
vi /opt/php/etc/php-fpm.conf
幾處修改,user/group要設(shè)好,其它選項可以自己調(diào)整
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 5s
[www]
user = www
group = www
安裝nginx
安裝pcre
cd /tmp/
tar zxvf pcre-8.11.tar.gz
cd pcre-8.11/
./configure
make && make install
編譯
cd /tmp/
tar zxvf nginx-0.8.54.tar.gz
cd nginx-0.8.54/
./configure –user=www –group=www –prefix=/opt/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install
配置
編輯/opt/nginx/conf/nginx.conf,這里給個簡單的例子
view source
print?
user www www;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
# ‘$status $body_bytes_sent “$http_referer” ‘
# ‘”$http_user_agent” “$http_x_forwarded_for”‘;
#access_log logs/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 60;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /data/www;
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#location ~ /\.ht {
# deny all;
#}
}
啟動服務(wù)器
/opt/nginx/sbin/nginx
/opt/php/sbin/php-fpm
好了,你可以試著從瀏覽器訪問了。為了測試nginx和php是否協(xié)作正常,可以建一個test.php,內(nèi)容為 ,將它放到到/data/www目錄中,從瀏覽器訪問http://your-server-ip-or-hostname/test.php,如果你能看到一個PHP的信息頁面就可以了。