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. To put it simply, there are only 3 steps to compile PHP7: 1. ./buildconf --force 2. ./configure 3. make make install Steps 1 and 3 are nothing to worry about. Configure is the key to compilation and involves
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:
1. ./buildconf --force
2. ./configure
3. make && make install
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:
curl
gd
fpm
mysqlnd
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 style="color: #800080;">0</span> --enable-mbstring --with-curl --with-gd --with-config-<span style="color: #0000ff;">file</span>-path=/apps/php/php7.<span style="color: #800080;">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:
--start Start
--stop force termination
--quit smooth termination
--restart Restart
--reload smoothly reloads php’s php.ini
--logrotate Re-enable log file
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 style="color: #0000ff;">grep</span> mysql
As you can see, PHP hopes to use mysqlnd to support MySQL, so the parameters can be written like this:
--enable-mysqlnd
--with-mysqli=mysqlnd
--with-pdo-mysql=mysqlnd
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:
--with-mysql-sock=/var/lib/mysql/mysql.sock
If that still doesn’t work, you can create a soft link to mysql.sock in the /tmp directory:
<span style="color: #0000ff;">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.