Home Backend Development PHP Tutorial Linux编译升级php的详细方法_PHP

Linux编译升级php的详细方法_PHP

Jun 01, 2016 am 11:58 AM
linux php

服务器环境:CentOS – 5.4
php升级:5.4.14 - 5.5.0
升级心得:比较顺利,但是有一点需要说明:eaccelerator无法兼容php5.5.0,好在php在5.5.0默认提供了Zend OPcache,所以一直习惯eaccelerator的朋友如果要升级到php5.5.0的话,可能要暂时和eaccelerator说bye bye了。
1、安装php5.5.0
下载php安装包:http://www.php.net/get/php-5.5.0.tar.gz/from/a/mirror
复制代码 代码如下:
# 解压缩安装包
tar zxvf php-5.5.0.tar.gz

# 进入目录
cd php-5.5.0

# 编译安装
./configure \
--prefix=/usr/local/webserver/php-d/php-5.5.0 \
--with-config-file-path=/usr/local/webserver/php-d/php-5.5.0/etc \
--with-config-file-scan-dir=/usr/local/webserver/php-d/php-5.5.0/etc/php.d \
--with-curl=/usr/local/lib \
--with-freetype-dir=/usr/lib64 \
--with-gd \
--with-gettext \
--with-iconv-dir=/usr/local/lib \
--with-jpeg-dir=/usr/lib64 \
--with-kerberos \
--with-ldap \
--with-ldap-sasl \
--with-libdir=lib64 \
--with-libxml-dir=/usr/lib64 \
--with-mcrypt \
--with-mhash \
--with-mysql \
--with-mysqli \
--with-openssl \
--with-pcre-regex=/usr \
--with-pdo-mysql=shared \
--with-pdo-sqlite=shared \
--with-pear=/usr/local/lib/php \
--with-png-dir=/usr/lib64 \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--disable-rpath

make ZEND_EXTRA_LIBS='liconv'
make install
cp php.ini-production /usr/local/webserver/php-d/php-5.5.0/etc/php.ini

这里有几个地方需要说明一下:
安装时,请根据自己的情况添加、删除附加组建,修改对应的目录路径
安装的时候别忘记了搭配opcache:–enable-opcache
php-5.3.10编译时加了–enable-safe-mode选项,但是php-5.4.0已经去掉了该选项,编译时可以 ./configure –help | grep “safe-mode” 查看一下,没有信息输出,表示已经不支持!
同样去处的还有:'–enable-discard-path','–enable-fastcgi','–enable-force-cgi-redirect','–with-curlwrappers'
2.编译安装php5.5.0扩展模块:
安装imagick
安装这个模块需要服务器支持ImageMagick,这里和升级php无关,这部分省略,需要的请自行搜索
下载地址:http://pecl.php.net/package/imagick
复制代码 代码如下:
tar xvzf imagick-3.1.0RC2.tgz
cd imagick-3.1.0RC2
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
./configure --with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make
make install

注意:
避免兼容问题,请使用最新版本,请不要使用3.0.1之前的版本
如果安装的时候报错make: *** [imagick_file.lo] 错误 1,请调用pkgconfig
以上目录路径请根据个人情况进行修改
安装memcache:
安装这个模块需要服务器支持memcached,这里和升级php无关,这部分省略,需要的请自行搜索
下载地址:http://pecl.php.net/package/memcache
复制代码 代码如下:
tar xvzf memcache-3.0.tgz
cd memcache-3.0.8
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
./configure \
--enable-memcache \
--with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make
make install

注:请不要使用2.2.6及以下版本,不兼容
安装phpredis-master
安装这个模块需要服务器支持redis,这里和升级php无关,这部分省略,需要的请自行搜索
下载地址:https://github.com/nicolasff/phpredis
复制代码 代码如下:
unzip master
cd phpredis-master
/usr/local/webserver/php-d/php-5.5.0/bin/phpize
./configure \
--enable-redis \
--with-php-config=/usr/local/webserver/php-d/php-5.5.0/bin/php-config
make
make install

至此,所有需要的模块都安装完毕。
3.配置php.ini
复制代码 代码如下:
vi /usr/local/webserver/php-d/php-5.5.0/etc/php.ini

# 找到extension_dir
extension_dir = "/usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/"

extension = "imagick.so"
extension = "memcache.so"
extension = "pdo_mysql.so"
extension = "redis.so"

# 找到date.timezone
date.timezone = Asia/Shanghai

# 找到session.save_handler
session.save_handler = redis

# 找到session.save_path
session.save_path = "tcp://127.0.0.1:6379?weight=1"

配置Zend OPcache
一直以来都习惯用eAccelerator为php提供加速,但是目前有两个问题:
eAccelerator暂时不兼容php5.5.0
eAccelerator和Zend Opcache冲突
好在php5.5.0默认提供了Zend Opcache为php加速,配置方法如下:
复制代码 代码如下:
zend_extension = /usr/local/webserver/php-d/php-5.5.0/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
; 上面zend_extension路径为opcache.so的路径

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

注意:如果在您的php扩展模块找不到opcache.so说明没有安装成功,请重新安装
4.配置php-fpm.conf
复制代码 代码如下:
pid = /usr/local/webserver/php-d/php-5.5.0/var/run/php-fpm.pid
error_log = /usr/local/webserver/php-d/php-5.5.0/logs/php-fpm.log

log_level = notice

emergency_restart_threshold = 10
emergency_restart_interval = 60s

process_control_timeout = 5s
daemonize = yes

rlimit_files = 65535
rlimit_core = 0

user = www
group = www

listen.backlog = -1
listen.owner = www
listen.group = www
listen.mode = 0666
listen.allowed_clients = 127.0.0.1

pm = static
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024

ping.response = pong
slowlog = /usr/local/webserver/php-d/php-5.5.0/logs/$pool.log.slow
request_slowlog_timeout = 0
request_terminate_timeout = 0
catch_workers_output = yes

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f jht2718@163.com
php_flag[display_errors] = on

备注:请根据自己的情况修改配置文件
5.修改启动项:
复制代码 代码如下:
cp /usr/local/webserver/php-d/php-5.5.0/bin/php /etc/init.d/php

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
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
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
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.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

Docker on Linux: Containerization for Linux Systems Docker on Linux: Containerization for Linux Systems Apr 22, 2025 am 12:03 AM

Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

See all articles