Home > Article > Operation and Maintenance > How to compile and install PHP in Linux system
Before compiling and installing PHP, first make sure that some necessary compilation environments have been installed in the system. This includes the GNU Compiler Collection (GCC) and the make tool. Install on Ubuntu using the following command:
sudo apt-get update sudo apt-get install build-essential
For other Linux distributions, you will need to use an appropriate package manager.
The source code of PHP can be downloaded from its official website (http://php.net/downloads.php). Select the latest version of the source code and download it to your computer. Next, unzip the downloaded file using the following command:
tar -zxvf php-x.x.x.tar.gz
After unzipping, you will get a directory named "php-x.x.x", where "x.x.x" is the PHP version number. Enter this directory to continue.
Before compiling PHP, you need to configure some options for it. This will ensure that PHP is compiled with the required features and extensions. Use the following command to configure PHP:
./configure --prefix=/path/to/install/dir [options]
In this command, "/path/to/install/dir" is the directory where you wish to install PHP. You can change this option as needed. It is also possible to add other options such as "--with-mysql" to support MySQL databases.
After completing the configuration, you need to compile PHP. Use the following command to compile:
make
The process may take a few minutes to complete.
After compilation is completed, you can use the following command to install PHP:
sudo make install
This command will install the PHP binary files and other related files into the directory you specify. After this, you can check if PHP has been installed correctly by running the following command:
/path/to/install/dir/bin/php -v
This command will display the installed PHP version number. If it's the version you expected, the installation is complete!
The above is the detailed content of How to compile and install PHP in Linux system. For more information, please follow other related articles on the PHP Chinese website!