linux - How to compile and install official php7 on ubuntu?

WBOY
Release: 2016-08-04 09:19:20
Original
776 people have browsed it

After all, when learning PHP, you still need to learn the bottom layer, but I have forgotten all about C for a long time. Please help me how to compile the official PHP7, http://php.net/downloads.php#...

Reply content:

After all, when learning PHP, you still need to learn the bottom layer, but I have forgotten all about C for a long time. Please help me how to compile the official PHP7, http://php.net/downloads.php#...

I'm bored, I just compiled it, I'll write about the process.

<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>
Copy after login

If there is an error about missing something in ./configure below, just add lib-dev(el) to the above command

<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>
Copy after login

Then we start compiling. Note that the memory of the compilation machine must be large. The initial 1G of my virtual machine was not enough, so I adjusted it to 4G

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

Then install

<code>sudo make install</code>
Copy after login

Install php7 into the directory specified by the prefix above, which is /opt/php-7.0.9/

Run cli to see the version number and information:

<code>/opt/php-7.0.9/bin/php -v
/opt/php-7.0.9/bin/php -i</code>
Copy after login

Before running the php-fpm service, you need to put the relevant configuration files in place:

<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>
Copy after login

Modify the port that fpm listens on:

<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>
Copy after login

Then start the service sudo /opt/php-7.0.9/sbin/php-fpm

Finally used in nginx configuration

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

That’s it.

If you use 16.04 LTS, come with the PHP7 software package

If you search on the Internet for Linux compilation of PHP, there will be many results. ./configure --help will get a parameter list.
I compiled the PHP beta version several times when it came out. Some extensions, such as curl, gd, iconv, json, mbstring, mysqlnd, and pdo, are must-install, otherwise many programs will have problems.

It’s better to compile it yourself. I suffer a lot from apt-get. The software package is so old that it hasn’t been repaired for a long time when bugs were reported

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template