ubuntu停源碼方式安裝php5.4.13並且配置nginx

來源:互聯網
上載者:User
ubuntu下源碼方式安裝php5.4.13並且配置nginx

ubuntu11.04版本,以下步驟是本人在前兩天安裝的基礎上,又在純新的ubuntu下安裝一遍

步驟都是順序操作的,希望朋友按照順序來操作,以免要回過頭來反覆操作,希望能為您節省時間

?

一、安裝前準備

下載php-5.4.13.tar.gz最新版本放到/user/src目錄下

?

二、安裝

??? 因為在安裝php過程中,會依賴安裝很多庫,為了不讓你反覆安裝,建議按步驟操作

??? 安裝autoconf工具

apt-get install autoconf

??? 安裝libxml2庫

apt-get install libxml2-dev 

??? 安裝libbz2-dev

apt-get install libbz2-dev

??? 安裝curl

apt-get install libcurl4-gnutls-dev

??? 安裝jpeglib

apt-get install libjpeg-dev

??? 安裝png

apt-get install libpng-dev

? ? 安裝libxpm-dev

apt-get install libxpm-dev 

??? 安裝freetype

apt-get install libfreetype6-dev

??? 安裝libt1

apt-get install libt1-dev

??? 安裝mcrypt

apt-get install libmcrypt-dev

??? 安裝xslt

apt-get install libxslt1-dev

???

??? 按照上面的步驟安裝將會為您節省至少20分鐘的時間,甚至更多;如果還有錯誤,則根據提示安裝庫

??? 最後執行安裝命令,當前在解壓好的php原檔案包/usr/src/php-5.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

安裝成功!!

?

三、配置php

??? 將php安裝目錄加到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

??? 當前會員也加到PATH中

export PATH="$PATH:/usr/local/php/bin:/usr/local/php/sbin"

??? 準備php的記錄檔目錄

mkdir /var/log/php-fpm   chown -R www:www /var/log/php-fpm

??? 準備php的設定檔

cd /usr/src/php-5.4.13cp -f php.ini-production /usr/local/php/etc/php.inichmod?644?/usr/local/php/etc/php.inicp?/usr/local/php/etc/php-fpm.conf.default?/usr/local/php/etc/php-fpm.conf 

注意: PHP的設定檔在/usr/local/php/etc/php.ini,

???????? php-fpm的設定檔在/usr/local/php/etc/php-fpm.conf.

?

??? 設定php-fpm啟動管理檔案,並讓PHP在ubuntu啟動時自動運行

cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpmupdate-rc.d -f php-fpm defaults

??? 設定PHP的自動日誌分割和壓縮

vi /etc/logrotate.d/php-fpm輸入一下內容:/var/log/php-fpm/*.log {weeklymissingokrotate 52compressdelaycompressnotifemptycreate 640 www wwwsharedscriptspostrotate[ ! -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
listen.group = www
listen.mode = 0666
user = www
group = www
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 /usr/local/nginx/conf/nginx.conf

? ? 內容如下

user www;
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 /var/log/nginx/access.log access;
}
}

??? 儲存退出,重啟fpm和nginx

/etc/init.d/php-fpm restart /etc/init.d/nginx restart

??? 安裝完成!!!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.