首页 数据库 mysql教程 ubuntu编译安装php5 mysql nginx_MySQL

ubuntu编译安装php5 mysql nginx_MySQL

Jun 01, 2016 pm 01:17 PM
ubuntu 下载软件

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

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

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

ubuntu终端打不开怎么办? 修复Ubuntu无法打开终端问题的方法 ubuntu终端打不开怎么办? 修复Ubuntu无法打开终端问题的方法 Feb 29, 2024 pm 05:30 PM

如今,Ubuntu不允许其用户打开终端是一个非常普遍的问题。如果您收到类似的问题并且不知道下一步该怎么做,请了解有关如何在Linux设备上解决此“Ubuntu无法打开终端”问题的五个修复程序。事不宜迟,让我们深入探讨导致它的原因及其可用的解决方案。为什么Ubuntu打不开它上面的终端?这主要发生在您安装一些有缺陷的软件或修改终端配置时。除此之外,与语言环境交互并破坏它们的新应用程序或游戏也可能导致类似的问题。一些用户在Ubuntu的活动菜单中搜索终端时报告修复了这个问题。这表明这个

如何取消Ubuntu 18.04文件夹右下角的锁定图标? 如何取消Ubuntu 18.04文件夹右下角的锁定图标? Jan 12, 2024 pm 11:18 PM

ubuntu系统经常遇到有的文件夹顶面有个锁的形状,这个文件常常是无法进行编辑或者移动,这是因为对这个文件没有可以编辑等的权限,所以我们要修改它的权限,就能去掉右下角的锁,该怎么操作呢?下面我们就来看看详细的教程。1、在上锁的文件夹上右键--属性。2、选择窗口中的权限选项。3、把里面都选择为创建和删除文件。4、接着选择底部的更改包含文件的权限,里面同样都设置为创建和删除文件,最后记得点击右上角的更改。5、如果还是没有去掉上面的锁,或者当面的选项出现灰色无法操作,可以在里面右键--打开终端。6、使

如何在Ubuntu开始菜单中移除图标? 如何在Ubuntu开始菜单中移除图标? Jan 13, 2024 am 10:45 AM

ubuntu系统开始菜单里面列出了好多的软件图标,有很多不常用的图标,想要删除,该怎么删除呢?下面我们就来看看详细的教程。1、首先进入ubuntu桌面,点击左边面板下面的开始菜单。2、里面可以找到一个文本编辑器图标,我们要把它删除了。3、现在我们回到桌面直接鼠标右键打开终端。4、使用命令打开应用列表目录。sudonautilus/usr/share/applicationssudonautilus~/.local/share/applications5、在里面找到对应的文本编辑器图标。6、接着直

以超级用户身份登录Ubuntu 以超级用户身份登录Ubuntu Mar 20, 2024 am 10:55 AM

在Ubuntu系统中,root用户通常是禁用状态的。要激活root用户,可以使用passwd命令设置密码,然后使用su-命令以root身份登录。根用户是具有系统管理权限且不受限制的用户。他拥有访问和修改文件、用户管理、软件安装和删除,以及系统配置更改等权限。根用户与普通用户有着明显的区别,根用户拥有系统中最高的权限和更广泛的控制权。根用户可以执行重要的系统命令和编辑系统文件,而普通用户则无法做到这一点。在本指南中,我将探讨Ubuntu根用户,如何以根用户身份登录,以及它与普通用户的不同之处。注意

Ubuntu 24.04 LTS 七大亮点抢先看 Ubuntu 24.04 LTS 七大亮点抢先看 Feb 27, 2024 am 11:22 AM

Ubuntu24.04LTS,代号「NobleNumbat」即将发布!如果你正在使用的是Ubuntu23.10这类非LTS版本,迟早需要考虑升级。对于那些使用Ubuntu20.04LTS或Ubuntu22.04LTS的用户,是否升级值得深思。Canonical已经宣布,Ubuntu24.04LTS将提供长达12年的更新支持,细分如下:作为LTS版本,它会有5年的常规维护和安全更新。如果订阅UbuntuPro,还能享受额外5年的支持。目前,这个额外的支持期限已经延长至7年,这意味着你将获得长达12

ubuntu 20.04录屏软件OBS安装和卸载图文教程 ubuntu 20.04录屏软件OBS安装和卸载图文教程 Feb 29, 2024 pm 04:01 PM

OBS是由世界各地的志愿贡献者在空闲时间开发的开源软件。一款视频直播录制软件,主要用于视频的录制、直播的创流。Ubuntu/Mint的安装请注意,OBSStudio在ChromeOS上不能完全工作,屏幕和窗口捕捉等功能不能使用。建议使用xserver-xorg1.18.4或更新的版本,以避免OBS中某些功能的潜在性能问题,如全屏投影仪。FFmpeg是必需的如果你没有安装FFmpeg(如果你不确定,那么你可能没有),你可以用以下命令得到它:sudoaptinstallffmpeg我这里已经安装有了

Ubuntu 最终支持禁用 snap 软件包的自动更新 Ubuntu 最终支持禁用 snap 软件包的自动更新 Jan 13, 2024 am 10:09 AM

snap是Canonical为使用Linux内核和systemdinit系统的操作系统开发的软件打包和部署系统。这些被称为snap的软件包和使用它们的工具snapd可以在一系列的Linux发行版中使用,并允许上游软件开发者直接向用户发布他们的应用程序。借助snap,用户可以轻松地安装Linux应用程序,在默认情况下,snapd一天内会检查四次更新,并自动将snap应用更新到最新的版本。虽然有很多方法可以控制更新的安装时间和频率,但为了安全用户无法完全关闭自动更新。虽然snap的初衷很好,但很多开

如何在Ubuntu系统中禁用全局菜单? 如何在Ubuntu系统中禁用全局菜单? Jan 11, 2024 pm 04:33 PM

Ubuntu11.04起,添加了一个新功能,称为全局菜单,它是所有应用程序共享的常用菜单栏(如上所示)。我们大多数人已被使用到具有自己的菜单栏的每个应用程序窗口。Unity桌面顶部面板上提供全局菜单,无论应用程序窗口在哪里。如果您的屏幕的右下角的应用程序窗口大小调整为小,则该应用程序的菜单栏仍在顶部面板上。如果不习惯,这可能会令人困惑和不舒服。本经验主要参照《Linux就该这么学》,如果您不喜欢新的全局菜单,并希望将菜单栏移回各个应用程序窗口,我们将向您展示如何禁用全局菜单。1、按Ctrl+Al

See all articles