Home >Backend Development >PHP Tutorial >How to compile and install PHP7 under openSUSE42.1, _PHP tutorial
First of all, I 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.
Download the source code and unzip it
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.
Configure compilation parameters
Generate configuration file
./buildconf
Configuration
./configure \ --prefix=/usr/local/php7 \ --exec-prefix=/usr/local/php7 \ --bindir=/usr/local/php7/bin \ --sbindir=/usr/local/php7/sbin \ --includedir=/usr/local/php7/include \ --libdir=/usr/local/php7/lib/php \ --mandir=/usr/local/php7/php/man \ --with-config-file-path=/usr/local/php7/etc \ --with-mysql-sock=/var/run/mysql/mysql.sock \ --with-mcrypt=/usr/include \ --with-mhash \ --with-openssl \ --with-mysqli=shared,mysqlnd \ --with-pdo-mysql=shared,mysqlnd \ --with-gd \ --with-iconv \ --with-zlib \ --enable-zip \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-xml \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-mbregex \ --enable-mbstring \ --enable-ftp \ --enable-gd-native-ttf \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-curl \ --with-jpeg-dir \ --with-freetype-dir \ --enable-opcache \ --enable-fpm \ --disable-cgi \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --without-gdbm \ --disable-fileinfo
Parameter description
prefix root directory of PHP7 installation
with-config-file-path PHP7 configuration file directory
The result after executing the above configuration command is as shown below:
During the execution of 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 install libxml2-devel
Error:
configure: WARNING: unrecognized options: --with-mysql
Solution:
Cancel this option, this option does not exist
Error:
configure: error: jpeglib.h not found.
Solution:
zypper install libjpeg-devel
Error:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Solution:
zypper install libmcrypt-devel
Error:
checking for recode support... yes
configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.
Solution:
zypper install 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 .
Compile and install PHP7
make && make install
Among them, you can choose make test after make. It's just an optional step. I don't know if there will be any problems if you don't execute it, but I haven't encountered it yet.
View the PHP7 directory after successful installation
After successful compilation and installation, check the PHP7 installation directory `ls /usr/local/php7`:
Set up PHP7 configuration file
cp /usr/local/src/php7/php.ini-production /usr/local/php7/etc/php.ini
cp /usr/local/src/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
Set environment variables
Add
to the last line of the /etc/profile file
export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
Then execute source /etc/profile
Set the PHP log directory and php-fpm process file (php-fpm.sock) directory
mkdir -p /var/log/php-fpm/ && mkdir -p /var/run/php-fpm && cd /var/run/ && chown -R nginx:nginx php-fpm
Set PHP to start at boot
chmod x /etc/init.d/php-fpm
chkconfig php-fpm on
You can use the chkconfig command to view the list of startup services.
Start PHP service
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!
The above describes how to compile and install PHP7 under openSUSE42.1. I hope you like it.