<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>船長日誌 &#187; php</title>
	<atom:link href="http://www.cslog.cn/tag/php/feed/zh-hant/" rel="self" type="application/rss+xml" />
	<link>http://www.cslog.cn</link>
	<description>最讓我激動的是不知道下一個星球上能發現什麼...</description>
	<lastBuildDate>Wed, 30 Jul 2025 16:06:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Ubuntu 10.04 上安裝Nginx 0.8.52 + PHP-fpm 5.3.3 + APC和MySQL</title>
		<link>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 17:28:19 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[服務器]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=543</guid>
		<description><![CDATA[Ubuntu 10.04 上源碼編譯安裝Nginx 0.8.52 + PHP-f &#8230; <a href="http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 10.04 上源碼編譯安裝Nginx 0.8.52 + PHP-fpm 5.3.3 + APC和MySQL<br />
Ubuntu 是服務器上常用的Linux發行版本. 10.04是最新的LTS版本. Nginx則是佔用內存少, 速度快的網頁server的後起之秀. PHP從5.3.3起, 內置了FPM補丁, 跟nginx的兼容性又上了一個台階. 本文是在Ubuntu 10.04上源碼編譯安裝nginx 0.8.52, PHP-fpm 5.3.3, 加APC PHP加速的操作教程. (最後使用apt-get安裝mysql數據庫).</p>
<p>注意, 整個安裝過程都是使用root帳號.</p>
<p><span id="more-543"></span></p>
<h3>第一步 安裝準備</h3>
<p>更新系統源庫和更新已經安裝過的程序:</p>
<pre>sudo apt-get update
sudo apt-get dist-upgrade</pre>
<p>安裝會用的程序:</p>
<pre>apt-get install htop binutils cpp flex gcc libarchive-zip-perl \
libc6-dev libcompress-zlib-perl m4 libpcre3 libpcre3-dev libssl-dev \
libpopt-dev lynx make perl perl-modules openssl unzip zip \
autoconf2.13 gnu-standards automake libtool bison build-essential \
zlib1g-dev ntp ntpdate autotools-dev g++ bc subversion psmisc \
libmysqlclient-dev libcurl4-openssl-dev libjpeg62-dev libpng3-dev \
libxpm-dev libfreetype6-dev libt1-dev libmcrypt-dev libxslt1-dev \
libbz2-dev libxml2-dev libevent-dev libltdl-dev libmagickwand-dev \
imagemagick</pre>
<p>創建用來臨時放源碼的目錄:</p>
<pre>mkdir ~/src
cd ~/src</pre>
<p>下載nginx和PHP等源碼:</p>
<pre>wget http://nginx.org/download/nginx-0.8.52.tar.gz
wget http://us2.php.net/distributions/php-5.3.3.tar.gz
wget http://download.suhosin.org/suhosin-patch-5.3.3-0.9.10.patch.gz
wget http://download.suhosin.org/suhosin-0.9.32.1.tar.gz
wget http://pecl.php.net/get/imagick-3.0.0.tgz</pre>
<p>解壓縮源碼包:</p>
<pre>tar zxvf nginx-0.8.52.tar.gz
tar xzvf php-5.3.3.tar.gz
tar xzvf suhosin-0.9.32.1.tar.gz
gunzip suhosin-patch-5.3.3-0.9.10.patch.gz
tar xzvf imagick-3.0.0.tgz</pre>
<h3>第二步 安裝nginx 0.8.52</h3>
<p>編譯安裝nginx:</p>
<pre>cd nginx-0.8.52/

./configure \
  --prefix=/opt/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/lock/nginx.lock \
  --http-log-path=/var/log/nginx/access.log \
  --error-log-path=/var/log/nginx/error.log \
  --http-client-body-temp-path=/var/lib/nginx/body \
  --http-proxy-temp-path=/var/lib/nginx/proxy \
  --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
  --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
  --http-scgi-temp-path=/var/lib/nginx/scgi \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --user=www-data \
  --group=www-data \
  --without-mail_pop3_module \
  --without-mail_imap_module \
  --without-mail_smtp_module 

make
make install
cd ..</pre>
<p>注意把nginx安裝到/opt/nginx目錄里了. nginx的配置文件在/etc/nginx/nginx.conf, pid在/var/run/nginx.pid.</p>
<p>在系統PATH里加入nginx的路徑:</p>
<pre>echo 'if [ -d "/opt/nginx/sbin" ]; then
    PATH="$PATH:/opt/nginx/sbin"
fi' &gt;&gt; /etc/bash.bashrc</pre>
<p>當前連接會話也加上:</p>
<pre>export PATH="$PATH:/opt/nginx/sbin"</pre>
<p>添加啟動管理文件並讓ubuntu開機時自動運行nginx網頁服務器, 我把修改好的腳本放到博客上了:</p>
<pre>wget http://www.cslog.cn/wp-content/uploads/2010/10/nginx.gz
gunzip nginx.gz
mv nginx /etc/init.d
chmod +x /etc/init.d/nginx
update-rc.d -f nginx defaults</pre>
<p>自動分割和壓縮nginx日誌分文:</p>
<pre>nano /etc/logrotate.d/nginx</pre>
<p>在裡面加入下面內容:</p>
<pre>/var/log/nginx/*.log {
	weekly
	missingok
	rotate 52
	compress
	delaycompress
	notifempty
	create 640 root adm
	sharedscripts
	postrotate
		[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
	endscript
}</pre>
<p>給nginx新建運行環境目錄:</p>
<pre>mkdir /var/lib/nginx</pre>
<p>到這裡nginx的安裝完成了.</p>
<h3>第三步 安裝PHP</h3>
<p>給php打上suhosin安全補丁:</p>
<pre>cd php-5.3.3
patch -p 1 -i ../suhosin-patch-5.3.3-0.9.10.patch</pre>
<p>開始編譯安裝php 5.3.3</p>
<pre>./buildconf --force

./configure \
	--prefix=/opt/php5 \
	--with-config-file-path=/opt/php5/etc \
	--with-curl \
	--with-pear \
	--with-gd \
	--with-jpeg-dir \
	--with-png-dir \
	--with-zlib \
	--with-xpm-dir \
	--with-freetype-dir \
	--with-t1lib \
	--with-mcrypt \
	--with-mhash \
	--with-mysql \
	--with-mysqli \
	--with-pdo-mysql \
	--with-openssl \
	--with-xmlrpc \
	--with-xsl \
	--with-bz2 \
	--with-gettext \
	--with-fpm-user=www-data \
	--with-fpm-group=www-data \
	--enable-fpm \
	--enable-exif \
	--enable-wddx \
	--enable-zip \
	--enable-bcmath \
	--enable-calendar \
	--enable-ftp \
	--enable-mbstring \
	--enable-soap \
	--enable-sockets \
	--enable-sqlite-utf8 \
	--enable-shmop \
	--enable-dba \
	--enable-sysvmsg \
	--enable-sysvsem \
	--enable-sysvshm

make
make install</pre>
<p>注意, PHP5.3.3自帶了fpm補丁, 不用再打了. PHP安裝到了/opt/php5目錄.</p>
<p>將php5所在的目錄也加到bash的PATH中去:</p>
<pre>echo 'if [ -d "/opt/php5/bin" ] &amp;&amp; [ -d "/opt/php5/sbin" ]; then
    PATH="$PATH:/opt/php5/bin:/opt/php5/sbin"
fi' &gt;&gt; /etc/bash.bashrc</pre>
<p>當前會話也加上:</p>
<pre>export PATH="$PATH:/opt/php5/bin:/opt/php5/sbin"</pre>
<p>準備PHP5的日誌文件目錄:</p>
<pre>mkdir /var/log/php-fpm
chown -R www-data:www-data /var/log/php-fpm</pre>
<p>準備PHP的配置文件:</p>
<pre>cp -f php.ini-production /opt/php5/etc/php.ini
chmod 644 /opt/php5/etc/php.ini
cp /opt/php5/etc/php-fpm.conf.default /opt/php5/etc/php-fpm.conf</pre>
<p>注意: PHP5的配置文件在/opt/php5/etc/php.ini, php-fpm的配置文件在/opt/php5/etc/php-fpm.conf.</p>
<p>修改php-fpm配置文件:</p>
<pre>nano /opt/php5/etc/php-fpm.conf</pre>
<p>另外, 裡面的服務數量請根據自己的機器硬件配置和網站流量做調整設置<br />
如:</p>
<pre>pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 20</pre>
<p>如果將監聽端口設置從</p>
<pre>listen = 127.0.0.1:9000</pre>
<p>換成sock,如</p>
<pre>listen = /var/run/php-fpm.sock</pre>
<p>要做如下操作,保證php-fpm.scok的可讀性</p>
<pre>touch /var/run/php-fpm.sock
chown -R www-data:www-data /var/run/php-fpm.sock</pre>
<p>按ctl+w搜索php_fpm_PID, 將它改的值改成</p>
<pre>php_fpm_PID=/var/run/php-fpm.pid</pre>
<p>設置php-fpm啟動管理文件,並讓PHP在ubuntu啟動時自動運行:</p>
<pre>cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
update-rc.d -f php-fpm defaults</pre>
<p>修改php-fpm啟動管理文件:</p>
<pre>nano /etc/init.d/php-fpm</pre>
<p>將裡面php_fpm_PID的值也改成/var/run/php-fpm.pid:</p>
<pre>php_fpm_PID=/var/run/php-fpm.pid</pre>
<p>設置PHP的自動日誌分割和壓縮:</p>
<pre>nano /etc/logrotate.d/php-fpm</pre>
<p>加入:</p>
<pre>/var/log/php-fpm/*.log {
	weekly
	missingok
	rotate 52
	compress
	delaycompress
	notifempty
	create 640 www-data www-data
	sharedscripts
	postrotate
		[ ! -f /var/run/php-fpm.pid ] || kill -USR1 `cat /var/run/php-fpm.pid`
	endscript
}</pre>
<p>給php安裝APC加速器:</p>
<pre>pecl install APC-3.1.4</pre>
<p>和安全補丁</p>
<pre>cd ../suhosin-0.9.32.1
/opt/php5/bin/phpize
./configure --enable-suhosin
make
make test
make install</pre>
<p>給PHP安裝imagick圖像處理模塊:</p>
<pre>cd ../imagick-3.0.0
/opt/php5/bin/phpize
./configure --with-imagick
make
make test
make install</pre>
<p>向php.ini配置文件第920行下面添加新模塊信息:</p>
<pre>nano +920 /opt/php5/etc/php.ini</pre>
<p>插入:</p>
<pre>extension = suhosin.so
extension = imagick.so
extension = apc.so
apc.enabled = 1
apc.shm_size = 128M
apc.shm_segments=1
apc.write_lock = 1
apc.rfc1867 = On
apc.ttl=7200
apc.user_ttl=7200
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.enable_cli=1
;# Optional, for "[apc-warning] Potential cache slam averted for key... errors"
;apc.slam_defense = Off</pre>
<p>注意, 在修改時可以順便將時區設置成中國時區:<br />
找到<br />
[Date] 部分<br />
加入:</p>
<pre>date.timezone = Asia/Chongqing</pre>
<h3>第四步 安裝MySQL數據庫</h3>
<p>為方便省事, 使用apt-get安裝MySQL</p>
<pre>sudo apt-get install mysql-server</pre>
<p>將mysql的默認字符編碼改成utf-8,以便更好的支持中文字符:<br />
打開mysql配置文件:</p>
<pre>nano /etc/mysql/my.cnf</pre>
<p>找到[client] 添加:</p>
<pre>default-character-set=utf8</pre>
<p>找到[mysqld] 添加:</p>
<pre>default-character-set=utf8
#設定連接mysql數據庫時使用utf8編碼，以讓mysql數據庫為utf8運行
init_connect='SET NAMES utf8'</pre>
<p>重啟mysql服務：</p>
<pre>/usr/bin/mysqld_safe --user=mysql &amp;</pre>
<p>到這裡, ubuntu 10.04上nginx, php-fpm+apc和mysql的安裝全部完成了.</p>
<h3>免費附送</h3>
<p>php的啟動方法</p>
<pre>/etc/init.d/php-fpm start</pre>
<p>重啟</p>
<pre>/etc/init.d/php-fpm restart</pre>
<p>nginx的啟動方法:</p>
<pre>/etc/init.d/nginx start</pre>
<p>不間斷nginx的重新裝載新配置文件的方法:</p>
<pre>nginx -s reload</pre>
<p>重啟前最好先測試一下新配置文件</p>
<pre>nginx -t</pre>
<p>好了, 希望你的安裝順利. 遇到什麼問題可以留言.</p>
<p>參考文章 : <a href="http://vladgh.com/blog/install-nginx-and-php-533-php-fpm-mysql-and-apc">http://vladgh.com/blog/install-nginx-and-php-533-php-fpm-mysql-and-apc</a>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/">http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/feed/zh-hant/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>mysqlnd cannot connect to MySQL 4.1+ using old authentication</title>
		<link>http://www.cslog.cn/Content/mysqlnd-cannot-connect/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/mysqlnd-cannot-connect/zh-hant/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 09:04:44 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[用PHP5.3.2安裝UCenter時遇到 mysqlnd cannot con &#8230; <a href="http://www.cslog.cn/Content/mysqlnd-cannot-connect/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>用PHP5.3.2安裝UCenter時遇到 mysqlnd cannot connect to MySQL 4.1+ using old authentication 錯誤. 類似的錯誤在安裝mediawiki時也遇到過.</p>
<p>這是由於mysql數據庫還使用舊的驗證方式的結果. 解決方法其實很簡單, 重新設置一下用戶密碼就可以了:</p>
<pre><code>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('新密碼');<br /></code></pre>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/mysqlnd-cannot-connect/zh-hant/">http://www.cslog.cn/Content/mysqlnd-cannot-connect/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/mysqlnd-cannot-connect/feed/zh-hant/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在leopard上安裝php</title>
		<link>http://www.cslog.cn/Content/leopard-php/zh-hant/</link>
		<comments>http://www.cslog.cn/Content/leopard-php/zh-hant/#comments</comments>
		<pubDate>Tue, 05 May 2009 23:46:22 +0000</pubDate>
		<dc:creator>船長</dc:creator>
				<category><![CDATA[信息處理]]></category>
		<category><![CDATA[站長文檔]]></category>
		<category><![CDATA[leopard]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[怎樣在蘋果leopard上安裝php語言環境? 其實不用安裝. 因為leopar &#8230; <a href="http://www.cslog.cn/Content/leopard-php/zh-hant/">繼續閱讀 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>怎樣在蘋果leopard上安裝php語言環境? 其實不用安裝. 因為leopard已經默認安裝了php5. 但默認設置下apache沒有裝載php組件, 所在不能使用. 要使用php時, 要先將它啟動, 方法如下:<br />
1.打開 /etc/apache2/httpd.conf 文件<br />
2.找到<br />
<typo:code><br />
#LoadModule php5_module libexec/apache2/libphp5.so<br />
</typo:code><br />
將前面的註解符#去除, 變成<br />
<typo:code><br />
LoadModule php5_module libexec/apache2/libphp5.so<br />
</typo:code><br />
保存文件<br />
3.重啟apache<br />
<typo:code><br />
sudo apachectl restart<br />
</typo:code><br />
現在可以在leopard上使用php5了.</p>
<p>附:</p>
<p>apache的默認根目錄:<br />
/Library/WebServer/Documents/<br />
可以在 /etc/apache2/httpd.conf 文件中修改.</p>
<p>用來顯示php環境的語句:<br />
<typo:code><br />
&lt;?php phpinfo(); ?&gt;<br />
</typo:code><br />
<br />
php.ini文件:<br />
/etc 目錄下有一個php.ini.default文件. 複製並改名為php.ini文件:<br />
<typo:code><br />
sudo cp /etc/php.ini.default /etc/php.ini<br />
</typo:code><br />
(修改後重啟apache才能生效)</p>
<p>在php.ini文件中找到<br />
mysql.default_socket =<br />
可以修改mysql socket位置, 如:<br />
<typo:code><br />
mysql.default_socket = /tmp/mysql.sock<br />
</typo:code>
<div style="margin-top: 15px; font-style: italic">
<p>轉載請註明: 轉自<a href="http://www.cslog.cn/">船長日誌</a>, 本文鏈接地址: <a href="http://www.cslog.cn/Content/leopard-php/zh-hant/">http://www.cslog.cn/Content/leopard-php/zh-hant/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/leopard-php/feed/zh-hant/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- WP Chinese Conversion Full Page Converted -->