安装配置Nginx 0.6.32 +php 5.2.6(fastcgi) + Mysql 5.0.51
安装过程参考: http://blog.s135.com/read.php/314.htm
安装 mysql 5.0.51
- 首先下载必须资源
-
wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz/from/ftp://ftp.iij.ad.jp/pub/db/mysql/
- 添加mysql 用户组和账号
-
/usr/sbin/groupadd mysql
-
/usr/sbin/useradd -d /var/lib/mysql -s /sbin/nologin -g mysql mysql
- 用源码包编译安装
-
tar zxvf mysql-5.0.51b.tar.gz
-
cd mysql-5.0.51b/
-
./configure –prefix=/usr/local/mysql5051 –without-debug –with-unix-socket-path=/usr/local/mysql5051/mysql.sock –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-static –enable-assembler –with-extra-charsets=gbk,gb2312,utf8 –with-pthread –enable-thread-safe-client
-
make
-
make install
- 修改目录的权限
-
chmod +w /usr/local/mysql5051
-
chown -R mysql:mysql /usr/local/mysql5051
- 复制默认配置文件
-
cp support-files/my-medium.cnf /usr/local/mysql5051/my.cnf
-
cp support-files/mysql.server /etc/init.d/mysqld
-
chmod +x /etc/init.d/mysqld
-
cd ../
- 初始化mysql库
-
/usr/local/mysql5051/bin/mysql_install_db –defaults-file=/usr/local/mysql5051/my.cnf –basedir=/usr/local/mysql5051 –datadir=/usr/local/mysql5051/data –user=mysql –pid-file=/usr/local/mysql5051/mysql.pid –skip-locking –port=3306 –socket=/tmp/mysql.sock
- 开启MySQL数据库服务
-
/bin/sh /usr/local/mysql5051/bin/mysqld_safe –defaults-file=/usr/local/mysql5051/my.cnf &
-
chkconfig –add mysqld
-
chkconfig –level 3456 mysqld on
-
/sbin/service mysqld start
-
/sbin/service mysqld stop
- 验证MySQL服务器运行情况
mysql 5.0.51 源码包获取。
设定安装路径到 /usr/local/mysql5051
建立初始化的数据库表,数据库数据存放在 /usr/local/mysql5051/data目录下
直接的命令行方式开启
或通过服务控制方式开启关闭服务
1.ps -fe |grep mysql 查看运行的进程
2.netstat -na |grep mysql 查看开放的端口
3./usr/local/mysql5051/bin/mysql -u root -p 登陆mysql看一下,同时可以修改一下root密码。
安装 php 5.2.6
- 下载源码包
-
wget http://cn2.php.net/get/php-5.2.6.tar.gz/from/cn.php.net/mirror
-
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
- 安装依赖包
-
rpm -ivh libjpeg-devel-6b-33.i386.rpm
-
rpm -ivh libpng-devel-1.2.7-1.i386.rpm
-
rpm -ivh freetype-devel-2.1.9-1.i386.rpm
-
rpm -ivh gd-devel-2.0.28-4.i386.rpm
-
tar -xzvf 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 -xzvf php-5.2.6.tar.gz
-
cd php-5.2.6
-
./configure –prefix=/usr/local/php526 –with-config-file-path=/usr/local/php526/etc –with-gd=/usr/ –enable-gd-native-ttf –with-ttf –with-freetype-dir –with-jpeg-dir=/usr/ –with-png-dir=/usr/ –with-zlib=/usr/ –with-mysql=/usr/local/mysql5051 –with-openssl=/usr/local/ssl –enable-mbstring –with-curl –with-curlwrappers –with-iconv-dir=/usr/local –with-libxml-dir –enable-xml –disable-debug –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –enable-mbregex –enable-fastcgi –enable-force-cgi-redirect –with-mcrypt
-
make
-
make install
-
cd ..
- 启动php的fast-cg进程
-
ulimit -SHn 51200
-
/usr/local/php526/spawn-fcgi -a 127.0.0.1 -p 10080 -C 30 -u www -f /usr/local/php526/bin/php-cgi
php 5.2.6
php 安装需要的一些配置包。
libmcrypt
先从RHEL安装盘上拷贝出如下一些rpm包用 rpm -ivh xxx.rpm 方式安装上。
在用源码方式安装下载下来的源码包
使用lighttpd带的 spwan-fcgi, 如下以www身份开启30个fast-cgi进程
安装 nginx
nginx的中文Wiki站点 http://wiki.codemongers.com/NginxChs
niginx的英文站点 http://nginx.net
- 下载需要的资源
-
wget http://sysoev.ru/nginx/nginx-0.6.32.tar.gz
-
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.7.tar.gz
- 安装需要的库
-
tar -xzvf pcre-7.7.tar.gz
-
cd pcre-7.7/
-
./configure
-
make
-
make install
-
cd ../
- 从源码包编译安装Nginx
-
tar -xzvf nginx-0.6.32.tar.gz
-
cd nginx-0.6.32/
-
./configure –user=www –group=www –prefix=/usr/local/nginx632 –with-http_stub_status_module
-
make
-
make install
-
cd ../
- 建立WEB账号以及组
-
/usr/sbin/groupadd www -g 48
-
/usr/sbin/useradd -u 48 -g www www
- 建立相关网站目录
-
mkdir -p /var/www/xxt.igrow.cn
-
chmod +w /var/www/xxt.igrow.cn
-
chown -R www:www /var/www/xxt.igrow.cn
-
mkdir -p /var/www/logs
-
chmod +w /var/www/logs
-
chown -R www:www /var/www/logs
- 做Nginx参数配置
-
user www www;
-
-
worker_processes 8;
-
-
error_log /var/www/logs/nginx_error.log crit;
-
pid /usr/local/nginx632/nginx.pid;
-
-
worker_rlimit_nofile 51200;
-
-
events
-
{
-
use epoll;
-
worker_connections 51200;
-
}
-
-
http
-
{
-
include mime.types;
-
default_type application/octet-stream;
-
-
charset utf-8;
-
-
server_names_hash_bucket_size 128;
-
-
sendfile on;
-
tcp_nopush on;
-
-
keepalive_timeout 60;
-
tcp_nodelay on;
-
-
fastcgi_connect_timeout 60;
-
fastcgi_send_timeout 180;
-
fastcgi_read_timeout 180;
-
fastcgi_buffer_size 128k;
-
fastcgi_buffers 4 128k;
-
fastcgi_busy_buffers_size 128k;
-
fastcgi_temp_file_write_size 128k;
-
fastcgi_temp_path /dev/shm;
-
-
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 xxt.igrow.cn;
-
index index.html index.htm index.php;
-
root /var/www/xxt.igrow.cn;
-
-
if (-d $request_filename)
-
{
-
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
-
}
-
-
location ~ .*\.php?$
-
{
-
include 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 /var/www/logs/access.log access;
-
}
-
-
server
-
{
-
listen 80;
-
server_name status.xxt.igrow.cn;
-
-
location / {
-
stub_status on;
-
access_log off;
-
}
-
}
-
}
-
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;
- 启动Nginx
-
ulimit -SHn 51200
-
/usr/local/nginx632/sbin/nginx
-
the configuration file /usr/local/nginx632/conf/nginx.conf syntax is ok
-
the configuration file /usr/local/nginx632/conf/nginx.conf was tested successfully
获取nginx 0.6.32 源码包和所依赖的 pcre 源码包
设定安装目录到 /usr/local/nginx632
建立以 www:www 的账号和组用来运行网站服务。
存放网站的路径
日志路径
建nginx.conf文件
cat /usr/local/nginx632/conf/nginx.conf:
建fcgi.conf文件
cat /usr/local/nginx632/conf/fcgi.conf
在运行前可以通过 /usr/local/nginx632/sbin/nginx -t 检查一下看nginx的参数是否配置正确。
如果屏幕显示以下两行信息,说明配置文件正确:
配置开机启动Mysql+Phpcgi+Nginx
因为没有安装服务,需要添加一些命令到 /etc/rc.local 中用来开机启动
-
ulimit -SHn 51200
-
/bin/sh /usr/local/mysql5051/bin/mysqld_safe –defaults-file=/usr/local/mysql5051/my.cnf &
-
/usr/local/php526/spawn-fcgi -a 127.0.0.1 -p 10080 -C 30 -u www -f /usr/local/php526/bin/php-cgi
-
/usr/local/nginx632/sbin/nginx
设置iptables
在防火墙中放开相关服务端口。
-
#web port
-
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-
#fastcgi port
-
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 10080 -s 127.0.0.1 -j ACCEPT
-
#mysql 本地通过unix socket访问, 不用设置
-
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp -s 127.0.0.1 –dport 3306 -j ACCEPT
使用 /sbin/service iptables restart 重新应用防火墙规则
验证服务状态
验证 nginx + php 运行是否正常。
在 /var/www/xxt.igrow.cn 目录下建一个test.php,里面存放内容
-
<?
-
echo phpinfo();
-
?>
通过 curl http://127.0.0.1/test.php 可以看到输出的php信息,表示 nginx + php 运行正常。
Popularity: 4% [?]
Related
July 11, 2008 | Filed Under LAMP, MySQL, WebServer
Comments
4 Responses to “安装配置Nginx 0.6.32 +php 5.2.6(fastcgi) + Mysql 5.0.51”
anybody here know of a good site to find more info on php force cgi redirect? I’ve got this site bookmarked and im gonna keep checking it out, but i still would like to find a site that covers php force cgi redirect a little more thoroughly..thanks
[Reply]
[...] 11, 2008 — 安装配置Nginx 0.6.32 +php 5.2.6(fastcgi) + Mysql 5.0.51 (1) Trackback url | Rss [...]
兄弟, 你好, 我安装php后, bin目录下怎么会没有php-cgi ?
我在./configure –enable-cgi 我也指定这个参数啦? 怎么会没有php-cgi这个文件啊 ?
期待你的回答!!
谢谢!!
[Reply]
sunny Reply:
November 27th, 2008 at 5:36 pm
你编译后在 ./sapi/cgi 目录下找一下看有没有文件
一般编译后的文件在 ./sapi目录下,可以看自己关注的 cgi, cli, apache等目录下有没有生成相关需要的文件。
如果是重新编译的话记住要 make clean 一下先
[Reply]