1.從php網址下載相應的版本
因為php下載頁面只有最近的幾個版本,下載比較老的版本在下載頁面已經找不到了,只能手動通過下面的url來下載,
http://cn.php.net/distributions/php-5.3.9.tar.bz2,此頁面里會列出一些老的版本,此處使用的是5.3版本,下載的是gz格式的
2.安裝php
將tar包解壓,進入解壓包目錄-執行命令:./configure --prefix=/opt/local/php ,“/opt/local/php”是安裝路徑,可以改成自己希望的安裝路徑。
(1)此處可能會提示缺少一些必須的插件,此時利用yum命令進行安裝,比如最可能報的錯誤:configure error xml2-config not found. please check your libxml2 installation,此時執行命令:yum -y install libxml2 libxml2-devel,安裝相應插件,以此類推
所有插件安裝完成后,再次執行
./configure --prefix=/opt/local/php
(2)此處如果是要安裝php-fpm的功能的話需要yum安裝更多插件,例如:
yum -y install openssl openssl-devel bzip2 bzip2-devel curl curl-devel readline-devel fcgi php-mcrypt libmcrypt libmcrypt-devel
其中安裝php-mcrypt libmcrypt libmcrypt-devel時可能會提示找不到包,這時要通過更新源解決,具體命令如下:
yum -y install epel-release
yum update
其中,update執行了兩次才成功,之后再執行configure
./configure --prefix=/opt/local/php5.3.29 --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear
通過后執行make
此時可能會出現以下提示
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
此處可暫進忽略,等之后再行安裝,再次在php目錄執行make all install
如果安裝了php-fpm,則還需要執行以下命令,將php/etc目錄下的配置文件拷貝一份
cp etc/php-fpm.conf.default etc/php-fpm.conf
將php/lib/php.ini拷貝到/etc/下
3.初裝phar
這時可以執行
wget http://pear.php.net/go-pear.phar
之后再執行
/opt/local/php/bin/php /opt/local/go-pear.phar
在出現的提示后,選1,選擇phar安裝目錄,然后一路回車進行安裝即可
最后制作php軟鏈,讓php全局可用
ln -s /opt/local/php/bin/php /usr/bin/php
4.驗證
執行php -v和sbin/php-fpm -v查看php版本以驗證php是否已安裝
5.啟動php-fpm
php/sbin/php-fpm
INT, TERM 立刻終止
QUIT 平滑終止
USR1 重新打開日志文件
USR2 平滑重載所有worker進程并重新載入配置和二進制模塊
示例:
php-fpm 關閉:
kill -INT `cat /opt/local/php/var/run/php-fpm.pid`
php-fpm 重啟:
kill -USR2 `cat /opt/local/php/var/run/php-fpm.pid`
如果找不到php-fpm.pid文件,可通過查找php-fpm進程號進行重啟和關閉
例如
[root@SH-DEV local]# ps -aux|grep php-fpm
root 141735 0.0 0.0 201840 3892 ?
Ss 16:27 0:00 php-fpm: master process (/opt/local/php5.3.29/etc/php-fpm.conf)
kill -USR2 141735
6.修改php-fpm配置
(1)如果在nginx.conf中使用了fastcgi_pass unix:/tmp/php-cgi.sock,則需要修改php-fpm.conf,找到如下碼段:
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This html' target='_blank'>value is mandatory.
;listen = 127.0.0.1:9000
listen = /tmp/php-cgi.sock
; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
;listen.backlog = -1
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nobody
listen.group = nobody
listen.mode = 0660
將原listen和listen.owner,listen.group段做如上修改,其中listen.owner,listen.group為nginx啟動用戶名,如此處不修改,會提示
nginx error connect to php-fpm.sock failed (13: Permission denied)
當然此處如果將sock放在內存中/dev/shm/php-fpm.sock會更快
(2)修改php-fpm線程數
; Per pool prefix
; It only applies on the following directives:
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic
#如何控制子進程,選項有static和dynamic。如果選擇static,則由pm.max_children指定固定的子進程數。如果選擇dynamic,則由下面的參數決定
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 8
#子進程最大數
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 8
#啟動時的進程數
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1
#保證空閑進程數最小值,如果空閑進程小于此值,則創建新的子進程
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 8
#保證空閑進程數最大值,如果空閑進程大于此值,此進行清理
相關推薦:
Linux上安裝php-mysqlnd擴展實例
mac安裝php開發環境方法實例分享
最詳細的linux安裝php過程
以上就是linux如何安裝php的詳細內容,更多請關注 其它相關文章!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答