热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ubuntu编译安装php5mysqlnginx_MySQL

ubuntu编译安装php5mysqlnginx
UbuntuNginx

一、首先下载软件源码包
wget http://sysoev.ru/nginx/nginx-0.8.53.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/php/php-5.2.10.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.10-fpm-0.5.11.diff.gz
wget http:/.s135.com/soft/linux/nginx_php/mysql/mysql-5.1.38.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http:/.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/pcre/pcre-7.9.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.5.3.tar.bz2
wget http:/.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http:/.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http:/.s135.com/soft/linux/nginx_php/imagick/imagick-2.2.2.tgz
二、安装PHP 5.2.10(FastCGI模式)
1、首先安装PHP 5.2.10所需的支持库
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure –prefix=/usr/local
make
make install
cd ..
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
cd ..
#在make中途出错的话, apt-get install g++ ,然后重新再做一边

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

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ..

2、编译安装MySQL 5.1.38
添加mysql用户组和用户
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.1.38.tar.gz
cd mysql-5.1.38/
./configure –prefix=/usr/local/webserver/mysql/ –enable-assembler –with-extra-charsets=complex –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=innobase
make && make install
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ..

#如果编译过程中出现如下错误
#checking for tgetent in -ltermcap… no
#checking for termcap functions library… configure: error: No curses/termcap library found
#说明 curses/termcap 库没有安装去下载一个ncurses-5.6.tar.gz,
#wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
#tar zxvf ncurses-5.6.tar.gz
#cd ncurses-5.6
# ./configure –prefix=/usr –with-shared –without-debug
# make
# make install clean
#然后再重新编译Mysql进行安装。
#如果又遇到如下错误:
make[2]: *** [do_abi_check] 错误 1
make[2]: Leaving directory `/tmp/mysql-5.5.3-m3′
make[1]: *** [abi_check] 错误 2
make[1]: Leaving directory `/tmp/mysql-5.5.3-m3′
make: *** [all-recursive] 错误 1
#在网上搜了一下,说是Mysql的一个Bug,解决方法是打开Makefile将do_abi_check:后面的语句删除,注意do_abi_check:需要留下来,然后再 make && make install

附:以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下两步。如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
1)、创建MySQL数据库存放目录
mkdir -p /var/webserver/mysql/3306/data
chown -R mysql:mysql /var/webserver/mysql/3306

2)、以mysql用户帐号的身份建立数据表:
/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/var/webserver/mysql/3306/data –user=mysql

3)、创建my.cnf配置文件:
vim /var/webserver/mysql/3306/my.cnf
输入以下内容:
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock

[mysql]
prompt=”(/u:blog.s135.com:)[/d]> ”
no-auto-rehash

[mysqld]
#default-character-set = utf8
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /var/webserver/mysql/3306/data
open_files_limit = 10240
back_log = 600
max_cOnnections= 3000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_cOncurrency= 8
query_cache_size = 32M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 1
log_long_format
log-bin = /var/webserver/mysql/3306/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 2048M #如果启动不了Mysql把它改为1024或者增大swap分区的大小
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_file_io_threads = 4
innodb_thread_cOncurrency= 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 32M

4)、创建管理MySQL数据库的shell脚本:
vim /etc/init.d/mysql
输入以下内容:
#!/bin/sh
mysql_port=3306
mysql_username=”root”
mysql_password=”root”
function_start_mysql()
{
printf “Starting MySQL…/n”
/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe –defaults-file=/var/webserver/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}

function_stop_mysql()
{
printf “Stoping MySQL…/n”
/usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}

function_restart_mysql()
{
printf “Restarting MySQL…/n”
function_stop_mysql
sleep 5
function_start_mysql
}

function_kill_mysql()
{
kill -9 $(ps -ef | grep ‘bin/mysqld_safe’ | grep ${mysql_port} | awk ‘{printf $2}’)
kill -9 $(ps -ef | grep ‘libexec/mysqld’ | grep ${mysql_port} | awk ‘{printf $2}’)
}

if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf “Usage: /var/webserver/mysql/${mysql_port}/mysql {start|stop|restart|kill}/n”
fi

5)、添加执行权限
sudo chmod +x /etc/init.d/mysql

6)、添加mysql服务(ubuntu),并启动服务添加自定义shell命令
#添加mysql服务
sudo update-rc.d mysql defaults 100

#启动mysql服务
service mysql start

#添加自写义shell命令,方便进入mysql
sudo vim ~/.bashrc
#在最后一行加入以下内容
mysql () {
/usr/local/webserver/mysql/bin/mysqlr
}

#让其立即生效
source ~/.bashrc

7)、登陆mysql以上添加好之后,直接输入mysql就可以登陆进去了

8)、输入以下SQL语句,创建一个具有root权限的用户
GRANT ALL PRIVILEGES ON *.* TO ‘root’@'localhost’ IDENTIFIED BY ”;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’127.0.0.1′ IDENTIFIED BY ”;

3、编译安装PHP(FastCGI模式)
tar zxvf php-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1
cd php-5.2.10/
./configure –prefix=/usr/local/webserver/php –with-config-file-path=/usr/local/webserver/php/etc –with-mysql=/usr/local/webserver/mysql –with-mysqli=/usr/local/webserver/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 –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –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 –without-pear

#如果出现下面的错误提示
#checking for xml2-config… no
#checking for xml-config… no
#configure: error: XML configuration could not be found
#安装 apt-get install libxml2-dev
#如果出现下面的错误提示
#checking for pkg-config… /usr/bin/pkg-config
#configure: error: Cannot find OpenSSL’s
#安装 apt-get install libssl-dev”
#如果出现下面的错误提示
#checking for cURL in default path… not found
#configure: error: Please reinstall the libcurl distribution – easy.h should be in /include/curl/
#安装: apt-get install libcurl4-gnutls-dev
#如果出现:
#configure: error: libjpeg.(a|so) not found.
#安装: apt-get install libjpeg-dev
#如果出现:
#configure: error: libpng.(a|so) not found.
#安装: apt-get install libpng12-dev
#如果出现:configure: error: freetype.h not found.
#安装: apt-get install libfreetype6-dev
#如果出现:configure: error: sasl.h not found!
#安装: apt-get install libsasl2-dev
如果出现:

+——————————————————————–+

| *** ATTENTION *** |

| |

| Something is likely to be messed up here, because the configure |

| script was not able to detect a simple feature on your platform. |

| This is often caused by incorrect configuration parameters. Please |

| see the file debug.log for error messages. |

| |

| If you are unable to fix this, send the file debug.log to the |

| php-install@lists.php.net mailing list and include appropiate |

| information about your setup. |

+——————————————————————–+

| License: |

| This software is subject to the PHP License, available in this |

| distribution in the file LICENSE. By continuing this installation |

| process, you are bound by the terms of this license agreement. |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point. |

+——————————————————————–+

Thank you for using PHP.

#到php安装程序目录(编译PHP的目录)去查看debug.log最后几行如果有以下警告

A conftest.c:3: warning: incompatible implicit declaration of built-in function ‘exit’

B ./conftest: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

#增加LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql到环境变量,方法为编辑/etc/profile文 件,添 加:export LD_LIBRARY_PATH=/usr/local/webserver/mysql/lib/mysql
#如果不想重启使用 . /etc/profile 就可以了,注意.和/etc中间有空格,然后再重新编译

make ZEND_EXTRA_LIBS=’-liconv’
make install

#复制配置好的php.ini到/usr/local/webserver/php/etc/目录下
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ..
#curl http://pear.php.net/go-pear | /usr/local/webserver/php/bin/php

4、编译安装PHP5扩展模块
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/webserver/php/bin/phpize
./configure –with-php-cOnfig=/usr/local/webserver/php/bin/php-config
make
make install
cd ..

#如果出现:
#Cannot find autoconf. Please check your autoconf installation and the

#$PHP_AUTOCONF environment variable. Then, rerun this script.

#安装:

#sudo apt-get install m4

#sudo apt-get install autoconf

#或者直接:

#sudo apt-get install autoconf

#因为autoconf 依赖于m4,所以会自动下载解决这个依赖关系.

tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/webserver/php/bin/phpize
./configure –enable-eaccelerator=shared –with-php-cOnfig=/usr/local/webserver/php/bin/php-config
make
make install
cd ..

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-cOnfig=/usr/local/webserver/php/bin/php-config –with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ..

tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ..

#如果执行make时出错,信息提示如下:
#/usr/bin/ld: cannot find -lperl
#collect2: ld returned 1 exit status
#make[2]: *** [blib/arch/auto/Image/Magick/Magick.so] 错误 1
#make[2]:正在离开目录 `/home/ouyangjunqiu/下载/ImageMagick-6.5.1-2/PerlMagick’
#make[1]: *** [all-perl] 错误 2
#make[1]:正在离开目录 `/home/ouyangjunqiu/下载/ImageMagick-6.5.1-2′
#make: *** [all] 错误 2
#有两种解决方法
#1.在配置的时候加个。。
#./configure –without-perl
#2.安装库文件
#apt-get install libperl-dev
#安装完成后验证一下是否能正常工作输入convert -version 如果出现如下错误:
convert: error while loading shared libraries: libMagickCore.so.2: cannot open shared object file: No such file or directory
#我们需要把安装目录下缺失的文件,用ln链接到/usr/lib目录下
#ln -s /usr/local/lib/libMagickCore.so.2 /usr/lib
#然后可以使用convert xx.jpg xx.gif 把jpg的图片转换为gif看看能不能正常使用

tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/usr/local/webserver/php/bin/phpize
./configure –with-php-cOnfig=/usr/local/webserver/php/bin/php-config
make
make install
cd ..

5、修改php.ini文件
手工修改:查找/usr/local/webserver/php/etc/php.ini中的extension_dir = “./”
修改为extension_dir = “/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”

再查找output_buffering = Off
修改为output_buffering = On

6、配置eAccelerator加速PHP:
mkdir -p /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini

按shift+g键跳到配置文件的最末尾,加上以下配置信息:

[eaccelerator]
zend_extension=”/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so”
eaccelerator.shm_size=”64″
eaccelerator.cache_dir=”/usr/local/webserver/eaccelerator_cache”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
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″

7、创建www用户和组:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /var/webserver/www
chmod +w /var/webserver/www
chown -R www:www /var/webserver/www

8、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi):
在/usr/local/webserver/php/etc/目录中创建php-fpm.conf文件:
rm -rf /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf
输入以下内容(如果您安装 Nginx + PHP 用于程序调试,请将以下的0改为1,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页):


All relative paths in this config are relative to php’s install prefix

Pid file
/usr/local/webserver/php/logs/php-fpm.pid

Error log file
/usr/local/webserver/php/logs/php-fpm.log

Log level
notice

When this amount of php processes exited with SIGSEGV or SIGBUS …
10

… in a less than this interval of time, a graceful restart will be initiated.
Useful to work around accidental curruptions in accelerator’s shared memory.
1m

Time limit on waiting child’s reaction on signals from master
5s

Set to ‘no’ to debug fpm
yes

Name of pool. Used in logs and stats.
default

Address to accept fastcgi requests on.
Valid syntax is ‘ip.ad.re.ss:port’ or just ‘port’ or ‘/path/to/unix/socket’
127.0.0.1:9000

Set listen(2) backlog
-1

Set permissions for unix socket, if one used.
In Linux read/write permissions must be set in order to allow connections from web server.
Many BSD-derrived systems allow connections regardless of permissions.


0666

Additional php.ini defines, specific to this pool of workers.

/usr/sbin/sendmail -t -i
1

Unix user of processes
www

Unix group of processes
www

Process manager settings

Sets style of controling worker process count.
Valid values are ‘static’ and ‘apache-like’
static

Sets the limit on the number of simultaneous requests that will be served.
Equivalent to Apache MaxClients directive.
Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgi
Used with any pm_style.
128

Settings group for ‘apache-like’ pm style

Sets the number of server processes created on startup.
Used only when ‘apache-like’ pm_style is selected
20

Sets the desired minimum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
5

Sets the desired maximum number of idle server processes.
Used only when ‘apache-like’ pm_style is selected
35

The timeout (in seconds) for serving a single request after which the worker process will be terminated
Should be used when ‘max_execution_time’ ini option does not stop script execution for some reason
’0s’ means ‘off’
0s

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
’0s’ means ‘off’
0s

The log file for slow requests
logs/slow.log

Set open file desc rlimit
65535

Set max core size rlimit
0

Chroot to this directory at the start, absolute path

Chdir to this directory at the start, absolute path

Redirect workers’ stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
yes

How much requests each process should execute before respawn.
Useful to work around memory leaks in 3rd party libraries.
For endless request processing please specify 0
Equivalent to PHP_FCGI_MAX_REQUESTS
102400

Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.
Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+)
Makes sense only with AF_INET listening socket.
127.0.0.1

Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment

$HOSTNAME
/usr/local/bin:/usr/bin:/bin
/tmp
/tmp
/tmp
$OSTYPE
$MACHTYPE
2

9、启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程)
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
注:/usr/local/webserver/php/sbin/php-fpm还有其他参数,包 括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件 使用reload。

三、安装Nginx 0.8.53
1、安装Nginx所需的pcre库:
tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
cd ..
2、安装Nginx
tar zxvf nginx-0.8.53.tar.gz
cd nginx-0.8.53/
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module
make && make install
cd ..

3、创建Nginx日志目录
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www:www /var/log/nginx

4、创建Nginx配置文件
1、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

输入以下内容:
user www www;
worker_processes 2;
error_log /var/log/nginx/nginx_error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}

http {
include /usr/local/webserver/nginx/conf/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 /var/log/nginx/access.log main;

sendfile on;
autoindex off;
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}

keepalive_timeout 10;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffers 8 128k;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
#gzip_types text/plain text/html text/css application/x-Javascript text/xml application/xml application/xml+rss text/Javascript;

# Load config files from the /usr/local/webserver/nginx/conf/conf.d directory
include /usr/local/webserver/nginx/conf/conf.d/*.conf;

}

添加虚似主机(注:因本人要使用Magento所以下面有的东西是给Magento写的,这只是个例子)
vim /usr/local/webserver/nginx/conf/conf.d/zozhang.test.conf
写下配置文件
server {
listen 80;
server_name zozhang.test;
#下面这包主要是给没有加www的添加www,由于是本地测试,就不启用了。
#rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
listen 80 default; #default 所的配置文件中,只能定义一个;
server_name zozhang.test; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/webserver/www/test;

location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento’s front handler
expires 30d; ## Assume all files are cachable
}
location /minify/ { ## Needed for Fooman Speedster
rewrite ^/minify/([0-9]+)(/.*/.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
}

## These locations would be hidden by .htaccess normally
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /lib/minify/ { allow all; } ## Deny is applied after rewrites so must specifically allow minify
location /media/downloadable/ { deny all; }
location /pkginfo/ { deny all; }
location /report/config.xml { deny all; }
location /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder
auth_basic “Restricted”; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /usr/local/webserver/nginx/confhtpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files
return 404;
}

location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}

location ~ /.php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*/.php)/ $1 last;
}

location ~ /.php$ { ## Execute PHP scripts
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /usr/local/webserver/nginx/conf/fastcgi_params
}
}

2、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/webserver/nginx/conf/fcgi.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;

5、启动Nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
#启动过程中如果提示:/usr/local/webserver/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory

#解决方法,在/lib中创建一个symbol link到/usr/local/lib/libpcre.so.0
# ln -s /usr/local/lib/libpcre.so.0 /lib

四、配置开机自动启动Nginx + PHP
vi /etc/rc.local

在末尾增加以下内容:
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx

创建Nginx管理脚本(启动、停止、配置、重启)
################################################
#!/bin/bash
# v.0.0.3
# create by jackbillow at 2007.10.15
# redevelop by XGuru at 2010.6.28
# On Ubuntu 10.04
# nginx – This shell script takes care of starting and stopping nginx.
#
# description: nginx [engine x] is light http web/proxy server
# that answers incoming ftp service requests.
###############################################

nginx_path=”/usr/local/webserver/nginx/” #配置nginx安装路径
nginx_pid=”/usr/local/webserver/nginx/logs/nginx.pid”
prog=”nginx”

RETVAL=0

start() {
# Start daemons.
if [ -e $nginx_path/conf/nginx.conf ];then
echo -n $”Starting $prog: ”
$nginx_path/sbin/nginx -c $nginx_path/conf/nginx.conf &
RETVAL=$?
[ $RETVAL -eq 0 ] && {
echo Start “$prog” successfully!
}
else
RETVAL=1
fi
return $RETVAL
}
# Stop daemons.
stop() {
echo -n $”Stopping $prog/n”
sudo killall -9 nginx
RETVAL=$?
}
# See how we were called.

conf(){
vim “$nginx_path/conf/nginx.conf” #这里请设置要使用什么方式打开配置文件,我使用的是vim
}
case “$1″ in
start)
start
;;
stop)
stop
;;
conf)
conf
;;
restart)
stop
start
;;
*)
echo $”Usage: $0 {start|stop|conf|restart}”
echo $”Your may need root privilege to execute this script!”
exit 1
esac
exit $RETVAL

六、在不停止Nginx服务的情况下平滑变更Nginx配置
1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t

如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully

2、这时,输入以下命令查看Nginx主进程号:
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’

屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302

或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`

七、编写每天定时切割Nginx日志的脚本
1、创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

输入以下内容:

#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path=”/usr/local/webserver/nginx/logs/”

mkdir -p ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/
mv ${logs_path}access.log ${logs_path}$(date -d “yesterday” +”%Y”)/$(date -d “yesterday” +”%m”)/access_$(date -d “yesterday” +”%Y%m%d”).log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`

2、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e

输入以下内容:

00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

当你幸福的时候,我不在,当我幸福的时候,你也不在

推荐阅读
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • mac php错误日志配置方法及错误级别修改
    本文介绍了在mac环境下配置php错误日志的方法,包括修改php.ini文件和httpd.conf文件的操作步骤。同时还介绍了如何修改错误级别,以及相应的错误级别参考链接。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • 本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。 ... [详细]
  • 本文介绍了在Hibernate配置lazy=false时无法加载数据的问题,通过采用OpenSessionInView模式和修改数据库服务器版本解决了该问题。详细描述了问题的出现和解决过程,包括运行环境和数据库的配置信息。 ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • 本文介绍了5个基本Linux命令行工具的现代化替代品,包括du、top和ncdu。这些替代品在功能上进行了改进,提高了可用性,并且适用于现代化系统。其中,ncdu是du的替代品,它提供了与du类似的结果,但在一个基于curses的交互式界面中,重点关注占用磁盘空间较多的目录。 ... [详细]
  • Python项目实战10.2:MySQL读写分离性能优化
    本文介绍了在Python项目实战中进行MySQL读写分离的性能优化,包括主从同步的配置和Django实现,以及在两台centos 7系统上安装和配置MySQL的步骤。同时还介绍了创建从数据库的用户和权限的方法。摘要长度为176字。 ... [详细]
  • 如何使用PLEX播放组播、抓取信号源以及设置路由器
    本文介绍了如何使用PLEX播放组播、抓取信号源以及设置路由器。通过使用xTeve软件和M3U源,用户可以在PLEX上实现直播功能,并且可以自动匹配EPG信息和定时录制节目。同时,本文还提供了从华为itv盒子提取组播地址的方法以及如何在ASUS固件路由器上设置IPTV。在使用PLEX之前,建议先使用VLC测试是否可以正常播放UDPXY转发的iptv流。最后,本文还介绍了docker版xTeve的设置方法。 ... [详细]
  • Linux下部署Symfoy2对app/cache和app/logs目录的权限设置,symfoy2logs
    php教程|php手册xml文件php教程-php手册Linux下部署Symfoy2对appcache和applogs目录的权限设置,symfoy2logs黑色记事本源码,vsco ... [详细]
  • 像跟踪分布式服务调用那样跟踪Go函数调用链 | Gopher Daily (2020.12.07) ʕ◔ϖ◔ʔ
    每日一谚:“Acacheisjustamemoryleakyouhaven’tmetyet.”—Mr.RogersGo技术专栏“改善Go语⾔编程质量的50个有效实践” ... [详细]
  • systemd-nspawn可以创建最轻量级的容器(ns的意思就是namespace),本文的实验平台是Ubuntu16.04,x86_64机器。本文的目的是:在Ubuntu中用syst ... [详细]
  • 本文主要介绍关于linux文件描述符设置,centos7设置文件句柄数,centos7查看进程数的知识点,对【Linux之进程数和句柄数】和【linux句柄数含义】有兴趣的朋友可以看下由【东城绝神】投 ... [详细]
author-avatar
廖劫讲
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有