I recently tried PHP7 and encountered some problems in compiling and supporting MySQL. I believe many students have encountered the same problem, so I will talk about the process here. Simply speaking, compiling PHP7 only requires 3 steps:
<p>1、./buildconf --force</p> <p>2、./configure</p> <p>3、make && make install</p>
There is nothing to worry about in steps 1 and 3. Configure is the key to compilation and involves PHP’s support for some libraries. Here we use the minimum support, including MySQL:
<p>curl</p> <p>gd</p> <p>fpm</p> <p>mysqlnd</p>
The reason why we use curl and gd as examples is to make it clear that these third-party libraries must be installed before compiling PHP. You can directly use yum to install them in the default location, or you can compile and install them to a specified location. After yum is installed, , there is no need to specify the installation location of the library when compiling. You can search for a lot about installing these libraries. Let’s take a look at the basic configure
./configure --prefix=/apps/php/php7.<span>0</span> --enable-mbstring --with-curl --with-gd --with-config-<span>file</span>-path=/apps/php/php7.<span>0</span>/etc/ --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd
Regarding fpm, I believe it goes without saying that using it to support PHP is a better choice. PHP5.3.3 has built-in php-fpm, so of course it is also available in PHP7. You only need to --enable-fpm. That’s it
php-fpm parameters:
<p>--start 启动</p> <p>--stop 强制终止</p> <p>--quit 平滑终止</p> <p>--restart 重启</p> <p>--reload 重新平滑加载php的php.ini</p> <p>--logrotate 重新启用log文件</p>
I’ll focus on this, because I spent a little time on it, and I don’t know which version it started from. PHP no longer wants to use the mysql library to support mysql connections. It has enabled mysqlnd to support it. I heard it is faster than libmysql. Many, PHP5.x can also use libmysql. PHP7 seems to have canceled the support. The --with-mysql parameter is not available in compilation. Only --with-mysqli and --with-pdo-mysql are supported. You can check the configure parameters. Come and find out:
./configure -help | <span>grep</span> mysql
As you can see, PHP hopes to use mysqlnd to support MySQL, so the parameters can be written like this:
<p>--enable-mysqlnd</p> <p>--with-mysqli=mysqlnd</p> <p>--with-pdo-mysql=mysqlnd</p>
mysqlnd does not require mysql support, so it can be compiled and passed without installing mysql first. Start php-fpm and check phpinfo. You can see that mysqlnd and pdo_mysql indicate that php can already support mysql (pdo is used here) , mysqli is the same)
This is the first time I encountered this problem. It turned out that my Alibaba Cloud server turned off swap and there was not enough memory, so I reported this error. The solution is very simple, just add the --disable-fileinfo parameter when configure.
As it said, it was indeed not found. Take a look at the pdo_mysql.default_socket item in phpinfo
Where is mysql.sock? Let’s take a look at the real location of mysql.sock. Use the command: ps -ef|grep mysql to view:
Obviously not in the same location, my correct location is: /var/lib/mysql/mysql.sock
So, modify php.ini, find pdo_mysql.default_socket, change it to your actual location, and restart php-fpm. Unfortunately, although php.ini has this configuration, after modification, it does not work. It is best to compile When, specify the location of mysql.socket:
<p>--with-mysql-sock=/var/lib/mysql/mysql.sock</p>
If that still doesn’t work, you can create a soft link to mysql.sock in the /tmp directory:
<span>ln</span> -s /var/lib/mysql/mysql.sock mysql.sock
Restart php-fpm again, I believe it is running normally. If you need more libraries supported by PHP, you can compile again and add the required support when configure, which is --with-xxx. Remember that if it is a third-party library, you must install these libraries first.