Home > Article > Backend Development > Dynamically compile and add php module, compile php module_PHP tutorial
Note: Please indicate the source for reprinting: http://www.programfish.com/blog/?p=85
Many times when we build a web server in Linux, we need to compile and install the PHP package. After compilation and installation, we may need to add some modules that were not specified to be compiled during compilation and installation, such as the following situation:
Mysql.so or mysqli.so, mbstring.so zlib.so and other modules.
Here’s a reminder:
If you have installed phpmyadmin and the homepage is blank after installation and configuration, then it is very likely that your php does not have the mysql and mbstring modules.
Also, when installing the wordpress plug-in online, it prompts that there is no zlib plug-in because there is no zlib.so module in your php environment.
The above is what the author has experienced, and I hope it can be helpful to solve your problem.
Okay, now let’s get to the point, dynamically compile and add the php module:
Please note that this blog post only discusses the Linux environment where PHP has been installed.
If you don’t want to add modules dynamically but want to reinstall the php environment, please go to:
Php environment installation under Linux: http://www.cnblogs.com/fly1988happy/archive/2011/12/14/2288096.html
At this time you need to save the php source code used when compiling and installing php. If not, you can go to http://cn2.php.net/downloads.php to download the source code package that is the same as the PHP version you have installed (the version here should be the same or close to it. Different versions may cause discomfort. match).
You also need to know where your php is installed, because you will need to use the /bin/phpize tool in the installation directory later.
If you don't know where your php directory is installed, you can use the find command to find where the phpize file is.
lfly@Dynamically compile and add php module, compile php module_PHP tutorial-oj9e:~> sudo find / -name phpize
Here I find that my php is installed under /php.
Okay, here I download a source code package of php-5.5.18.tar.gz.
After downloading, use tar -zxvf to decompress it. (Only for .tar.gz compressed packages)
lfly@Dynamically compile and add php module, compile php module_PHP tutorial-oj9e:~/temp> tar -zxvf php-5.5.18.tar.gz
After decompression, you will get a php-5-5-18 folder
Then cd into the ext directory inside that directory:
lfly@Dynamically compile and add php module, compile php module_PHP tutorial-oj9e:~/temp> cd php-5.5.18/ext
You can see many folders after using the ls command to list files:
These are the source directories of the modules you want to compile. Here I assume that what we want to compile is the mysql module, then we cd into the mysql directory. If you want to compile other modules, then cd into the corresponding module.
lfly@Dynamically compile and add php module, compile php module_PHP tutorial-oj9e:~/temp/php-5.5.18/ext/mysql> /php/bin/phpize
After Cd is entered, we call the phpize script mentioned above.
What is the Phpize script?
Mention it here:
Phpize can be understood as the role of reconnaissance environment. The phpize tool will generate the corresponding configure file based on the configuration of PHP you have installed.
After executing this command, you may be prompted that the autoconf program is not installed. If so, you must install the software before running this command.
I have no problem here:
After Phpize runs without problems, use ./configure –with-php-config=/php/bin/php-config
Here /php/bin/php-config should be replaced with your Php installation directory. For example, if it is /usr/local/aaa, then you can set it to /usr/local/aaa/bin/php-config
If no error is reported after executing this step, execute the make command.
If no error is reported when executing the make command, then execute the make install command.
I found an error when making install here, because ordinary users do not have permission to install compiled modules into the PHP installation directory.
At this time, you can use sudo to execute the make install command or directly switch to the root user for execution. You need to enter your password during execution.
After Make install is successfully installed, there are two things to do:
One is: Add a sentence in the php.ini configuration file:
extension=mysql.so
It is assumed here that the mysql module is compiled. If it is other, use other module names.
For example:
If you don’t know the name of the module you just compiled, you can check it in the module directory of php:
I have compiled and installed 4 modules here.
Note: Please indicate the source for reprinting: http://www.programfish.com/blog/?p=85
The second thing is to restart your apache. (If you install apache to provide web services)