Home Backend Development PHP Tutorial php5.4.13在ubuntu12.04上的配备

php5.4.13在ubuntu12.04上的配备

Jun 13, 2016 pm 12:50 PM
enable fpm install php

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
Copy after login

?? 然后

apt-get autoremove autoconf
Copy after login

?? 然后直接安装

apt-get install autoconf
Copy after login

五、开始编译安装配置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
Copy after login

?

当中遇到的错误和解决方法如下:

?

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>
Copy after login

?

至此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
Copy after login
?当前会话也加上:

export PATH="$PATH:/usr/local/php/bin:/usr/local/php/sbin"
Copy after login
?准备PHP5的日志文件目录:

?

mkdir /var/log/php-fpm 
chown -R www-data:www-data /var/log/php-fpm
Copy after login
?

?

准备PHP的配置文件:

?

cp -f php.ini-production /usr/local/php/etc/php.ini
Copy after login
chmod 644 /usr/local/php/etc/php.ini
Copy after login
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
Copy after login
?

注意: 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
}
Copy after login

?

配置php-fpm和nginx

php-fpm:

vi /usr/local/php/etc/php-fpm.conf 
Copy after login

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

  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
Copy after login

一些参考资料:

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles