2014-04-09 10:14:01
来 源
itjs.cn
Nginx
本篇分享了Linux系统编译安装nginx+mysql+php,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。
此次安装nginx只是用于静态页面,而没有+mysql和php (1)安装PCRE,它是perl所用到的正则表达式,目的是让所有软件支持正则表达式,默认Nginx只处理静态网页。如果是来自动态网页php的请求,那么Nginx就需要根据正则表达式查询路径,然后把*.php的交给PHP去处理

先查看是否安装pcre,默认都是安装好了的,但是Nginx找不到默认安装好的pcre,所以需要删除,再从新安装。安装前先保存/lib/libpcre.so.0这个文件

cp /lib/libpcre.so.0 /

rpm -e --nodeps pcre-7.8-3.1.el6.i686

tar -zxf pcre-8.00.tar.gz

cd pcre-8.00

cp /libpcre.so.0 /lib/

./configure

make && make install

(2)安装nginx

tar -zxf nginx-08.24.tar.gz

cd nginx-08.24

./configure --prefix=/usr/local/nginx

make && make install

/usr/local/nginx/sbin/nginx

=====================================================================

2012-05-22 再次安装后的配置文档 nginx+mysql+php

1 mysql安装

yum install ncurses-devel

yum install libtermcap-devel

#tar xvfz mysql-5.0.80.tar.gz

#cd mysql-5.0.80

修改mysql客户端最大连接数,默认的只有100,修改为1000

# vi sql/mysqld.cc

{"max_connections", OPT_MAX_CONNECTIONS,

"The number of simultaneous clients allowed.", (gptr*) &max_connections,

(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,

0},

将其中的100改为1000,不建议改的太大。

{"max_connections", OPT_MAX_CONNECTIONS,

"The number of simultaneous clients allowed.", (gptr*) &max_connections,

(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1000, 1, 16384, 0, 1,

0},

*************************************************

上面的修改在6131行

*************************************************

./configure --prefix=/opt/mysql --localstatedir=/var/lib/mysql --with-comment=Source --with-server-suffix=-enterprise-gpl --with-mysqld-user=mysql --without-debug --with-big-tables --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-pthread --enable-static --enable-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --without-ndb-debug --with-unix-socket-path=/opt/mysql/tmp/mysql.sock

执行成功后会显示:

config.status: executing depfiles commands

MySQL has a Web site at http://www.mysql.com/ which carries details on the

latest release, upcoming features, and other information to make your

work or play with MySQL more productive. There you can also find

information about mailing lists for MySQL discussion.

Remember to check the platform specific part of the reference manual for

hints about installing MySQL on your platform. Also have a look at the

files in the Docs directory.

Thank you for choosing MySQL!

编译的时间可能会比较长

make && make install

编译安装完成后执行后续操作:

useradd mysql //添加 mysql 用户

cd /opt/mysql

bin/mysql_install_db --user=mysql

chown -R mysql /opt/mysql //设置权限

chown -R mysql /var/lib/mysql //设置 mysql目录权限

cp /opt/mysql/share/mysql/my-large.cnf /etc/my.cnf

cp /opt/mysql/share/mysql/mysql.server /etc/init.d/mysqld //开机自动启动 mysql。

chmod 755 /etc/init.d/mysqld

chkconfig --add mysqld

/etc/init.d/mysqld start //启动 MySQL

/opt/mysql/bin/mysqladmin -u root password "password_for_root" //password_for_root为密码.本机是mysql

/opt/mysql/bin/mysql –u root –p //进入mysql客户端

(/opt/mysql/bin/mysql -u root -p 提示Enter password: 输入密码,回车进入)

/etc/init.d/mysqld stop //关闭 MySQL

ln -s /opt/mysql/bin/mysql /usr/bin/

2 安装pcre

PCRE,它是perl所用到的正则表达式,目的是让所有软件支持正则表达式,默认Nginx只处理静态网页。如果是来自动态网页php的请求,那么Nginx就需要根据正则表达式查询路径,然后把*.php的交给PHP去处理

先查看是否安装pcre,默认都是安装好了的,但是Nginx找不到默认安装好的pcre,所以需要删除,再从新安装。安装前先保存/lib/libpcre.so.0这个文件

cp /lib/libpcre.so.0.0.1 /opt/libpcre.so.0.0.1.32bit

cp /lib64/libpcre.so.0.0.1 /opt/libpcre.so.0.0.1.64bit

rpm -e --nodeps pcre-7.8-3.1.el6.i686

注意:再删除pcre时可能会出错

*************************************************************

因为64bit系统会包含32bit系统的同名库文件,想删除两个同名的rpm文件会报错,请使用下面命令

rpm -qa | grep pcre | xargs rpm -e --allmatches --nodeps

*************************************************************

解压缩

tar -zxf pcre-8.12.tar.gz

cd pcre-8.12

cp /opt/libpcre.so.0.0.1.64bit /lib/libpcre.so.0

./configure --prefxi=/opt/pcre

make && make install

3 安装nginx

yum install openssl-devel

groupadd nginx

useradd -g nginx nginx

./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-pcre=../pcre-8.12 --with-http_stub_status_module --with-http_ssl_module

安装nginx时,make遇到的错误

*************************************************************

环境 nginx 1.0.5

configure 配置通过

./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre/ --with-openssl=/usr/local/openssl/ --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --user=nginx --group=nginx

make 错误

[[email protected] nginx-1.0.5]# make

make -f objs/Makefile

make[1]: Entering directory `/root/nginx/nginx-1.0.5'

cd /usr/local/pcre/

&& if [ -f Makefile ]; then make distclean; fi

&& CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe "

./configure --disable-shared

/bin/sh: line 2: ./configure: No such file or directory

make[1]: *** [/usr/local/pcre//Makefile] Error 127

make[1]: Leaving directory `/root/nginx/nginx-1.0.5'

make: *** [build] Error 2

google

make[1]: *** [/usr/local/pcre//Makefile] Error 127

分析

[[email protected] nginx-1.0.5]# ./configure --help | grep '--with-pcre'

--with-pcre force PCRE library usage

--with-pcre=DIR set path to PCRE library sources

--with-pcre-opt=OPTIONS set additional options for PCRE building

source ????????

解决

[[email protected] nginx-1.0.5]# ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.12/ --with-openssl=/usr/local/openssl/ --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --user=nginx --group=nginx

[[email protected] nginx-1.0.5]# make

make -f objs/Makefile

make[1]: Entering directory `/root/nginx/nginx-1.0.5'

cd ../pcre-8.12/

&& if [ -f Makefile ]; then make distclean; fi

&& CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe "

./configure --disable-shared

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... make[1]: *** [../pcre-8.12//Makefile]

ok

总结:--with-pcre=DIR 是设置源码目录,而不是编译安装后的目录。

*************************************************************

make && make install

*************************************************************

安装后的结果

nginx path prefix: "/opt/nginx"

nginx binary file: "/opt/nginx/sbin/nginx"

nginx configuration prefix: "/opt/nginx/conf"

nginx configuration file: "/opt/nginx/conf/nginx.conf"

nginx pid file: "/opt/nginx/logs/nginx.pid"

nginx error log file: "/opt/nginx/logs/error.log"

nginx http access log file: "/opt/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"

*************************************************************

启动nginx进程

/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

4 PHP的安装

yum install libxml2

yum install libxml2-devel

安装jpeg库

tar -zxvf jpegsrc.v7.tar.gz

./configure --prefix=/opt/php-module/jpeg-7/ --enable-shared --enable-static

make && make install

安装libpng

tar -jxvf libpng-1.2.10.tar.bz2

./configure --prefix=/opt/php-module/libpng/

make && make install

安装freetype

tar -zxvf freetype-2.1.10.tar.gz

./configure --prefix=/opt/php-module/freetype

make && make install

安装php

使用php-fpm来做nginx的php gateway

PHP 5.3.8内置了php-fpm ( FastCGI Process Manager SAPI ) 模块,

也就是说如果你使用Nginx的话,编译php时候直接加上参数--enable-fpm就可以了。

cd php-5.3.8

export LD_LIBRARY_PATH=/opt/mysql/lib/mysql/

./configure --prefix=/opt/php --enable-fpm --with-mysql=/opt/mysql --enable-sockets --with-gd --with-freetype-dir=/opt/php-module/freetype --with-jpeg-dir=/opt/php-module/jpeg-7 --with-png-dir=/opt/php-module/libpng

make && make install

5 配置php-fpm

#cd /opt/php/etc

#cp php-fpm.conf.default php-fpm.conf

修改php-fpm.conf文件内容

pm.max_children = 100

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

request_terminate_timeout = 10m

启动服务,监听9000端口

/opt/php/sbin/php-fpm

6 配置nginx.conf

[[email protected] conf]# more nginx.conf

user nginx;

worker_processes 1;

error_log /opt/nginx/logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

pid /opt/nginx/logs/nginx.pid;

events {

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 /opt/nginx/logs/access.log;

sendfile on;

tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen 80;

server_name 192.168.198.5;

index index.html index.htm index.php;

#charset koi8-r;

access_log /opt/nginx/logs/host.access.log;

location / {

root html;

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/php;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME $document_root$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;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443;

# server_name localhost;

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。