Home > Article > Backend Development > How to install PHP separately in Linux system
With the continuous development of modern software development, the applications and services of Linux systems are becoming more and more diverse. PHP is a widely used open source server-side scripting language. It is widely used in web development, including web page production, dynamic content generation, web applications, etc. In many cases, PHP needs to be used with other software, so correctly installing PHP is crucial to system stability and security. This article will introduce in detail how to separately install PHP in a Linux system.
1. Download PHP and its extension library
First download the PHP compressed package on the official website and download the corresponding version. Some common extension libraries can be obtained on the official website, including mysql, gd, zip, etc. It should be noted that its version should match the PHP version, otherwise problems such as incompatibility may occur.
2. Install dependencies
Before installing PHP, you need to ensure that some dependencies have been installed. You can use the following command:
Under Ubuntu/Debian:
sudo apt-get install build-essential libxml2-dev libbz2-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libssl-dev libmcrypt-dev libreadline-dev libxslt1-dev
CentOS Next:
sudo yum install epel-release
sudo yum install gcc make autoconf libc-dev pkg-config libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel openssl-devel mcrypt-devel readline-devel libxslt-devel
Among them, CentOS needs to install the epel source first before using sudo yum install to install dependencies.
3. Decompression and configuration
Extract the downloaded PHP compressed package to the directory of your choice and configure php.ini. You can copy the php.ini-development file to php.ini file to achieve.
After decompressing PHP, enter the PHP directory and execute the following command:
./configure --prefix=/usr/local/php --with-config-file-path=/usr /local/php/etc --with-bz2 --with-curl --with-freetype-dir=/usr/local/freetype --with-png-dir --with-jpeg-dir --with-gd - -with-iconv-dir=/usr/local/libiconv --with-zlib --with-gettext --with-openssl --with-mhash --enable-ftp --enable-mbstring --enable-mysqlnd -- with-mysqli --with-pdo-mysql --with-openssl
Note: The above commands are for reference only. In actual situations, you need to adjust them according to your own Linux version and PHP version.
4. Compilation and installation
Execute the make command to compile. The specific command is:
make && make install
This step may take some time. It depends on your hardware configuration. After the final installation, you can view related files in the target directory.
5. Configuration
After installing PHP, you need to configure the web server to work with PHP. Copy the PHP configuration file (php.ini) to the /etc directory under the installation directory.
Modify apache's http.conf configuration file and add the following code to it:
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
6. Test
Start the Apache server, create a new index.php file in the web root directory, and write the following code:
phpinfo() ;
?>
After saving, visit the index.php file in the browser. If you can see PHP related information, it proves that PHP is installed successfully.
7. Install extension libraries
If you need to use some extension libraries, you can install them with the following command:
sudo apt-get install php5-mysql php5-curl php5 -gd
or
sudo yum install php-mysql php-curl php-gd
After the installation is complete, you need to restart the Apache server.
The above are the detailed steps on how to install PHP separately under Linux system. Note that during the installation process, you need to pay close attention to the accuracy of the corresponding commands and ensure version compatibility. By correctly installing PHP, we can easily use a variety of functions and develop more powerful web applications. I wish everyone a successful installation!
The above is the detailed content of How to install PHP separately in Linux system. For more information, please follow other related articles on the PHP Chinese website!