Home Backend Development PHP Tutorial unbutu升级php和安装php扩展插件

unbutu升级php和安装php扩展插件

Jun 20, 2016 pm 12:39 PM

ubuntu升级php和安装php扩展

我想说的话:

    虽然对已一个运维来说,升级个php安装个扩展是很简单的事情,但我还是把这次升级的过程完整记录下来(每个插件都带有wget下载地址,这是我的初衷),这样再次安装扩展插件时就省事多了,不至于每个插件去趟官网找下载地址。

=======================废话不多说,开始======================

php升级5.3.24到5.4.34
首先查看原版本的php编译参数:

root@develop:~# /usr/local/php/bin/php -i | grep configure./configure  '--prefix=/usr/local/php-5.3.24/' \'--with-config-file-path=/usr/local/php-5.3.24/etc' \'--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' \'--with-zlib' '--enable-xml' '--with-curl' '--with-curlwrappers' \'--enable-mbregex' '--enable-mbstring' '--with-openssl' \'--enable-sockets' '--enable-zip' '--disable-ipv6' \'--with-pear' \'--enable-fpm' \'--with-fpm-user=www' \'--with-fpm-group=www' \'--with-mysql=/usr/local/mysql' \'--with-mysqli=mysqlnd' \'--enable-soap' \'--with-pdo-mysql' \'--enable-pcntl' \'--with-gd' '--with-xmlrpc' '--with-iconv' '--with-mcrypt'
Copy after login


升级php要注意php的编译参数要相同。要带上版本号,然后使用软连接访问。


开始升级:

cd /usr/local/src/wget http://cn2.php.net/distributions/php-5.4.34.tar.gztar zxf php-5.4.34.tar.gzcd php-5.4.34./configure  '--prefix=/usr/local/php-5.4.34/' \'--with-config-file-path=/usr/local/php-5.4.34/etc' \'--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' \'--with-zlib' '--enable-xml' '--with-curl' '--with-curlwrappers' \'--enable-mbregex' '--enable-mbstring' '--with-openssl' \'--enable-sockets' '--enable-zip' '--disable-ipv6' \'--with-pear' \'--enable-fpm' \'--with-fpm-user=www' \'--with-fpm-group=www' \'--with-mysql=/usr/local/mysql' \'--with-mysqli=mysqlnd' \'--enable-soap' \'--with-pdo-mysql' \'--enable-pcntl' \'--with-gd' '--with-xmlrpc' '--with-iconv' '--with-mcrypt'make
Copy after login

其中make步骤报错如下:

ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':/home/king/php-5.2.13/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'collect2: ld returned 1 exit statusmake: *** [sapi/cli/php] Error 1
Copy after login

解决:参考:http://blog.csdn.net/sflsgfs/article/details/6318583
在安� PHP 到系统中时要是发生「undefined reference to libiconv_open'」之类的错误信息,那表示在「./configure 」�抓好一些环境变数值。错误发生点在建立「-o sapi/cli/php」是出错,没�到要 link 的 iconv 函式库参数。

解决方法:编辑Makefile 大约77 行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,
例如: EXTRA_LIBS = ..... -lcrypt -liconv
然后重新再次 make 即可。
继续升级:

 make make install cd ..
Copy after login

编译完成有如下提示:
Wrote PEAR system config file at: /usr/local/php-5.4.34/etc/pear.conf
You may want to add: /usr/local/php-5.4.34/lib/php to your php.ini include_path
/usr/local/src/php-5.4.34/build/shtool install -c ext/phar/phar.phar /usr/local/php-5.4.34/bin
ln -s -f /usr/local/php-5.4.34/bin/phar.phar /usr/local/php-5.4.34/bin/phar
Installing PDO headers: /usr/local/php-5.4.34/include/php/ext/pdo/

====================升级完成,开始配置php===========================


1) 拷贝源码包目录下的php.ini参考文件到安装目录的etc目录下

cp /usr/local/src/php-5.4.34/php.ini-production  /usr/local/php-5.4.34/etc/php.ini
Copy after login

修改php.ini参数(参考已有的5.3.24的php.ini)

2 )配置生产php-fpm配置文件

root@develop:/usr/local/php-5.4.34/etc# pwd/usr/local/php-5.4.34/etcroot@develop:/usr/local/php-5.4.34/etc# cp php-fpm.conf.default php-fpm1.conf
Copy after login

修改 php-fpm1.conf (参考已有的5.3.24的php-fpm1.conf)


3)配置完成后,创建软连接

ln -s /usr/local/php-5.4.34/ /usr/local/php
Copy after login


4 )查看就版本安装的php扩展,为新版本的php安装扩展插件


旧版本安装的php安装扩展如下:

extension=redis.soextension=eaccelerator.so;extension=memcached.soextension=memcache.soextension=gearman.soextension=trie_filter.soextension=mongo.so
Copy after login
Copy after login

======================开始安装php扩展====================

1 redis扩展安装

cd /usr/local/src/wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gztar zxf 2.2.4.tar.gzcd phpredis-2.2.4//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ..
Copy after login

检查:(出现redis.so表示正确)

ll /usr/local/php-5.4.34/lib/php/extensions/no-debug-non-zts-20100525/
Copy after login


配置php支持:

vim /usr/local/php/etc/php.ini     #修改扩展模块路径    extension_dir = "/usr/local/php-5.4.34/lib/php/extensions/no-debug-non-zts-20100525/"    # 添加支持    extension="redis.so"
Copy after login

重启php和nginx(最后统一重启)

2 安装eaccelerator插件

cd /usr/local/src/wget https://codeload.github.com/eaccelerator/eaccelerator/legacy.tar.gz/mastertar zxf mastercd eaccelerator-eaccelerator-42067ac//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ..echo 'include /usr/lib/php/modules/*.so' >>  /etc/ld.so.conf
Copy after login

修改/usr/local/php/ect/php.ini添加如下配置:

[eaccelerator]zend_extension_ts="/usr/local/php-5.4.34/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"eaccelerator.shm_size="32"eaccelerator.cache_dir="/tmp/eaccelerator"eaccelerator.enable="1"eaccelerator.optimizer="1"eaccelerator.check_mtime="1"eaccelerator.debug="0"eaccelerator.filter=""eaccelerator.shm_max="0"eaccelerator.shm_ttl="0"eaccelerator.shm_prune_period="0"eaccelerator.shm_only="0"eaccelerator.compress="1"eaccelerator.compress_level="9"
Copy after login

创建缓存目录:

mkdir -p /tmp/eacceleratorchmod 777 /tmp/eaccelerator
Copy after login

(重启nginx php,最后统一重启)


3 安装memcache.so扩展

cd /usr/local/src/wget http://pecl.php.net/get/memcache-2.2.7.tgztar zxf memcache-2.2.7.tgzcd memcache-2.2.7//usr/local/php/bin/phpize./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dirmakemake installcd ..
Copy after login

(重启nginx php,最后统一重启)

4 安装gearman扩展

cd /usr/local/src/wget http://pecl.php.net/get/gearman-1.1.2.tgztar zxf gearman-1.1.2.tgz cd gearman-1.1.2//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ..
Copy after login

(重启nginx php,最后统一重启)


5 安装trie_filter扩展:
(该软件不好下载,网络因素) 参考网址:http://www.codeweblog.com/用于检测敏感词的-php-扩展/

cd /usr/local/src/mkdir trie_filtercd trie_filter/wget https://as3chat.googlecode.com/files/trie_filter-2011-03-21.tar.gztar zxf trie_filter-2011-03-21.tar.gz/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installcd ..
Copy after login

(重启nginx php,最后统一重启)


6 安装mongo扩展

cd /usr/local/src/wget http://pecl.php.net/get/mongo-1.4.5.tgztar zxf mongo-1.4.5.tgzcd mongo-1.4.5//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config makemake installcd ..
Copy after login

7 扩展安装完成检查:

root@develop:/usr/local/src# ll /usr/local/php-5.4.34/lib/php/extensions/no-debug-non-zts-20100525/total 3380drwxr-xr-x 2 root root    4096 Jan 20 15:11 ./drwxr-xr-x 3 root root    4096 Jan 20 14:00 ../-rwxr-xr-x 1 root root  467380 Jan 20 14:13 eaccelerator.so*-rwxr-xr-x 1 root root  302505 Jan 20 14:39 gearman.so*-rwxr-xr-x 1 root root  265098 Jan 20 14:32 memcache.so*-rwxr-xr-x 1 root root 1445848 Jan 20 15:11 mongo.so*-rwxr-xr-x 1 root root  928238 Jan 20 14:00 redis.so*-rwxr-xr-x 1 root root   36722 Jan 20 14:54 trie_filter.so*
Copy after login

8 把已安装的扩展插件添加到php.ini

vim /usr/local/php/etc/php.ini
Copy after login


添加如下配置:

extension=redis.soextension=eaccelerator.so;extension=memcached.soextension=memcache.soextension=gearman.soextension=trie_filter.soextension=mongo.so
Copy after login
Copy after login

9 重启nginx和php

10 调用phpinfo();来检查

升级完毕。

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

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.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO) How do you prevent SQL Injection in PHP? (Prepared statements, PDO) Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

See all articles