日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

ubuntu编译安装php5 mysql nginx

發(fā)布時(shí)間:2025/4/16 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ubuntu编译安装php5 mysql nginx 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、首先下載軟件源碼包
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中途出錯(cuò)的話, 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 ..

#如果編譯過程中出現(xiàn)如下錯(cuò)誤
#checking for tgetent in -ltermcap… no
#checking for termcap functions library… configure: error: No curses/termcap library found
#說明 curses/termcap 庫沒有安裝去下載一個(gè)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進(jìn)行安裝。
#如果又遇到如下錯(cuò)誤:
make[2]: *** [do_abi_check] 錯(cuò)誤 1
make[2]: Leaving directory `/tmp/mysql-5.5.3-m3′
make[1]: *** [abi_check] 錯(cuò)誤 2
make[1]: Leaving directory `/tmp/mysql-5.5.3-m3′
make: *** [all-recursive] 錯(cuò)誤 1
#在網(wǎng)上搜了一下,說是Mysql的一個(gè)Bug,解決方法是打開Makefile將do_abi_check:后面的語句刪除,注意do_abi_check:需要留下來,然后再 make && make install

附:以下為附加步驟,如果你想在這臺(tái)服務(wù)器上運(yùn)行MySQL數(shù)據(jù)庫,則執(zhí)行以下兩步。如果你只是希望讓PHP支持MySQL擴(kuò)展庫,能夠連接其他服務(wù)器上的MySQL數(shù)據(jù)庫,那么,以下兩步無需執(zhí)行。
1)、創(chuàng)建MySQL數(shù)據(jù)庫存放目錄
mkdir -p /var/webserver/mysql/3306/data
chown -R mysql:mysql /var/webserver/mysql/3306

2)、以mysql用戶帳號(hào)的身份建立數(shù)據(jù)表:
/usr/local/webserver/mysql/bin/mysql_install_db –basedir=/usr/local/webserver/mysql –datadir=/var/webserver/mysql/3306/data –user=mysql

3)、創(chuàng)建my.cnf配置文件:
vim /var/webserver/mysql/3306/my.cnf
輸入以下內(nèi)容:
[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 ?#如果啟動(dòng)不了Mysql把它改為1024或者增大swap分區(qū)的大小
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)、創(chuàng)建管理MySQL數(shù)據(jù)庫的shell腳本:
vim /etc/init.d/mysql
輸入以下內(nèi)容:
#!/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)、添加執(zhí)行權(quán)限
sudo chmod +x /etc/init.d/mysql

6)、添加mysql服務(wù)(ubuntu),并啟動(dòng)服務(wù)添加自定義shell命令
#添加mysql服務(wù)
sudo update-rc.d mysql defaults 100

#啟動(dòng)mysql服務(wù)
service mysql start

#添加自寫義shell命令,方便進(jìn)入mysql
sudo vim ~/.bashrc
#在最后一行加入以下內(nèi)容
mysql () {
/usr/local/webserver/mysql/bin/mysqlr
}

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

7)、登陸mysql以上添加好之后,直接輸入mysql就可以登陸進(jìn)去了

8)、輸入以下SQL語句,創(chuàng)建一個(gè)具有root權(quán)限的用戶
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

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

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

| ? ? ? ? ? ? ? ? ? ? ? *** 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到環(huán)境變量,方法為編輯/etc/profile文 件,添 加:export LD_LIBRARY_PATH=/usr/local/webserver/mysql/lib/mysql
#如果不想重啟使用 . /etc/profile 就可以了,注意.和/etc中間有空格,然后再重新編譯

make ZEND_EXTRA_LIBS=’-liconv’
make install

#復(fù)制配置好的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擴(kuò)展模塊
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 ..

#如果出現(xiàn):
#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

#因?yàn)閍utoconf 依賴于m4,所以會(huì)自動(dòng)下載解決這個(gè)依賴關(guān)系.

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 ..

#如果執(zhí)行make時(shí)出錯(cuò),信息提示如下:
#/usr/bin/ld: cannot find -lperl
#collect2: ld returned 1 exit status
#make[2]: *** [blib/arch/auto/Image/Magick/Magick.so] 錯(cuò)誤 1
#make[2]:正在離開目錄 `/home/ouyangjunqiu/下載/ImageMagick-6.5.1-2/PerlMagick’
#make[1]: *** [all-perl] 錯(cuò)誤 2
#make[1]:正在離開目錄 `/home/ouyangjunqiu/下載/ImageMagick-6.5.1-2′
#make: *** [all] 錯(cuò)誤 2
#有兩種解決方法
#1.在配置的時(shí)候加個(gè)。。
#./configure –without-perl
#2.安裝庫文件
#apt-get install libperl-dev
#安裝完成后驗(yàn)證一下是否能正常工作輸入convert -version 如果出現(xiàn)如下錯(cuò)誤:
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的圖片轉(zhuǎn)換為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、創(chuàng)建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、創(chuàng)建php-fpm配置文件(php-fpm是為PHP打的一個(gè)FastCGI管理補(bǔ)丁,可以平滑變更php.ini配置而無需重啟php-cgi):
在/usr/local/webserver/php/etc/目錄中創(chuàng)建php-fpm.conf文件:
rm -rf /usr/local/webserver/php/etc/php-fpm.conf
vi /usr/local/webserver/php/etc/php-fpm.conf
輸入以下內(nèi)容(如果您安裝 Nginx + PHP 用于程序調(diào)試,請(qǐng)將以下的<value name=”display_errors”>0</value>改為<value name=”display_errors”>1</value>,以便顯示PHP錯(cuò)誤信息,否則,Nginx 會(huì)報(bào)狀態(tài)為500的空白錯(cuò)誤頁):

<?xml version=”1.0″ ?>
<configuration>

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

<section name=”global_options”>

Pid file
<value name=”pid_file”>/usr/local/webserver/php/logs/php-fpm.pid</value>

Error log file
<value name=”error_log”>/usr/local/webserver/php/logs/php-fpm.log</value>

Log level
<value name=”log_level”>notice</value>

When this amount of php processes exited with SIGSEGV or SIGBUS …
<value name=”emergency_restart_threshold”>10</value>

… 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.
<value name=”emergency_restart_interval”>1m</value>

Time limit on waiting child’s reaction on signals from master
<value name=”process_control_timeout”>5s</value>

Set to ‘no’ to debug fpm
<value name=”daemonize”>yes</value>

</section>

<workers>

<section name=”pool”>

Name of pool. Used in logs and stats.
<value name=”name”>default</value>

Address to accept fastcgi requests on.
Valid syntax is ‘ip.ad.re.ss:port’ or just ‘port’ or ‘/path/to/unix/socket’
<value name=”listen_address”>127.0.0.1:9000</value>

<value name=”listen_options”>

Set listen(2) backlog
<value name=”backlog”>-1</value>

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.
<value name=”owner”></value>
<value name=”group”></value>
<value name=”mode”>0666</value>
</value>

Additional php.ini defines, specific to this pool of workers.
<value name=”php_defines”>
<value name=”sendmail_path”>/usr/sbin/sendmail -t -i</value>
<value name=”display_errors”>1</value>
</value>

Unix user of processes
<value name=”user”>www</value>

Unix group of processes
<value name=”group”>www</value>

Process manager settings
<value name=”pm”>

Sets style of controling worker process count.
Valid values are ‘static’ and ‘a(chǎn)pache-like’
<value name=”style”>static</value>

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.
<value name=”max_children”>128</value>

Settings group for ‘a(chǎn)pache-like’ pm style
<value name=”apache_like”>

Sets the number of server processes created on startup.
Used only when ‘a(chǎn)pache-like’ pm_style is selected
<value name=”StartServers”>20</value>

Sets the desired minimum number of idle server processes.
Used only when ‘a(chǎn)pache-like’ pm_style is selected
<value name=”MinSpareServers”>5</value>

Sets the desired maximum number of idle server processes.
Used only when ‘a(chǎn)pache-like’ pm_style is selected
<value name=”MaxSpareServers”>35</value>

</value>

</value>

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’
<value name=”request_terminate_timeout”>0s</value>

The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file
’0s’ means ‘off’
<value name=”request_slowlog_timeout”>0s</value>

The log file for slow requests
<value name=”slowlog”>logs/slow.log</value>

Set open file desc rlimit
<value name=”rlimit_files”>65535</value>

Set max core size rlimit
<value name=”rlimit_core”>0</value>

Chroot to this directory at the start, absolute path
<value name=”chroot”></value>

Chdir to this directory at the start, absolute path
<value name=”chdir”></value>

Redirect workers’ stdout and stderr into main error log.
If not set, they will be redirected to /dev/null, according to FastCGI specs
<value name=”catch_workers_output”>yes</value>

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
<value name=”max_requests”>102400</value>

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.
<value name=”allowed_clients”>127.0.0.1</value>

Pass environment variables like LD_LIBRARY_PATH
All $VARIABLEs are taken from current environment
<value name=”environment”>
<value name=”HOSTNAME”>$HOSTNAME</value>
<value name=”PATH”>/usr/local/bin:/usr/bin:/bin</value>
<value name=”TMP”>/tmp</value>
<value name=”TMPDIR”>/tmp</value>
<value name=”TEMP”>/tmp</value>
<value name=”O(jiān)STYPE”>$OSTYPE</value>
<value name=”MACHTYPE”>$MACHTYPE</value>
<value name=”MALLOC_CHECK_”>2</value>
</value>

</section>

</workers>

</configuration>

9、啟動(dòng)php-cgi進(jìn)程,監(jiān)聽127.0.0.1的9000端口,進(jìn)程數(shù)為200(如果服務(wù)器內(nèi)存小于3GB,可以只開啟64個(gè)進(jìn)程)
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
注:/usr/local/webserver/php/sbin/php-fpm還有其他參數(shù),包 括: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、創(chuàng)建Nginx日志目錄
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www:www /var/log/nginx

4、創(chuàng)建Nginx配置文件
1、在/usr/local/webserver/nginx/conf/目錄中創(chuàng)建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf

輸入以下內(nèi)容:
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;

}

添加虛似主機(jī)(注:因本人要使用Magento所以下面有的東西是給Magento寫的,這只是個(gè)例子)
vim /usr/local/webserver/nginx/conf/conf.d/zozhang.test.conf
寫下配置文件
server {
listen 80;
server_name zozhang.test;
#下面這包主要是給沒有加www的添加www,由于是本地測(cè)試,就不啟用了。
#rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
listen 80 default; #default 所的配置文件中,只能定義一個(gè);
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/目錄中創(chuàng)建fcgi.conf文件:
vi /usr/local/webserver/nginx/conf/fcgi.conf

輸入以下內(nèi)容:

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、啟動(dòng)Nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
#啟動(dòng)過程中如果提示:/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中創(chuàng)建一個(gè)symbol link到/usr/local/lib/libpcre.so.0
# ln -s ?/usr/local/lib/libpcre.so.0 ?/lib

四、配置開機(jī)自動(dòng)啟動(dòng)Nginx + PHP
vi /etc/rc.local

在末尾增加以下內(nèi)容:
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm start
/usr/local/webserver/nginx/sbin/nginx

創(chuàng)建Nginx管理腳本(啟動(dòng)、停止、配置、重啟)
################################################
#!/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” ? #這里請(qǐng)?jiān)O(shè)置要使用什么方式打開配置文件,我使用的是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服務(wù)的情況下平滑變更Nginx配置
1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,請(qǐng)執(zhí)行以下命令檢查配置文件是否正確:
/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、這時(shí),輸入以下命令查看Nginx主進(jìn)程號(hào):
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’

屏幕顯示的即為Nginx主進(jìn)程號(hào),例如:
6302
這時(shí),執(zhí)行以下命令即可使修改過的Nginx配置文件生效:
kill -HUP 6302

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

七、編寫每天定時(shí)切割Nginx日志的腳本
1、創(chuàng)建腳本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh

輸入以下內(nèi)容:

#!/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、設(shè)置crontab,每天凌晨00:00切割nginx訪問日志
crontab -e

輸入以下內(nèi)容:

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

轉(zhuǎn)載于:https://www.cnblogs.com/xiao-yu/archive/2011/05/24/2055968.html

總結(jié)

以上是生活随笔為你收集整理的ubuntu编译安装php5 mysql nginx的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。