Common steps of Linux software source installation
- wget Download Compression Pack
- Unzip and enter the source directory
- ./configure Run Configuration Add Configuration constants (./configure--help)
- Make compilation
- Make install Installation
Source code Compilation install PHP download installation package
wget http://am1.php.net/get/php-7.2.4.tar.gz
wget [parameters] [URL]
wget instruction Introduction
Unzip the installation package and enter the source directory
tar -zxvf php-7.2.4.tar.gzcd php-7.2.4
Introduction to TAR Instructions
Configure configuration
- To view configure configuration parameters
./configure --help
- Specifying the installation directory
--prefix=/usr/bin/php
- Specify php.ini Storage Directory
--with-config-file-path=/usr/bin/php/etc
The default is LIB, and the configuration parameter specifies the INI for the CLI. FPM INI to be set in fpm.conf
Common errors in this step are the lack of installation dependent software such as GCC,AUTOCONFIG,LIBXML2, which can be prompted to install the corresponding dependent softwaresudo apt install xxx
Compile
make
A common mistake in this procedure is to report insufficient memory (virtual memory Exhausted:cannot-allocate memory), try to reset configure parameters, do not install FileInfo extensions, or set swap partitions
Installation
make install
Test whether the installation was successful
/usr/bin/php/bin/php -m
Add PHP to environment variables
sudo ~/.bashrcalias php7=/usr/bin/phpsource ~/.bashrc
This method adds PHP to the environment variable only for the current user, and is not for all users. If you want to add environment variables for all users, you need to modify them /etc/profile .
Add php.ini File
Of course, the above storage php.ini directory is not necessarily correct, php.ini stored in the directory depends on the configuration of configure parameters, so it is reasonable to execute
php -i | grep php.iniTo get the directory that should be stored
Source Compilation install PHP encountered the pit of lack of dependent software
- No GCC
sudo apt install gcc
- AutoConfig
sudo apt install autoconfig
- No LIBXML2.
sudo apt install libxml2-dev
In fact, if the error is missing LIBXML2 This software, not apt install libxml2 necessarily can be installed, because in your apt source, LIBXML2 's package may be called Libxml2-dev, so you can based on the error prompts to search for the package related to what is.
Does not take effect after configuring php.ini
In this case, it is usually because the location of the php.ini storage is incorrect. If the Configure is not set --with-config-file-path=Path , then the default is in the installation directory of the Lib directory, there are settings in the corresponding directory.
The php -i | grep php.ini php.ini should be stored in which directory, corresponding to the introduction of php.ini will be effective
Insufficient memory during compilation
Common to servers with less than 2G memory (Exhausted:cannot allocate memories)
There are two types of solutions:
-
Do not install FileInfo extensions
Because the FileInfo extension will be installed by default after 5.3, if your server memory is too small, you will report insufficient memory in the process of compiling. It can be resolved by re-setting the parameters of the./configure. --disable-fileinfo Of course, this method is not a cure. It is recommended that you also set up virtual memory to resolve
-
Configure virtual memory (Swap partition)
Use free to view memory informationfree
Using sudo swapon -s view to swap partition information
To set virtual memory steps:
创 建 swap 文 件cd /varsudo dd if=/dev/zero of=swapfile bs=1024 count=2048000sudo mkswap swapfile激 活sudo chmod 600 swapfilesudo swapon swapfile开 机 自动 创建sudo vim /etc/fstab/swapfile none swap sw 0 0
Source code Compilation Install PHP extension
Download the installation package
wget
Enter the source directory
cd
Execute Phpize (under the bin directory in the PHP directory) to generate the Configure file
/usr/bin/php/bin/phpize
Execute Configure setup parameters
./configure --with-php-config=/usr/bin/php/bin/php-config
Compiling the installation
make && make install
Other one-click installation method:
- Apt Install
- Pecl Install (/USR/BIN/PHP/BIN/PECL)
Source Code Compilation Installation PHP7