php5.4.13在ubuntu12.04上的配置
一、到官網下載最新的php5.4.13.tar.gz
在這裡弱弱的提醒一句---自PHP5.3以後都內建了php-fpm,不需要另行安裝php-fpm,即php-cgi管理程式
二、tar zxvf php5.4.13.tar.gz
三、cd php5.4.13
四、./buildconf --force如果報以下錯誤You need autoconf version 2.59 or higher
??? 則執行先卸載原先的autoconf:
apt-get --purge remove autoconf
?? 然後
apt-get autoremove autoconf
?? 然後直接安裝
apt-get install autoconf
五、開始編譯安裝配置PHP5.4.13
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/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 --enable-pdo --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-gettext --with-fpm-user=www-data --with-fpm-group=www-data --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath -with-bz2 --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-shmop --enable-dba --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-debug --enable-maintainer-zts --enable-embed
?
make && make install
?
當中遇到的錯誤和解決方案如下:
?
1) Configure: error: xml2-config not found. Please check your libxml2 installation.
Solutions :
# aptitude install libxml2-dev
2) Checking for pkg-config… /usr/bin/pkg-config
configure: error: Cannot find OpenSSL’s ?or?
Solutions :
?
sudo apt-get install openssl-dev
?
sudo apt-get install libcurl3-openssl-dev
?
?
?
3) Configure: error: Please reinstall the BZip2 distribution
Solutions :
? apt-get install libbz2-dev
4) Configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/
Solutions :
apt-get install curl
apt-get install libcurl3
apt-get install libcurl4-gnutls-dev(For Ubuntu)
5) Configure: error: libjpeg.(also) not found.
Solutions :
?apt-get install libjpeg-dev
6) Configure: error: libpng.(also) not found.
Solutions :
apt-get install libpng-dev
7) Configure: error: freetype.h not found.
Solutions :
8) Configure: error: Unable to locate gmp.h
Solutions :
yum install gmp-devel
9) Configure: error: Cannot find MySQL header files under /usr.
Note that the MySQL client library is not bundled anymore!
Solutions :
yum install mysql-devel (For Redhat & Fedora)
# apt-get install libmysql++-dev (For Ubuntu)
10) Configure: error: Please reinstall the ncurses distribution
Solutions :
yum install ncurses ncurses-devel
11) Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
Solutions :
yum install unixODBC-devel
12) Configure: error: Cannot find pspell
Solutions :
yum install pspell-devel
13) configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Solutions :
yum install libmcrypt libmcrypt-devel (For Redhat & Fedora)
# apt-get install libmcrypt-dev
14) Configure: error: snmp.h not found. Check your SNMP installation.
Solutions :
?
15)configure: error: libXpm.(a|so)not found.
apt-get install libxpm-dev有可能還會出現這個錯誤,那麼繼續cd /usr/lib/ln -s /usr/lib/x86_64-linux-gnu/libXpm.a .ln -s /usr/lib/x86_64-linux-gnu/libXpm.so .ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4.ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4.11.0.
?
至此php5.4.13應該安裝成功,接下來進行配置
將php5所在的目錄也加到bash的PATH中去:
?
echo 'if [ -d "/usr/local/php/bin" ] && [ -d "/usr/local/php/sbin" ]; then PATH="$PATH:/usr/local/php/bin:/usr/local/php/sbin"fi' >> /etc/bash.bashrc
?當前會話也加上:
export PATH="$PATH:/usr/local/php/bin:/usr/local/php/sbin"
?準備PHP5的記錄檔目錄:
?
mkdir /var/log/php-fpm chown -R www-data:www-data /var/log/php-fpm
?
?
準備PHP的設定檔:
?
cp -f php.ini-production /usr/local/php/etc/php.ini
chmod 644 /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
?
注意: PHP5的設定檔在/usr/local/php/etc/php.ini, php-fpm的設定檔在/usr/local/php/etc/php-fpm.conf.
設定php-fpm啟動管理檔案,並讓PHP在ubuntu啟動時自動運行(下面地sapi是PHP5.4.0安裝包中的):
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
設定PHP的自動日誌分割和壓縮: vi /etc/logrotate.d/php-fpm
加入下面的內容儲存退出:
/var/log/php-fpm/*.log {weeklymissingokrotate 52compressdelaycompressnotifemptycreate 640 www-data www-datasharedscriptspostrotate[ ! -f /usr/local/php /var/run/php-fpm.pid ] || kill -USR1 `cat /usr/local/php/ /var/run/php-fpm.pid`endscript}
?
配置php-fpm和nginx
php-fpm:
vi /usr/local/php/etc/php-fpm.conf
主要是下面的參數需要改下:
- pid = run/php-fpm.pid? //這個必去將前面的;注釋去掉(一開始沒去掉結果出502錯誤)
- error_log = log/php-fpm.log
- log_level = notice
- ;emergency_restart_threshold = 0
- ;emergency_restart_interval = 0
- ;process_control_timeout = 0
- ;daemonize = yes
- [www]
- ;prefix = /path/to/pools/$pool
- listen = 127.0.0.1:9000
- ; listen.backlog = -1
- listen.allowed_clients = 127.0.0.1
- listen.owner = www-data
- listen.group = www-data
- listen.mode = 0666
- user = www-data
- group = www-data
- pm = dynamic
- pm.max_children = 50
- pm.start_servers = 20
- pm.min_spare_servers = 5
- pm.max_spare_servers = 35
- pm.max_requests = 500
?
?
?
?
?
然後配置nginx:vi /etc/nginx/nginx.confuser nginx;worker_processes 2;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { use epoll; worker_connections 1024;}http{ include mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8M; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300s; fastcgi_send_timeout 300s; fastcgi_read_timeout 300s; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; server { listen 80; #/*監聽連接埠*/ server_name localhost; #/*伺服器名稱*/ index index.html index.htm index.php; #/*預設首頁名稱*/ root /var/www; #/*網站根目錄,也可以採用下面內容*/#也可以採用相對路徑,下面注釋部分*/ #location / { # root html; # index index.html index.htm; # } #limit_conn crawler 20; #通過FastCGI方式支援PHP,php頁面由fastcgi代理處理,這也是反向 Proxy的一個應用,這裡可以是jsp/asp等指令碼。 location ~ .*\.(php|php5)?$ { include /etc/nginx/fastcgi_params;#為FastCGI模組設定了基本的環境變數 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name; #include fcgi.conf; #/*fastcgi設定檔,修改為以下內容*/ } #對於某一類型的檔案,設定到期時間,靜態頁面通常設定長一點。 #靜態檔案,nginx自己處理 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } #日誌的格式 log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log access_log /usr/local/ngxin/logs/access.log access; }}然後儲存退出,重啟fpm和nginx /etc/init.d/php-fpm restart /etc/init.d/nginx restart 安裝完成:root@Cyrec-desktop:~# php-fpm -vPHP 5.4.0 (fpm-fcgi) (built: Mar 12 2012 18:13:13) (DEBUG)Copyright (c) 1997-2009 The PHP GroupZend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
一些參考資料:
http://www.cslog.cn/Content/ubuntu-10-04-nginx-0-8-52-php-fpm-5-3-3-apc-mysql-i/
http://www.laruence.com/2009/07/28/1030.html
http://www.frostsky.com/2011/11/php-configure-error/
http://letle.iteye.com/blog/625728
http://kangxiaowei.com/archives/2398.html
http://wenku.baidu.com/view/2ae270e9551810a6f52486ea.html