Home >Backend Development >PHP Problem >linux php source code installation

linux php source code installation

WBOY
WBOYOriginal
2023-05-24 18:42:37762browse

PHP source code installation under Linux

When using the Linux operating system, when you need to use PHP, you will generally choose to install the PHP source file. Let's introduce how to install PHP source code under Linux.

Step One: Preparation

Before installing the PHP source code, you need to do some preparation work. First, you need to install development environments such as Apache and MySQL on the Linux system, and you also need to install some necessary development tools, such as gcc, make, etc. These tools can be installed through the package manager that comes with the Linux system. For example, in a Debian/Ubuntu system, you can install it through the following command:

sudo apt-get install apache2 mysql-server gcc make

Step 2: Download the PHP source code

After completing the necessary preparations, you need to go to the official website to download the latest version of PHP source code. You can download the latest stable version through the download page of the PHP official website (https://www.php.net/downloads.php). After downloading, you can save it to a directory in the Linux system, such as /home/user.

Step 3: Unzip the source code

Extract the downloaded PHP source code file to the specified directory. For example, we unzip it to the /home/user/php-7.4.7 directory:

cd /home/user
tar -xzvf php-7.4.7.tar.gz

Step 4: Compile and install

After completing the decompression operation, you need to enter the decompressed source code directory to compile and install. Enter the source code directory:

cd /home/user/php-7.4.7

Then execute the configure command, which is used to generate the Makefile file:

. /configure --prefix=/usr/local/php

where --prefix=/usr/local/php means to install PHP to the /usr/local/php directory.

After executing the configure command, if there are no errors, the Makefile will be generated in the current directory, and then compiled:

make

After the compilation is completed, you can use Make test command to test whether PHP is compiled correctly. If there is no problem, you can install it:

sudo make install

At this point, the installation of PHP source code is basically completed. We can use the php -v command to test whether PHP has been successfully installed.

Step 5: Configure PHP

After completing the installation of the PHP source code, you need to perform some configurations on PHP. You can find the default php.ini file, usually under the /usr/local/php/lib/php.ini path in the installation directory. You can configure PHP related parameters by modifying this file.

For example:

Modify the time-related configuration:

date.timezone = Asia/Shanghai

Enable a certain function:

extension=php_mysql.so

After modifying the configuration, you need to restart the Apache server to make the new configuration take effect:

sudo service apache2 restart

Summary:

Through these five basic operations, you can complete the compilation and installation of PHP source code under Linux, and perform basic configuration of PHP. If you need to know more about Linux and PHP, you can consult relevant literature or seek help in the community.

The above is the detailed content of linux php source code installation. 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