Home >Operation and Maintenance >Linux Operation and Maintenance >How to install PHP separately in Linux system

How to install PHP separately in Linux system

王林
王林forward
2023-05-12 11:04:13971browse

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 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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete