search
HomeBackend DevelopmentPHP ProblemHow 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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
ACID vs BASE Database: Differences and when to use each.ACID vs BASE Database: Differences and when to use each.Mar 26, 2025 pm 04:19 PM

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

PHP Secure File Uploads: Preventing file-related vulnerabilities.PHP Secure File Uploads: Preventing file-related vulnerabilities.Mar 26, 2025 pm 04:18 PM

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

PHP Input Validation: Best practices.PHP Input Validation: Best practices.Mar 26, 2025 pm 04:17 PM

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

PHP API Rate Limiting: Implementation strategies.PHP API Rate Limiting: Implementation strategies.Mar 26, 2025 pm 04:16 PM

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

PHP Password Hashing: password_hash and password_verify.PHP Password Hashing: password_hash and password_verify.Mar 26, 2025 pm 04:15 PM

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.OWASP Top 10 PHP: Describe and mitigate common vulnerabilities.Mar 26, 2025 pm 04:13 PM

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

PHP XSS Prevention: How to protect against XSS.PHP XSS Prevention: How to protect against XSS.Mar 26, 2025 pm 04:12 PM

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

PHP Interface vs Abstract Class: When to use each.PHP Interface vs Abstract Class: When to use each.Mar 26, 2025 pm 04:11 PM

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools