Linux 下编译安装 PHP 环境

文章
林里克斯

PHP 作为一种强大的语言,无论是以模块还是 CGI 的方式安装,它的解释器都可以在服务器上访问文件、运行命令以及创建网络连接等。本文介绍在 Linux 环境下编译安装 PHP-7.4.12 环境。

Linux 下编译安装 PHP 环境


试验平台:CentOS Linux 7.6.1810

PHP Version:php-7.4.12


目录:


一、官网下载


1.官网 downloads

https://www.php.net/downloads.php

2.下载

$ wget https://www.php.net/distributions/php-7.4.12.tar.gz

3.解压

$ tar xf php-7.4.12.tar.gz 
$ cd php-7.4.12/

二、编译安装


1.编译

$ ./configure --prefix=/data/php --with-config-file-path=/data/php -with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --with-openssl --with-iconv --with-curl --with-jpeg --with-xmlrpc --with-zip --with-freetype --with-gettext --with-ldap --enable-mbstring --enable-ftp --enable-fpm --enable-xml --enable-sockets --enable-soap --enable-gd --enable-pcntl --enable-bcmath 
#这里把基本上需要用到的模块都加上了,可以根据自己所需增减 PHP 模块

2.缺少 libxml2 依赖

checking for libxml-2.0 >= 2.7.6... no
configure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:

No package 'libxml-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML_CFLAGS
and LIBXML_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
$ sudo yum -y install libxml2 libxml2-devel
#安装依赖

3.缺少 sqlite 依赖

checking for sqlite3 > 3.7.4... no
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:

No package 'sqlite3' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables SQLITE_CFLAGS
and SQLITE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
$ sudo yum -y install sqlite-devel

4.缺少 libcurl 依赖

checking for libcurl >= 7.15.5... no
configure: error: Package requirements (libcurl >= 7.15.5) were not met:

No package 'libcurl' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables CURL_CFLAGS
and CURL_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
$ sudo yum -y install libcurl-devel

5.缺少 libpng 依赖

checking for libpng... no
configure: error: Package requirements (libpng) were not met:

No package 'libpng' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables PNG_CFLAGS
and PNG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
$ sudo yum -y install libpng-devel
$ sudo yum -y install http://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.6-1.el7.remi.x86_64.rpm
$ sudo yum -y install http://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.6-1.el7.remi.x86_64.rpm

缺少 freetype 依赖

No package 'freetype2' found
yum -y install freetype-devel

6.编译安装

$ make && make install

三、验证


1.验证 php 版本

$ cd /data/php/bin/
$ ./php -v
PHP 7.4.12 (cli) (built: Nov 20 2020 17:00:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

2.增加用户环境变量

$ vim /home/users/.bash_profile
#编辑所需增加用户的环境变量文件,注意这只是个某一个用户增加,不是全局变量添加。若需全局,在 /etc/profile.d/ 下添加

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH=/data/php/bin:/data/php/sbin:$PATH
export PATH

3.页面访问 phpinfo

<?php
phpinfo();
?>

Linux 下编译安装 PHP 环境


Over ~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

1328 0 2020-11-20


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-12-28

今日天气
站点统计
  • 文章总数:241篇
  • 分类总数:29个
  • 评论总数:12条
  • 本站总访问量 353196 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!