Heim >Backend-Entwicklung >PHP-Tutorial > php5.4.13在ubuntu12.04上的配备

php5.4.13在ubuntu12.04上的配备

WBOY
WBOYOriginal
2016-06-13 12:50:30837Durchsuche

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.

<span class="pln">apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install libxpm</span><span class="pun">-</span><span class="pln">dev
有可能还会出现这个错误,那么继续
</span><span class="pln"><span class="pln">cd </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">
ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">x86_64</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">gnu</span><span class="pun">/</span><span class="pln">libXpm</span><span class="pun">.</span><span class="pln">a </span><span class="pun">.</span><span class="pln">
ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">x86_64</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">gnu</span><span class="pun">/</span><span class="pln">libXpm</span><span class="pun">.</span><span class="pln">so </span><span class="pun">.</span><span class="pln">
ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">x86_64</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">gnu</span><span class="pun">/</span><span class="pln">libXpm</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="lit">4</span><span class="pun">.</span><span class="pln">
ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">x86_64</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">gnu</span><span class="pun">/</span><span class="pln">libXpm</span><span class="pun">.</span><span class="pln">so</span><span class="pun">.</span><span class="lit">4.11</span><span class="pun">.</span><span class="lit">0</span><span class="pun">.</span></span>

?

至此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 {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 www-data www-data
sharedscripts
postrotate
[ ! -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 

主要是下面的参数需要改下:

  1. pid = run/php-fpm.pid? //这个必去将前面的;注释去掉(一开始没去掉结果出502错误)
  2. error_log = log/php-fpm.log
  3. log_level = notice
  4. ;emergency_restart_threshold = 0
  5. ;emergency_restart_interval = 0
  6. ;process_control_timeout = 0
  7. ;daemonize = yes
  8. [www]
  9. ;prefix = /path/to/pools/$pool
  10. listen = 127.0.0.1:9000
  11. ; listen.backlog = -1
  12. listen.allowed_clients = 127.0.0.1
  13. listen.owner = www-data
  14. listen.group = www-data
  15. listen.mode = 0666
  16. user = www-data
  17. group = www-data
  18. pm = dynamic
  19. pm.max_children = 50
  20. pm.start_servers = 20
  21. pm.min_spare_servers = 5
  22. pm.max_spare_servers = 35
  23. pm.max_requests = 500

?

?

?

?

?

然后配置nginx:
vi /etc/nginx/nginx.conf

user  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代理处理,这也是反向代理的一个应用,这里可以是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 -v
PHP 5.4.0 (fpm-fcgi) (built: Mar 12 2012 18:13:13) (DEBUG)
Copyright (c) 1997-2009 The PHP Group
Zend 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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn