Table of Contents
下载 PHP 源码包
添加 epel 源
安装依赖
创建 www 用户
编译安装
配置 PHP
添加 PHP 命令到环境变量
Home Backend Development PHP Tutorial Linux 下编译安装 PHP 5.6

Linux 下编译安装 PHP 5.6

Jun 23, 2016 pm 01:28 PM

系统环境:

CentOS 6.5 / 7.0 x86_64

Fedora 20 x86_64

下载 PHP 源码包

# wget http://cn2.php.net/distributions/php-5.6.0.tar.xz# xz -d php-5.6.0.tar.xz# tar xf php-5.6.0.tar -C /usr/local/src/
Copy after login

添加 epel 源

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Copy after login

安装依赖

# yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel
Copy after login

注:如果你使用的 epel 7 的源,可能会没有 mcrypt mhash mhash-devel 几个包,在http://dl.fedoraproject.org/pub/epel/6/x86_64/ 中下载,使用 yum localinstall xxx.rpm 或 rpm -Uvh xxx.rpm 手动安装即可。

创建 www 用户

# groupadd www# useradd -g www -s /sbin/nologin -M www
Copy after login

编译安装

# cd /usr/local/src/php-5.6.0/# ./configure \--prefix=/usr/local/php56 \--with-config-file-path=/usr/local/php56/etc \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-opcache \--enable-fpm \--with-fpm-user=www \--with-fpm-group=www \--with-mysql=mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-gettext \--enable-mbstring \--with-iconv \--with-mcrypt \--with-mhash \--with-openssl \--enable-bcmath \--enable-soap \--with-libxml-dir \--enable-pcntl \--enable-shmop \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-sockets \--with-curl \--with-zlib \--enable-zip \--with-bz2 \--with-readline
Copy after login

参数说明:

""" 安装路径 """--prefix=/usr/local/php56 \""" php.ini 配置文件路径 """--with-config-file-path=/usr/local/php56/etc \""" 优化选项 """--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """--enable-opcache \""" FPM """--enable-fpm \--with-fpm-user=www \--with-fpm-group=www \""" MySQL """--with-mysql=mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \""" 国际化与字符编码支持 """--with-gettext \--enable-mbstring \--with-iconv \""" 加密扩展 """--with-mcrypt \--with-mhash \--with-openssl \""" 数学扩展 """--enable-bcmath \""" Web 服务,soap 依赖 libxml """--enable-soap \--with-libxml-dir \""" 进程,信号及内存 """--enable-pcntl \--enable-shmop \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \""" socket & curl """--enable-sockets \--with-curl \""" 压缩与归档 """--with-zlib \--enable-zip \--with-bz2 \""" GNU Readline 命令行快捷键绑定 """--with-readline
Copy after login

如果你的 Web Server 使用的 Apache 请添加类似:--with-apxs2=/usr/local/apache-xx/bin/apxs 参数。

关于 mysqlnd 请查看 什么是 PHP 的 MySQL Native 驱动? 或查看 MySQL 官方介绍:MySQL native driver for PHP, 或 Installation on Unix。

PHP 5.6 ?建了 phpdbg 交互式调试器,通过 --enable-phpdbg 开启,会在 PREFIX/bin 目录下产生一个 phpdbg 命令,感兴趣的可以试一下。

更多编译参数请使用 ./configure --help 查看。

# make -j8# make install
Copy after login

如果想重新安装:

# make clean# make clean all# ./configure ...# make -j8# make install
Copy after login

配置 PHP

配置文件:

# cp php.ini-development /usr/local/php56/etc/php.ini
Copy after login

php-fpm 服务

# cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56# chmod +x /etc/init.d/php-fpm56
Copy after login

启动 php-fpm

# service php-fpm56 startStarting php-fpm  done
Copy after login

php-fpm 可用参数 start|stop|force-quit|restart|reload|status

添加 PHP 命令到环境变量

编辑 ~/.bash_profile,将:

PATH=$PATH:$HOME/bin改为:PATH=$PATH:$HOME/bin:/usr/local/php56/bin
Copy after login

使 PHP 环境变量生效:

# . ~/.bash_profile
Copy after login

查看看 PHP 版本

# php -vPHP 5.6.0 (cli) (built: Sep 23 2014 03:44:18) Copyright (c) 1997-2014 The PHP GroupZend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
Copy after login

转载请注明出处。<br />本文地址:http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux
Copy after login


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)

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,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

See all articles