Heim  >  Artikel  >  Backend-Entwicklung  >  linux - ubuntu如何编译安装官方php7?

linux - ubuntu如何编译安装官方php7?

WBOY
WBOYOriginal
2016-08-04 09:19:20737Durchsuche

php学习终归还是要学习底层的,但是我c相关的早就忘光了,求助如何编译官方php7,http://php.net/downloads.php#...

回复内容:

php学习终归还是要学习底层的,但是我c相关的早就忘光了,求助如何编译官方php7,http://php.net/downloads.php#...

闲着无聊,刚刚编译了下,我写一下过程。

<code>wget http://cn2.php.net/get/php-7.0.9.tar.bz2/from/this/mirror

tar xvf mirror

cd php-7.0.9/

sudo apt-get update

sudo apt-get install libkrb5-dev \
libc-client2007e                 \
libc-client2007e-dev             \
libcurl4-openssl-dev             \
libbz2-dev                       \
libjpeg-dev                      \
libmcrypt-dev                    \
libxslt1-dev                     \
libxslt1.1                       \
libpq-dev                        \
libpng12-dev                     \
libfreetype6-dev                 \
build-essential                  \
git                              \
make</code>

如果下面的./configure爆出缺什么的错误,就在上面命令中加一条 lib-dev(el)

<code>./configure \
--prefix=/opt/php-7.0.9                      \
--with-config-file-path=/opt/php-7.0.9/etc   \
--with-zlib-dir                              \
--with-freetype-dir                          \
--enable-mbstring                            \
--with-libxml-dir=/usr                       \
--enable-soap                                \
--enable-calendar                            \
--with-curl                                  \
--with-mcrypt                                \
--with-zlib                                  \
--with-gd                                    \
--disable-rpath                              \
--enable-inline-optimization                 \
--with-bz2                                   \
--with-zlib                                  \
--enable-sockets                             \
--enable-sysvsem                             \
--enable-sysvshm                             \
--enable-pcntl                               \
--enable-mbregex                             \
--enable-exif                                \
--enable-bcmath                              \
--with-mhash                                 \
--enable-zip                                 \
--with-pcre-regex                            \
--with-pdo-mysql                             \
--with-mysqli                                \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-jpeg-dir=/usr                         \
--with-png-dir=/usr                          \
--enable-gd-native-ttf                       \
--with-openssl                               \
--with-fpm-user=www-data                     \
--with-fpm-group=www-data                    \
--enable-ftp                                 \
--with-imap                                  \
--with-imap-ssl                              \
--with-kerberos                              \
--with-gettext                               \
--with-xmlrpc                                \
--with-xsl                                   \
--enable-opcache                             \
--enable-fpm</code>

然后我们开始编译,注意编译机器的内存必须要大,我虚拟机最开始1G还不够,调到了4G

<code>make  #或者根据你当前正在编译机器cpu核数调参数加速编译,比如我虚拟机是2核 make -j2 就可以同时跑2个job加速编译,编译了差不多15分钟</code>

然后安装

<code>sudo make install</code>

把php7装到上面prefix指定目录,也就是/opt/php-7.0.9/下

跑下cli看看版本号与信息:

<code>/opt/php-7.0.9/bin/php -v
/opt/php-7.0.9/bin/php -i</code>

运行php-fpm服务前,需要把相关的配置文件放好:

<code>sudo mv /opt/php-7.0.9/etc/php-fpm.conf.default /opt/php-7.0.9/etc/php-fpm.conf
sudo mv /opt/php-7.0.9/etc/php-fpm.d/www.conf.default /opt/php-7.0.9/etc/php-fpm.d/www.conf
sudo cp ./php.ini-production /opt/php-7.0.9/etc/php.ini</code>

修改fpm监听的端口:

<code>sudo vi /opt/php-7.0.9/etc/php-fpm.d/www.conf
>;listen = 127.0.0.1:9000
>listen = /var/run/php7.0.9-fpm.sock</code>

然后启动服务 sudo /opt/php-7.0.9/sbin/php-fpm

最后在nginx配置里用

<code>fastcgi_pass   unix:/var/run/php7.0.9-fpm.sock;</code>

就可以了。

如果你用16.04 LTS,就自带PHP7软件包

这个在网上搜Linux编译PHP都会有很多结果吧,./configure --help就能得到一个参数列表。
PHP测试版出来的时候我编译过好几次了,有些扩展,比如curl,gd,iconv,json,mbstring,mysqlnd,pdo这些是必装的,不然很多程序会出问题。

还是自己编译好,我是深受apt-get的害,特么软件包老的要死,报洞的时候很久都没修

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn