Table of Contents
下载源码并解压
配置编译参数
生成配置文件
配置
编译和安装PHP7
查看安装成功后的PHP7目录
设置PHP7的配置文件
设置环境变量
设置PHP日志目录和php-fpm进程文件(php-fpm.sock)目录
将PHP设置为开机启动
启动PHP服务
Home Backend Development PHP Tutorial 【安装PHP】怎么在openSUSE42.1下编译安装PHP7

【安装PHP】怎么在openSUSE42.1下编译安装PHP7

Jun 13, 2016 pm 12:28 PM
enable php usr with

【安装PHP】如何在openSUSE42.1下编译安装PHP7

首先推荐一篇文章PHP 7 Release Date Arrived: Will Developers Adopt PHP 7? - PHP Classes blog。

里面说到是否会去使用PHP7,就个人而言,我是毫不犹豫地使用的,但是生产环境就不是我说了算,所以只能自己在自己的开发环境里更新PHP的版本。那么,你呢?

笔者使用的是Linux的openSUSE42.1发行版,Yast里面还没有PHP7的安装包,于是乎只能自己手动编译安装了。作为一个PHP开发者,我是非常希望能够学会编译安装PHP7的,之前试过几次,但是每次安装都要上网找各种资料,于是乎,这次安装成功后就想把自己的安装过程以及遇到的问题记录下来,方便以后查阅和分享给需要的人。

下载源码并解压

进入正题,要编译安装PHP7,首先当然要下载PHP7的源码。你可以到github上clone,也可以到PHP官网下载。下载后解压到 /usr/local/src 目录,并将目录重命名为php7。进入目录。

配置编译参数

生成配置文件

./buildconf
Copy after login

配置

./<span style="color: #000000;">configure \</span>--prefix=/usr/local/<span style="color: #000000;">php7 \</span>--exec-prefix=/usr/local/<span style="color: #000000;">php7 \</span>--bindir=/usr/local/php7/<span style="color: #000000;">bin \</span>--sbindir=/usr/local/php7/<span style="color: #000000;">sbin \</span>--includedir=/usr/local/php7/<span style="color: #000000;">include \</span>--libdir=/usr/local/php7/lib/<span style="color: #000000;">php \</span>--mandir=/usr/local/php7/php/<span style="color: #0000ff;">man</span><span style="color: #000000;"> \</span>--with-config-<span style="color: #0000ff;">file</span>-path=/usr/local/php7/<span style="color: #000000;">etc \</span>--with-mysql-sock=/var/run/mysql/<span style="color: #000000;">mysql.sock \</span>--with-mcrypt=/usr/<span style="color: #000000;">include \</span>--with-<span style="color: #000000;">mhash \</span>--with-<span style="color: #000000;">openssl \</span>--with-mysqli=<span style="color: #000000;">shared,mysqlnd \</span>--with-pdo-mysql=<span style="color: #000000;">shared,mysqlnd \</span>--with-<span style="color: #000000;">gd \</span>--with-<span style="color: #000000;">iconv \</span>--with-<span style="color: #000000;">zlib \</span>--enable-<span style="color: #0000ff;">zip</span><span style="color: #000000;"> \</span>--enable-inline-<span style="color: #000000;">optimization \</span>--disable-<span style="color: #000000;">debug \</span>--disable-<span style="color: #000000;">rpath \</span>--enable-<span style="color: #000000;">shared \</span>--enable-<span style="color: #000000;">xml \</span>--enable-<span style="color: #000000;">bcmath \</span>--enable-<span style="color: #000000;">shmop \</span>--enable-<span style="color: #000000;">sysvsem \</span>--enable-<span style="color: #000000;">mbregex \</span>--enable-<span style="color: #000000;">mbstring \</span>--enable-<span style="color: #0000ff;">ftp</span><span style="color: #000000;"> \</span>--enable-gd-native-<span style="color: #000000;">ttf \</span>--enable-<span style="color: #000000;">pcntl \</span>--enable-<span style="color: #000000;">sockets \</span>--with-<span style="color: #000000;">xmlrpc \</span>--enable-<span style="color: #000000;">soap \</span>--without-<span style="color: #000000;">pear \</span>--with-<span style="color: #000000;">gettext \</span>--enable-<span style="color: #000000;">session \</span>--with-<span style="color: #000000;">curl \</span>--with-jpeg-<span style="color: #0000ff;">dir</span><span style="color: #000000;"> \</span>--with-freetype-<span style="color: #0000ff;">dir</span><span style="color: #000000;"> \</span>--enable-<span style="color: #000000;">opcache \</span>--enable-<span style="color: #000000;">fpm \</span>--disable-<span style="color: #000000;">cgi \</span>--with-fpm-user=<span style="color: #000000;">nginx \</span>--with-fpm-group=<span style="color: #000000;">nginx \</span>--without-<span style="color: #000000;">gdbm \</span>--disable-fileinfo
Copy after login

 

参数说明

prefix PHP7安装的根目录

with-config-file-path PHP7的配置文件目录

 

执行完上面的配置命令后的结果如下图所示:

 

执行上面命令的过程中会遇到一些依赖缺少的提示,下面列出我遇到的依赖问题:

错误:

configure: error: xml2-config not found. Please check your libxml2 installation.
Copy after login

解决:

zypper <span style="color: #0000ff;">install</span> libxml2-devel
Copy after login

错误:

configure: WARNING: unrecognized options: --with-mysql
Copy after login

解决:

取消这个选项,这个选项是不存在的
Copy after login

错误:

configure: error: jpeglib.h not found.
Copy after login

解决:

zypper <span style="color: #0000ff;">install</span> libjpeg-devel
Copy after login

错误:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Copy after login

解决:

zypper <span style="color: #0000ff;">install</span> libmcrypt-devel
Copy after login

错误:

checking <span style="color: #0000ff;">for</span><span style="color: #000000;"> recode support... yesconfigure: error: Can not </span><span style="color: #0000ff;">find</span> recode.h anywhere under /usr /usr/local /usr /opt.
Copy after login

解决:

zypper <span style="color: #0000ff;">install</span> librecode-devel
Copy after login

总的来说,在配置的时候遇到没有的就打开Yast搜一下,如果有的话就安装,然后重新编译看还需要那些,如果在Yast找不到,那就上网找一下Google。

编译和安装PHP7

<span style="color: #0000ff;">make</span> && <span style="color: #0000ff;">make</span> <span style="color: #0000ff;">install</span>
Copy after login

其中,make之后可以选择make test。只是一个可选步骤,不执行不知道有什么问题,不过笔者暂时还没遇到。

 

查看安装成功后的PHP7目录

编译安装成功后,查看PHP7的安装目录`ls /usr/local/php7`:

 

设置PHP7的配置文件

<span style="color: #0000ff;">cp</span> /usr/local/src/php7/php.ini-production /usr/local/php7/etc/<span style="color: #000000;">php.ini</span><span style="color: #0000ff;">cp</span> /usr/local/src/sapi/fpm/init.d.php-fpm /etc/init.d/php-<span style="color: #000000;">fpm</span><span style="color: #0000ff;">cp</span> /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-<span style="color: #000000;">fpm.conf</span><span style="color: #0000ff;">cp</span> /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
Copy after login

 

设置环境变量

在/etc/profile 文件的最后一行加上

export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
Copy after login


然后执行 source /etc/profile 

设置PHP日志目录和php-fpm进程文件(php-fpm.sock)目录

<span style="color: #0000ff;">mkdir</span> -p /var/log/php-fpm/ && <span style="color: #0000ff;">mkdir</span> -p /var/run/php-fpm && cd /var/run/ && <span style="color: #0000ff;">chown</span> -R nginx:nginx php-fpm
Copy after login

将PHP设置为开机启动

<span style="color: #0000ff;">chmod</span> +x /etc/init.d/php-<span style="color: #000000;">fpmchkconfig php</span>-fpm on
Copy after login

可以用chkconfig命令查看开机启动服务列表。

启动PHP服务

service php-fpm start
Copy after login

通过ps aux | grep 'php'查看PHP是否启动成功

至此,PHP7就安装成功了,你也开始使用PHP7吧!

1楼冯煜博
NB!,我学到不少东西!
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)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

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,

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

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

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.

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.

See all articles