First recommend an article PHP 7 Release Date Arrived: Will Developers Adopt PHP 7? - PHP Classes blog.
It talks about whether I will use PHP7. Personally, I will use it without hesitation, but I don’t have the final say in the production environment, so I can only update the PHP version in my own development environment. . So, what about you?
The author is using the openSUSE42.1 distribution of Linux. There is no installation package for PHP7 in Yast, so I can only compile and install it manually. As a PHP developer, I really hope to learn how to compile and install PHP7. I have tried it several times before, but every time I install it, I have to go online to find various information. So, after the successful installation this time, I want to go through my own installation process. And record the problems encountered so that you can refer to them later and share them with those who need them.
Getting to the point, to compile and install PHP7, you must first download the source code of PHP7. You can clone it on github or download it from the PHP official website. After downloading, extract it to the /usr/local/src directory and rename the directory to php7. Enter the directory.
./buildconf
./<span>configure \ </span>--prefix=/usr/local/<span>php7 \ </span>--exec-prefix=/usr/local/<span>php7 \ </span>--bindir=/usr/local/php7/<span>bin \ </span>--sbindir=/usr/local/php7/<span>sbin \ </span>--includedir=/usr/local/php7/<span>include \ </span>--libdir=/usr/local/php7/lib/<span>php \ </span>--mandir=/usr/local/php7/php/<span>man</span><span> \ </span>--with-config-<span>file</span>-path=/usr/local/php7/<span>etc \ </span>--with-mysql-sock=/var/run/mysql/<span>mysql.sock \ </span>--with-mcrypt=/usr/<span>include \ </span>--with-<span>mhash \ </span>--with-<span>openssl \ </span>--with-mysqli=<span>shared,mysqlnd \ </span>--with-pdo-mysql=<span>shared,mysqlnd \ </span>--with-<span>gd \ </span>--with-<span>iconv \ </span>--with-<span>zlib \ </span>--enable-<span>zip</span><span> \ </span>--enable-inline-<span>optimization \ </span>--disable-<span>debug \ </span>--disable-<span>rpath \ </span>--enable-<span>shared \ </span>--enable-<span>xml \ </span>--enable-<span>bcmath \ </span>--enable-<span>shmop \ </span>--enable-<span>sysvsem \ </span>--enable-<span>mbregex \ </span>--enable-<span>mbstring \ </span>--enable-<span>ftp</span><span> \ </span>--enable-gd-native-<span>ttf \ </span>--enable-<span>pcntl \ </span>--enable-<span>sockets \ </span>--with-<span>xmlrpc \ </span>--enable-<span>soap \ </span>--without-<span>pear \ </span>--with-<span>gettext \ </span>--enable-<span>session \ </span>--with-<span>curl \ </span>--with-jpeg-<span>dir</span><span> \ </span>--with-freetype-<span>dir</span><span> \ </span>--enable-<span>opcache \ </span>--enable-<span>fpm \ </span>--disable-<span>cgi \ </span>--with-fpm-user=<span>nginx \ </span>--with-fpm-group=<span>nginx \ </span>--without-<span>gdbm \ </span>--disable-fileinfo
Parameter description
<p>prefix PHP7安装的根目录</p> <p><em id="__mceDel">with-config-file-path PHP7的配置文件目录</em></p>
The result after executing the above configuration command is as shown below:
When executing the above command, you will encounter some prompts about missing dependencies. The dependency problems I encountered are listed below:
Error:
configure: error: xml2-config not found. Please check your libxml2 installation.
Solution:
zypper <span>install</span> libxml2-devel
Error:
configure: WARNING: unrecognized options: --with-mysql
Solution:
取消这个选项,这个选项是不存在的
Error:
configure: error: jpeglib.h not found.
Solution:
zypper <span>install</span> libjpeg-devel
Error:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Solution:
zypper <span>install</span> libmcrypt-devel
Error:
checking <span>for</span><span> recode support... yes configure: error: Can not </span><span>find</span> recode.h anywhere under /usr /usr/local /usr /opt.
Solution:
zypper <span>install</span> librecode-devel
In general, when configuring, if you encounter something that is not available, open Yast and search for it. If it exists, install it, and then recompile to see what else is needed. If you can’t find it in Yast, then search online on Google .
<span>make</span> && <span>make</span> <span>install</span>
<p>其中,make之后可以选择make test。只是一个可选步骤,不执行不知道有什么问题,不过笔者暂时还没遇到。</p>
After successful compilation and installation, check the PHP7 installation directory `ls /usr/local/php7`:
<span>cp</span> /usr/local/src/php7/php.ini-production /usr/local/php7/etc/<span>php.ini </span><span>cp</span> /usr/local/src/sapi/fpm/init.d.php-fpm /etc/init.d/php-<span>fpm </span><span>cp</span> /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-<span>fpm.conf </span><span>cp</span> /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
Add
to the last line of the /etc/profile fileexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
Then execute source /etc/profile
<span>mkdir</span> -p /var/log/php-fpm/ && <span>mkdir</span> -p /var/run/php-fpm && cd /var/run/ && <span>chown</span> -R nginx:nginx php-fpm
<span>chmod</span> +x /etc/init.d/php-<span>fpm chkconfig php</span>-fpm on
<p>可以用chkconfig命令查看开机启动服务列表。</p>
service php-fpm start
Check whether PHP is started successfully through ps aux | grep 'php'
At this point, PHP7 has been installed successfully, and you can start using PHP7!