php之编译安装
<p> </p><p>1. 安装所需环境</p>
<div class="cnblogs_code">
<pre>yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel pcre-devel</pre>
</div>
<p> </p>
<p>2. 下载并安装PHP</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">. 下载
wget http:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">cn2.php.net/distributions/php-7.3.3.tar.gz</span>
<span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">. 解压
tar </span>-xzf php-<span style="color: rgba(128, 0, 128, 1)">7.3</span>.<span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">.tar.gz
</span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">. 进入目录
cd php7.</span><span style="color: rgba(128, 0, 128, 1)">3.3</span>
<span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">. 编译php
.</span>/configure --prefix=/usr/local/<span style="color: rgba(0, 0, 0, 1)">php7 \
</span>--with-config-file-path=/usr/local/php7/<span style="color: rgba(0, 0, 0, 1)">etc \
</span>--with-config-file-scan-dir=/usr/local/php7/etc/<span style="color: rgba(0, 0, 0, 1)">php.d \</span>--enable-<span style="color: rgba(0, 0, 0, 1)">mysqlnd \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">mysqli \
</span>--with-pdo-<span style="color: rgba(0, 0, 0, 1)">mysql \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">fpm \
</span>--with-fpm-user=<span style="color: rgba(0, 0, 0, 1)">nginx \
</span>--with-fpm-group=<span style="color: rgba(0, 0, 0, 1)">nginx \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">gd \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">iconv \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">zlib \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">xml \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">shmop \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">sysvsem \
</span>--enable-inline-<span style="color: rgba(0, 0, 0, 1)">optimization \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">mbregex \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">mbstring \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">ftp \</span>--with-<span style="color: rgba(0, 0, 0, 1)">openssl \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">pcntl \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">sockets \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">xmlrpc \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">zip \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">soap \
</span>--without-<span style="color: rgba(0, 0, 0, 1)">pear \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">gettext \
</span>--enable-<span style="color: rgba(0, 0, 0, 1)">session \
</span>--with-<span style="color: rgba(0, 0, 0, 1)">curl \
</span>--with-jpeg-<span style="color: rgba(0, 0, 0, 1)">dir \
</span>--with-freetype-<span style="color: rgba(0, 0, 0, 1)">dir \
</span>--enable-opcache</pre>
</div>
<p> 编译,安装</p>
<div class="cnblogs_code">
<pre>make && make install -<span style="color: rgba(0, 0, 0, 1)">j2
</span>-j: 启用两个任务</pre>
</div>
<p> </p>
<p>3. 配置PHP</p>
<p> 1) 复制ini文件</p>
<div class="cnblogs_code">
<pre>cp php.ini-production /usr/local/php7/etc/php.ini</pre>
</div>
<p> 2) 配置fpm</p>
<p> </p>
<div class="cnblogs_code">
<pre>cd /usr/src/php-<span style="color: rgba(128, 0, 128, 1)">7.0</span>.<span style="color: rgba(128, 0, 128, 1)">0</span>/sapi/<span style="color: rgba(0, 0, 0, 1)">fpm
cp init.d.php</span>-fpm /etc/init.d/php-<span style="color: rgba(0, 0, 0, 1)">fpm
chmod </span>+x /etc/init.d/php-<span style="color: rgba(0, 0, 0, 1)">fpm
chkconfig </span>--add php-<span style="color: rgba(0, 0, 0, 1)">fpm
chkconfig php</span>-fpm on</pre>
</div>
<p> </p>
<p>4. 启动服务</p>
<div class="cnblogs_code">
<pre>/etc/init.d/php-fpm start</pre>
</div>
<p> </p>
<p>5. 添加环境变量</p>
<div class="cnblogs_code">
<pre>vim /etc/<span style="color: rgba(0, 0, 0, 1)">profile
最后添加
export PATH</span>=$PATH:/usr/local/php7/<span style="color: rgba(0, 0, 0, 1)">bin
马上生效
source </span>/etc/<span style="color: rgba(0, 0, 0, 1)">profile
可以正常使用全局命令
php </span>-<span style="color: rgba(0, 0, 0, 1)">v
PHP </span><span style="color: rgba(128, 0, 128, 1)">7.2</span>.<span style="color: rgba(128, 0, 128, 1)">0</span> (cli) (built: Jan <span style="color: rgba(128, 0, 128, 1)">16</span> <span style="color: rgba(128, 0, 128, 1)">2020</span> <span style="color: rgba(128, 0, 128, 1)">12</span>:<span style="color: rgba(128, 0, 128, 1)">17</span>:<span style="color: rgba(128, 0, 128, 1)">55</span><span style="color: rgba(0, 0, 0, 1)">) ( NTS )
Copyright (c) </span><span style="color: rgba(128, 0, 128, 1)">1997</span>-<span style="color: rgba(128, 0, 128, 1)">2017</span><span style="color: rgba(0, 0, 0, 1)"> The PHP Group
Zend Engine v3.</span><span style="color: rgba(128, 0, 128, 1)">2.0</span>, Copyright (c) <span style="color: rgba(128, 0, 128, 1)">1998</span>-<span style="color: rgba(128, 0, 128, 1)">2017</span> Zend Technologies</pre>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> 常见错误:</p>
<p> 1. </p>
<div class="cnblogs_Highlighter">
<pre class="brush:csharp;gutter:true;">make时提示:
.....................................................
ext/iconv/.libs/iconv.o(.text+0x1738): In function `zif_iconv_mime_encode':
/usr/src/php-7.2.0/ext/iconv/iconv.c:1017: undefined reference to `libiconv_open'
ext/iconv/.libs/iconv.o(.text+0x1756):/usr/src/php-7.2.0/ext/iconv/iconv.c:1031: undefined reference to `libiconv_open'
ext/iconv/.libs/iconv.o(.text+0x1993):/usr/src/php-7.2.0/ext/iconv/iconv.c:1290: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x19ad):/usr/src/php-7.2.0/ext/iconv/iconv.c:1293: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x1b01):/usr/src/php-7.2.0/ext/iconv/iconv.c:1102: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1b33):/usr/src/php-7.2.0/ext/iconv/iconv.c:1134: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1b5e):/usr/src/php-7.2.0/ext/iconv/iconv.c:1150: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1e10):/usr/src/php-7.2.0/ext/iconv/iconv.c:1202: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x1e3c):/usr/src/php-7.2.0/ext/iconv/iconv.c:1233: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x207f):/usr/src/php-7.2.0/ext/iconv/iconv.c:1277: more undefined references to `libiconv' follow
ext/iconv/.libs/iconv.o(.text+0x2c08): In function `php_iconv_stream_filter_dtor':
/usr/src/php-7.2.0/ext/iconv/iconv.c:2393: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o(.text+0x2cf2): In function `php_iconv_stream_filter_append_bucket':
/usr/src/php-7.2.0/ext/iconv/iconv.c:2543: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x2d34):/usr/src/php-7.2.0/ext/iconv/iconv.c:2543: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x2de7):/usr/src/php-7.2.0/ext/iconv/iconv.c:2465: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o(.text+0x30e2): In function `php_iconv_stream_filter_factory_create':
/usr/src/php-7.2.0/ext/iconv/iconv.c:2419: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** Error 1
</pre>
</div>
<p> 解决:</p>
<p> </p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">安装libiconv:
#wget http:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz</span>
#tar -zxvf libiconv-<span style="color: rgba(128, 0, 128, 1)">1.13</span>.<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">.tar.gz
#cd libiconv</span>-<span style="color: rgba(128, 0, 128, 1)">1.13</span>.<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">
# .</span>/configure --prefix=/usr/local/<span style="color: rgba(0, 0, 0, 1)">libiconv
# make
# make install
编译PHP添加参数:
再检查php,指定 iconv的位置</span>--with-iconv=/usr/local/<span style="color: rgba(0, 0, 0, 1)">libiconv
#.</span>/configure --prefix=/usr/local/php72 --with-iconv=/usr/local/<span style="color: rgba(0, 0, 0, 1)">libiconv
#make
#make install</span></pre>
</div>
<p> </p>
<p> 2. error:Please reinstall the BZip2 distribution</p>
<div class="cnblogs_code">
<pre>yum install bzip2 bzip2-devel</pre>
</div>
<p> </p>
<p> 3. configure: error: cURL version 7.10.5 or later is required to compile php with cURL support</p>
<div class="cnblogs_code">
<pre>yum -y install libcurl libcurl-devel</pre>
</div>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p><br><br>
来源:https://www.cnblogs.com/xingxia/p/php-fpm_install_b.html
頁:
[1]