nginx + php(fastcgi) + mysql + eaccelerator + ZendOptimizer + phpmyadmin |
所需软件 |
spawn-fcgi-1.6.0.tar.gz |
nginx-0.6.36.tar.gz |
mysql-5.0.56.tar.gz |
php-5.2.6.tar.gz |
ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz |
phpMyAdmin-3.1.3-all-languages.tar.bz2 |
suhosin-patch-5.2.6-0.9.6.2.patch.gz |
eaccelerator-0.9.5.3.tar.bz2 |
自己整理的,可能会有些排版问题导致某些字符错误。附件有个精简版的,命令字符无误。
操作系统:
Nginx安装
安装需要的库
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g zlib1g-dev
sudo apt-get install libssl0.9.8 libssl-dev
建立用户
sudo groupadd www
sudo useradd -g www www
安装命令
tar -zxvf nginx-0.6.36.tar.gz
cd nginx-0.6.36/
./configure --user=www --group=www --prefix=/opt/web/nginx636 --with-http_stub_status_module --with-http_ssl_module
make
sudo make install
sudo ln -s /opt/web/nginx636/sbin/nginx /sbin/nginx
启动与重启
启动:sudo nginx
关闭:sudo pkill nginx
重启:sudo kill -HUP `cat /opt/web/nginx636/logs/nginx.pid`
测试配置文件:sudo nginx -t
存放网站的路径
sudo mkdir -p /var/www/bbs.sends.cc
sudo chmod +w /var/www/bbs.sends.cc
sudo chown -R www:www /var/www/bbs.sends.cc
sudo chown -R www:www /opt/web/nginx636/logs
配置配置文件
sudo vi /opt/web/nginx636/conf/nginx.conf
以下仅供参考,请认真阅读
官方wiki后跟据自身需要配置
/opt/web/nginx636/conf/nginx.conf
#user nobody;
user www www;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
#my config
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
tcp_nodelay on;
#fastcgi
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
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;
#my config end
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;
#keepalive_timeout 0;
keepalive_timeout 45;
#gzip on;
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /var/www/bbs.sends.cc;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location ~ .*\.php?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:20080;
fastcgi_index index.php;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
#charset koi8-r;
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 logs/bbs.access.log access;
location /NginxStatus {
stub_status on;
access_log off;
auth_basic "NginxStatus";
}
#location / {
# root html;
# index index.html index.htm;
#}
#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 /scripts$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 ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
/opt/web/nginx636/conf/fastcgi.conf
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;
开机启动所有此次安装的服务(加入rc.local)
sudo /etc/init.d/mysqld start
sudo /opt/web/nginx636/sbin/spawn-fcgi -a 127.0.0.1 -p 20080 -C 30 -u www -f /opt/web/php/bin/php-cgi
sudo /opt/web/nginx636/sbin/nginx
优化
sudo vi /etc/security/limits.conf
加入两行:
* hard nofile 65535
* soft nofile 65535
sudo vi /etc/sysctl.conf
尾部加入:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000
查看正确配置与否
sudo sysctl -p
Mysql安装
sudo groupadd mysql
sudo useradd -g mysql mysql
安装相关库
sudo apt-get install libncurses5-dev
sudo apt-get install libncursesw5-dev
安装命令
tar zxvf mysql-5.0.56.tar.gz
cd mysql-5.0.56
./configure --prefix=/opt/web/mysql --enable-assembler --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-extra-charsets=all --with-charset=utf8 --with-collation=utf8_general_ci --enable-thread-safe-client --without-debug --without-bench
make
sudo make install
sudo cp support-files/my-medium.cnf /etc/my.cnf
sudo cp support-files/mysql.server /etc/init.d/mysqld
sudo chmod 700 /etc/init.d/mysqld
sudo ./scripts/mysql_install_db --user=mysql
设置用户访问权限
cd /opt/web/mysql
sudo chown -R root .
sudo chown -R mysql var
sudo chown -R mysql var/.
sudo chown -R mysql var/mysql/.
sudo chgrp -R mysql .
启动设置
sudo /opt/web/mysql/bin/mysqld_safe --user=mysql &
sudo mysqladmin -uroot password newpassword
sudo mysql -uroot -pnewpassword
mysql>use mysql;
mysql>delete from user where password=""; #删除用于本机匿名连接的空密码帐号
mysql>flush privileges;
mysql>quit
PHP安装
安装lighttpd的spawn-fcgi用于控制php-cgi
tar zxvf spawn-fcgi-1.6.0.tar.gz
cd spawn-fcgi-1.6.0
./configure
sudo cp src/spawn-fcgi /opt/web/nginx636/sbin/
安装相关库
sudo apt-get install libxml2-dev
sudo apt-get install libcurl4-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libpng3-dev
sudo apt-get install libfreetype6-dev
sudo apt-get install libxslt1-dev
安装命令
gunzip suhosin-patch-5.2.6-0.9.6.2.patch.gz
tar zxvf php-5.2.6.tar.gz
cd php-5.2.6
patch -p1 < ../suhosin-patch-5.2.6-0.9.6.2.patch
./configure --prefix=/opt/web/php --with-mysql=/opt/web/mysql --with-config-file-path=/opt/web/nginx636/conf --with-openssl=/usr --with-curl --with-libxml-dir --enable-soap --with-xsl --with-gd --with-jpeg-dir --with-zlib-dir --with-freetype-dir --with-png-dir --enable-mbstring --with-iconv --enable-magic-quotes --enable-inline-optimization --enable-ftp --enable-fastcgi -with-mcrypt --enable-force-cgi-redirect --enable-short-tags --disable-debug --with-mysqli=/opt/web/mysql/bin/mysql_config
make
sudo make test
sudo make install
配置文件修改
sudo cp php.ini-dist /opt/web/nginx636/conf/php.ini
sudo vi /opt/web/nginx636/conf/php.ini
;default_charset = "iso-8859-1"
#在这行下面加一行
default_charset = "utf-8"
安装zendOptimizer and phpmyadmin
tar zxvf ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-x86_64
./install.sh
安装步骤略
tar zxvf phpMyAdmin-3.1.3-all-languages.tar.bz2
sudo cp –rf phpMyAdmin-3.1.3-all-languages /var/www/phpadmin
cd /var/www/phpadmin
cp config.sample.inc.php config.inc.php
sudo vi config.inc.php
phpMyadmin可以各人发挥了,每个人的配置可能不一样。
$cfg['blowfish_secret'] = 'cookie';(使用cookie加密)
$cfg['Servers'][$i]['connect_type'] = 'socket';(以socket方式连接MySQL)
$cfg['Servers'][$i]['compress'] = TRUE;
(启用压缩以提高速度,如果访问不正常请改回FALSE)
$cfg['Servers'][$i]['auth_type'] = 'cookie';(使用cookie进行身份验证)
安装结束后可以用 http://localhost/phpadmin 测试phpmyadmin
安装eAccelerator
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3
./configure -enable-eaccelerator=shared -with-php-config=/opt/web/php/bin/php-config
make
sudo make install
安装完后记住扩展所在地址,如:/opt/web/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so
sudo vi /opt/web/nginx636/conf/php.ini
插入配置,注意:必须[Zend]前加入
[eAccelerator]
zend_extension="/opt/web/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
[Zend]
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3
zend_optimizer.version=3.3.3
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so
启动php-cgi
nginx636/sbin/spawn-fcgi -a 127.0.0.1 -p 20080 -C 30 -u www -g www –f /opt/web/php/bin/php-cgi
检查配置是否正确
sudo /opt/web/php/bin/php -v
作者
分享到:
相关推荐
Linux+nginx+php+mysql+memcache服务器安装,配置与优化 .pdf Nginx官网配置.pdf Nginx基本配置.pdf Nginx模块.pdf Nginx指南.pdf 第1章 Nginx简介.pdf 第2章 Nginx服务器的安装与配置.pdf 第3章 Nginx的基本配置与...
Windows+Nginx+PHP7安装配置 在本文中,我们将详细介绍如何在Windows环境下安装和配置Nginx和PHP7,从而实现一个完美的PHP开发环境。本文将从头到尾详细介绍安装和配置的每一个步骤,使您能够快速解决问题,并少走...
选择与Nginx版本兼容的PHP版本,同时确保安装时勾选`php-fpm`(FastCGI Process Manager)组件。安装完成后,编辑`php.ini`配置文件,开启需要的扩展,如`php_mysql.dll`、`php_pdo.dll`等。 接着配置`php-fpm`。...
### Nginx与PHP配置详解 #### Nginx配置步骤 **一、开启Nginx服务** 1. **编辑Nginx配置文件**: 首先需要编辑Nginx的配置文件,通常位于`/etc/nginx/nginx.conf`或`/usr/local/nginx/conf/nginx.conf`。在配置...
本文将详细介绍如何安装和配置Nginx以及PHP,以实现一个能够展示WEB页面的服务器。 首先,我们需要在Linux系统上安装Nginx。这里以CentOS为例,可以使用`yum`包管理器来简化安装过程。运行以下命令来安装Nginx: `...
windows 下nginx和php 安装配置,可以学习安装步骤和配置信息
3. 配置Nginx与PHP:在Nginx的站点配置文件中添加`location ~ \.php$ { ... }`段,指定PHP处理器。 **整合LAMP/LNMP**: 1. 对于LAMP,Apache直接处理PHP文件。确保Apache配置正确识别.php文件并传递给PHP解释器。 ...
第4章 Nginx与PHP(FastCGI)的安装、配置与优化 第5章 Nginx与JSP、ASP.NET、Perl的安装与配置 第6章 Nginx HTTP负载均衡和反向代理的配置与优化 第7章 Nginx的Rewrite规则与实例 第8章 Nginx模块开发 .................
【标题】:“基于Linux下Nginx的安装与项目部署详解” 【描述】:本文将详细介绍如何在Linux系统中安装Nginx,并探讨其主要功能,包括反向代理、负载均衡以及项目部署的具体操作。 【标签】:“Nginx”,“Nginx...
nginx for windows下载以及详细安装与配置 1.目前官方 Nginx 并不支持Windows,您只能在包括Linux,UNIX,BSD系统下安装和使用,现在提供nginx for windows下载以及详细安装与配置,供windows下的nginx应用。 2.Nginx ...
### 第4章 Nginx与PHP(FastCGI)的安装、配置与优化 #### Nginx+FastCGI运行原理详解 Nginx作为一款高性能的Web服务器,在处理动态内容时,通常需要借助于FastCGI接口来调用外部程序(如PHP)。这种架构不仅提升了...
接着,我们需要安装PHP以及与Nginx交互所需的PHP-FPM(FastCGI Process Manager)。在Ubuntu/Debian上: 1. 安装PHP:`sudo apt install php-fpm php-mbstring php-curl php-gd php-xml` 2. 配置PHP-FPM:确保`/etc...
【Nginx与PHP的整合】 在Web服务器领域,Nginx以其高效的反向代理、负载均衡和静态文件处理能力而备受青睐。与此同时,PHP是动态网站开发中广泛使用的服务器端脚本语言,尤其适合处理PHP框架如ThinkPHP的应用。将...