首頁 資料庫 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脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++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