ubuntu编译安装PHP5.4.0+Nginx(FPM/FastCGI)
2012-07-30 09:01
786 查看
PHP5.4.0发布了,添加了很多新特性,于是今天在ubuntu下编译安装了PHP5.4+Nginx1.0.13+Memcache,让PHP
以fastcgi模式运行。MySQL就不装了用以前的5.1版本的。附张图:
安装编译过程遇到许多小问题,折腾了一个晚上,现在整理下:
(1):卸载以前通过源安装的php5.3.2和apache
sudoapt-get–purgeremoveapache2
sudoapt-get–purgeremoveapache2-common
sudoapt-get–purgeremoveapache2-utils
sudoapt-getautoremoveapache2
(–purge是不保留配置文件的意思,这个绝对不能少)
然后再sudoapt-getinstallapache2就可以了
PS:如果不行的话,就把关于apache2的所有东西强删掉,因为我执行这些命令之前就已经把所有的都干掉。
删掉/etc/apache2文件夹:sudorm-r/etc/apache2
删掉/var/www文件夹:sudorm-r/var/www
删掉/etc/init.d/apache2文件:sudorm-r/etc/init.d/apache2
然后就是卸载PHP5了,方法如下:
sudoapt-get–purgeremovelibapache2-mod-php5php5php5-gdphp5-mysql
sudoapt-getautoremovephp5
下面是卸载MYSQL的方法:
终端下输入命令:
1sudoapt-getautoremove–purgemysql-server-5.0
2sudoapt-getremovemysql-server
3sudoapt-getautoremovemysql-server
4sudoapt-getremovemysql-common(非常重要)
下面这句是清楚残留信息。
dpkg-l|grep^rc|awk’{print$2}’|sudoxargsdpkg-P
(2):安装Nginx1.0.13
然后sudoapt-getinstallnginx
(3):准备工作
1,从php官网下载php5.4.tar.gz解压:tar-zxvfphp-5.4.0tar.gz然后cdphp-5.4.0
2,./buildconf--force报错(好像是这样):Youneedautoconfversion2.59orhigher要安装autoconf2.59更高
版本,方法如下:
1,先卸载原先的autoconf:sudoapt-get--purgeremoveautoconf,然后sudoapt-getautoremoveautoconf
2,安装autoconf2.62:
(4):开始编译安装配置PHP5.4.0
./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--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
最后几个参数解释下:
当中遇到的错误和解决方法如下:
1)Configure:error:xml2-confignotfound.Pleasecheckyourlibxml2installation.
Solutions:
yuminstalllibxml2libxml2-devel(ForRedhat&Fedora)
#aptitudeinstalllibxml2-dev(Forubuntu)
2)Checkingforpkg-config…/usr/bin/pkg-config
configure:error:CannotfindOpenSSL’s<evp.h>or<hmac.h>
Solutions:
yuminstallopensslopenssl-devel
onsomesystems,likeUbuntuFeisty,youmightneedtousethiscommand:
sudoapt-getinstallopenssl-dev
sudoapt-getinstalllibcurl3-openssl-dev
3)Configure:error:PleasereinstalltheBZip2distribution
Solutions:
yuminstallbzip2bzip2-devel
4)Configure:error:Pleasereinstallthelibcurldistribution-
easy.hshouldbein/include/curl/
Solutions:
yuminstallcurlcurl-devel(ForRedhat&Fedora)
apt-getinstallcurl
apt-getinstalllibcurl3
apt-getinstalllibcurl4-gnutls-dev(ForUbuntu)
5)Configure:error:libjpeg.(also)notfound.
Solutions:
yum-yinstallgd
yum-yinstallgd-devel
yuminstalllibjpeglibjpeg-devel
6)Configure:error:libpng.(also)notfound.
Solutions:
yuminstalllibpnglibpng-devel
apt-getinstalllibpng12-dev
7)Configure:error:freetype.hnotfound.
Solutions:
yuminstallfreetype-devel
8)Configure:error:Unabletolocategmp.h
Solutions:
yuminstallgmp-devel
9)Configure:error:CannotfindMySQLheaderfilesunder/usr.
NotethattheMySQLclientlibraryisnotbundledanymore!
Solutions:
yuminstallmysql-devel(ForRedhat&Fedora)
#apt-getinstalllibmysql++-dev(ForUbuntu)
10)Configure:error:Pleasereinstallthencursesdistribution
Solutions:
yuminstallncursesncurses-devel
11)CheckingforunixODBCsupport…configure:error:ODBCheaderfile‘/usr/include/sqlext.h’notfound!
Solutions:
yuminstallunixODBC-devel
12)Configure:error:Cannotfindpspell
Solutions:
yuminstallpspell-devel
13)configure:error:mcrypt.hnotfound.Pleasereinstalllibmcrypt.
Solutions:
yuminstalllibmcryptlibmcrypt-devel(ForRedhat&Fedora)
#apt-getinstalllibmcrypt-dev
14)Configure:error:snmp.hnotfound.CheckyourSNMPinstallation.
Solutions:
yuminstallnet-snmpnet-snmp-devel
编译完成后make&&makeinstall,将php5所在的目录也加到bash的PATH中去:
mkdir/var/log/php-fpmchown-Rwww-data:www-data/var/log/php-fpm
准备PHP的配置文件:
cp-fphp.ini-production/opt/php5/etc/php.ini
chmod644/opt/php5/etc/php.ini
cp/opt/php5/etc/php-fpm.conf.default/opt/php5/etc/php-fpm.conf
注意:PHP5的配置文件在/opt/php5/etc/php.ini,php-fpm的配置文件在/opt/php5/etc/php-fpm.conf.
设置php-fpm启动管理文件,并让PHP在ubuntu启动时自动运行(下面地sapi是PHP5.4.0安装包中的):
cp-fsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
chmod755/etc/init.d/php-fpm
update-rc.d-fphp-fpmdefaults
设置PHP的自动日志分割和压缩:vi/etc/logrotate.d/php-fpm
加入下面的内容保存退出:
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
一些参考资料:
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.htmlhttp://www.frostsky.com/2011/11/php-configure-error/http://letle.iteye.com/blog/625728http://kangxiaowei.com/archives/2398.htmlhttp://wenku.baidu.com/view/2ae270e9551810a6f52486ea.html
以fastcgi模式运行。MySQL就不装了用以前的5.1版本的。附张图:
安装编译过程遇到许多小问题,折腾了一个晚上,现在整理下:
(1):卸载以前通过源安装的php5.3.2和apache
sudoapt-get–purgeremoveapache2
sudoapt-get–purgeremoveapache2-common
sudoapt-get–purgeremoveapache2-utils
sudoapt-getautoremoveapache2
(–purge是不保留配置文件的意思,这个绝对不能少)
然后再sudoapt-getinstallapache2就可以了
PS:如果不行的话,就把关于apache2的所有东西强删掉,因为我执行这些命令之前就已经把所有的都干掉。
删掉/etc/apache2文件夹:sudorm-r/etc/apache2
删掉/var/www文件夹:sudorm-r/var/www
删掉/etc/init.d/apache2文件:sudorm-r/etc/init.d/apache2
然后就是卸载PHP5了,方法如下:
sudoapt-get–purgeremovelibapache2-mod-php5php5php5-gdphp5-mysql
sudoapt-getautoremovephp5
下面是卸载MYSQL的方法:
终端下输入命令:
1sudoapt-getautoremove–purgemysql-server-5.0
2sudoapt-getremovemysql-server
3sudoapt-getautoremovemysql-server
4sudoapt-getremovemysql-common(非常重要)
下面这句是清楚残留信息。
dpkg-l|grep^rc|awk’{print$2}’|sudoxargsdpkg-P
(2):安装Nginx1.0.13
然后sudoapt-getinstallnginx
(3):准备工作
1,从php官网下载php5.4.tar.gz解压:tar-zxvfphp-5.4.0tar.gz然后cdphp-5.4.0
2,./buildconf--force报错(好像是这样):Youneedautoconfversion2.59orhigher要安装autoconf2.59更高
版本,方法如下:
1,先卸载原先的autoconf:sudoapt-get--purgeremoveautoconf,然后sudoapt-getautoremoveautoconf
2,安装autoconf2.62:
#cd/home/cyrec
#wgethttp://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz#tar-zvxfm4-1.4.9.tar.gz
#cdm4-1.4.9/
#./configure&&make&&makeinstall
#cd../
#wgethttp://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz#tar-zvxfautoconf-2.62.tar.gz
#cdautoconf-2.62/
#./configure&&make&&makeinstall
然后再./buildconf--force(如果php出现找不到autoconf的错误执行exportPHP_AUTOCONF="/(autoconf路径)/autoconf2.62")
(4):开始编译安装配置PHP5.4.0
./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--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
最后几个参数解释下:
--enable-debug
顾名思义,它的作用是激活调试模式。它将激活PHP源码中几个非常关键的函数,最典型的功能便是在每一个请求结束后给出这一次请求中内存的泄漏情况。--enable-maintainer-zts
激活php的线程安全机制(ThreadSafeResourceManager(TSRM)/ZendThreadSafety(ZTS)),使我们开发出的程序是线程安全的。--enable-embed
它主要用在你做php的嵌入式开发的场景中。平时我们把php作为apache的一个module进行编译,得到libphp5.so,而这个选项便使php编译后得到一个与我们设定的SAPI相对应的结果。当中遇到的错误和解决方法如下:
1)Configure:error:xml2-confignotfound.Pleasecheckyourlibxml2installation.
Solutions:
yuminstalllibxml2libxml2-devel(ForRedhat&Fedora)
#aptitudeinstalllibxml2-dev(Forubuntu)
2)Checkingforpkg-config…/usr/bin/pkg-config
configure:error:CannotfindOpenSSL’s<evp.h>or<hmac.h>
Solutions:
yuminstallopensslopenssl-devel
onsomesystems,likeUbuntuFeisty,youmightneedtousethiscommand:
sudoapt-getinstallopenssl-dev
sudoapt-getinstalllibcurl3-openssl-dev
3)Configure:error:PleasereinstalltheBZip2distribution
Solutions:
yuminstallbzip2bzip2-devel
4)Configure:error:Pleasereinstallthelibcurldistribution-
easy.hshouldbein/include/curl/
Solutions:
yuminstallcurlcurl-devel(ForRedhat&Fedora)
apt-getinstallcurl
apt-getinstalllibcurl3
apt-getinstalllibcurl4-gnutls-dev(ForUbuntu)
5)Configure:error:libjpeg.(also)notfound.
Solutions:
yum-yinstallgd
yum-yinstallgd-devel
yuminstalllibjpeglibjpeg-devel
6)Configure:error:libpng.(also)notfound.
Solutions:
yuminstalllibpnglibpng-devel
apt-getinstalllibpng12-dev
7)Configure:error:freetype.hnotfound.
Solutions:
yuminstallfreetype-devel
8)Configure:error:Unabletolocategmp.h
Solutions:
yuminstallgmp-devel
9)Configure:error:CannotfindMySQLheaderfilesunder/usr.
NotethattheMySQLclientlibraryisnotbundledanymore!
Solutions:
yuminstallmysql-devel(ForRedhat&Fedora)
#apt-getinstalllibmysql++-dev(ForUbuntu)
10)Configure:error:Pleasereinstallthencursesdistribution
Solutions:
yuminstallncursesncurses-devel
11)CheckingforunixODBCsupport…configure:error:ODBCheaderfile‘/usr/include/sqlext.h’notfound!
Solutions:
yuminstallunixODBC-devel
12)Configure:error:Cannotfindpspell
Solutions:
yuminstallpspell-devel
13)configure:error:mcrypt.hnotfound.Pleasereinstalllibmcrypt.
Solutions:
yuminstalllibmcryptlibmcrypt-devel(ForRedhat&Fedora)
#apt-getinstalllibmcrypt-dev
14)Configure:error:snmp.hnotfound.CheckyourSNMPinstallation.
Solutions:
yuminstallnet-snmpnet-snmp-devel
编译完成后make&&makeinstall,将php5所在的目录也加到bash的PATH中去:
echo'if[-d"/opt/php5/bin"]&&[-d"/opt/php5/sbin"];then
PATH="$PATH:/opt/php5/bin:/opt/php5/sbin"
fi'>>/etc/bash.bashrc
当前会话也加上:
exportPATH="$PATH:/opt/php5/bin:/opt/php5/sbin"
准备PHP5的日志文件目录:
mkdir/var/log/php-fpmchown-Rwww-data:www-data/var/log/php-fpm
准备PHP的配置文件:
cp-fphp.ini-production/opt/php5/etc/php.ini
chmod644/opt/php5/etc/php.ini
cp/opt/php5/etc/php-fpm.conf.default/opt/php5/etc/php-fpm.conf
注意:PHP5的配置文件在/opt/php5/etc/php.ini,php-fpm的配置文件在/opt/php5/etc/php-fpm.conf.
设置php-fpm启动管理文件,并让PHP在ubuntu启动时自动运行(下面地sapi是PHP5.4.0安装包中的):
cp-fsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
chmod755/etc/init.d/php-fpm
update-rc.d-fphp-fpmdefaults
设置PHP的自动日志分割和压缩:vi/etc/logrotate.d/php-fpm
加入下面的内容保存退出:
/var/log/php-fpm/*.log{
weekly
missingok
rotate52
compress
delaycompress
notifempty
create640www-datawww-data
sharedscripts
postrotate
[!-f/opt/php5/var/run/php-fpm.pid]||kill-USR1`cat/opt/php5/
/var/run/php-fpm.pid`
endscript
}
(5):安装APC,Memcache拓展:
wgethttp://pecl.php.net/get/APC-3.1.9.tgztar-zxfAPC-3.1.9.tgz
cdAPC-3.1.9
/opt/php5/bin/phpize
./configure--with-php-config=/opt/php5/bin/php-config
make
makeinstall
然后打开php配置文件:vi/opt/etc/php.ini
在末尾加上:
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]Potentialcacheslamavertedforkey...errors"
;apc.slam_defense=Off
PS:虽然能正常编译安装,但加载APC启动fpm时会报错,看来APC拓展在php5.4下不兼容,虽然能使用,但运行PHP程序
会出core,而且另外两款PHP缓存拓展eacc和xcache在php5.4下也不能编译安装,所以现在php5.4还不能用在生产
环境,只能尝鲜玩玩。
安装Memcache只要在pecl上找到相应的安装包按上面步骤重做一遍。
顺便修改php.ini的时区:
date.timezone=Asia/Shanghai
(6):配置php-fpm和nginx
php-fpm:
vi/opt/php5/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.conf
usernginx;
worker_processes2;
error_log/var/log/nginx/error.logwarn;
pid/var/run/nginx.pid;
events
{
useepoll;
worker_connections1024;
}
http
{
includemime.types;
default_typeapplication/octet-stream;
#charsetgb2312;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size8M;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
tcp_nodelayon;
fastcgi_connect_timeout300s;
fastcgi_send_timeout300s;
fastcgi_read_timeout300s;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
#limit_zonecrawler$binary_remote_addr10m;
server
{
listen80;#/*监听端口*/
server_namelocalhost;#/*服务器名称*/
indexindex.htmlindex.htmindex.php;#/*缺省主页名称*/
root/var/www;#/*网站根目录,也可以采用下面内容*/
#也可以采用相对路径,下面注释部分*/
#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#limit_conncrawler20;
#通过FastCGI方式支持PHP,php页面由fastcgi代理处理,这也是反向代理的一个应用,这里可以是jsp/asp等脚本。
location~.*\.(php|php5)?$
{
include/etc/nginx/fastcgi_params;#为FastCGI模块设置了基本的环境变量
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/var/www/$fastcgi_script_name;
#includefcgi.conf;#/*fastcgi配置文件,修改为以下内容*/
}
#对于某一类型的文件,设置过期时间,静态的页面通常设置长一点。
#静态文件,nginx自己处理
location~.*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires30d;
}
#日志的格式
log_formataccess'$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.logaccess;
}
}
然后保存退出,重启fpm和nginx
/etc/init.d/php-fpmrestart
/etc/init.d/nginxrestart
安装完成:
root@Cyrec-desktop:~#php-fpm-v
PHP5.4.0(fpm-fcgi)(built:Mar12201218:13:13)(DEBUG)
Copyright(c)1997-2009ThePHPGroup
ZendEnginev2.4.0,Copyright(c)1998-2012ZendTechnologies
一些参考资料:
相关文章推荐
- ubuntu编译安装PHP5.4.0+Nginx(FPM/FastCGI)
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- nginx+PHP+PHP-FPM(FastCGI)在Ubuntu上的安装和配置
- 编译安装spawn-fcgi(nginx通过FastCGI方式调用PHP)
- Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL
- [Linux] Ubuntu_9.04_server安装nginx+php(fastcgi)+nginx虚拟主机配置格式
- ubuntu16.04编译安装nginx和php
- Debian/Ubuntu源码编译安装PHP--支持FastCGI
- nginx架构特性及编译安装,实战Nginx与PHP(FastCGI)的安装、配置与优化
- ubuntu 下编译安装 mysql php nginx 及常见错误 (持续添加)
- Ubuntu下安装Nginx,PHP5(及PHP-FPM),MySQL
- Ubuntu下安装Nginx+PHP+MySQL+FastCGI
- 在 Debian 上源码编译和安装 Nginx+PHP+FastCGI+MySQL
- ubuntu 安装 nginx php7.0-fpm mysql-server php7.0-mysql
- Nginx之三:PHP的编译安装(FastCGI模式)