Home > Backend Development > PHP Problem > How to manually install the php runtime environment

How to manually install the php runtime environment

PHPz
Release: 2023-04-13 10:16:48
Original
849 people have browsed it

Currently, the mainstream installation of PHP operating environment on the market is installed through software package tools, cloud platform management tools, one-click installation packages, etc. However, sometimes we want to manually install the PHP operating environment for a better understanding. PHP working principle and the details of interactive communication with the server. Here's how to manually install the PHP running environment.

  1. Prepare dependent installation packages

Before installing PHP, you need to install some dependent packages, such as web servers, databases, development tools, etc. Common web servers include Apache and Nginx, databases include MySQL, SQLite, etc., and development tools include Vim, Emacs, etc. We can use the system's own package manager to install, or we can download the installation package from the official website and install it manually.

  1. Download the PHP compressed package

Download the required PHP compressed package from the PHP official website https://www.php.net/downloads.php and select Web Server compatible version. Usually, two versions of Apache and Nginx are provided. It should be noted that different versions have different configuration and compilation options. If you choose the wrong one, PHP will not be able to run.

  1. Decompress the PHP compressed package

Decompress the downloaded PHP compressed package and execute the following command:

tar -xzvf php-x.y.z.tar.gz
Copy after login

Among them, x.y.z is the PHP version number, after decompression You will get a directory of php-x.y.z.

  1. Configure compilation options

After entering the php-x.y.z directory, execute the following command to configure:

./configure --prefix=/usr/local/php [--with-apxs2=/usr/local/apache/bin/apxs]
Copy after login

Among them, ./configure is the execution configuration Script, --prefix specifies the installation directory, --with-apxs2 specifies the APXS path of Apache. If you use Nginx as the web server, you do not need to specify this option.

When executing the above command, you may be prompted that relevant dependencies are missing and you need to install them according to the prompts.

  1. Compile and install PHP

After the configuration is completed, execute the following command to compile and install:

make
make install
Copy after login

The make command is used to compile the source code, make install The command is used to install the compiled files to the specified location.

  1. Configuring PHP

After PHP is installed, some configuration is required to run properly. First, enter the bin directory under the PHP installation directory and execute the following command:

cp php.ini-development /usr/local/php/lib/php.ini
Copy after login

Rename php.ini-development to php.ini and copy it to the PHP configuration directory.

Secondly, add the following directive to the web server's configuration file (such as Apache's httpd.conf):

AddType application/x-httpd-php .php
Copy after login

This directive tells the web server to use the file with the suffix php as a PHP script deal with.

Finally, start the web server and access the PHP file. If the page can display PHP information normally, it means that the manual installation of the PHP running environment is successful.

This article introduces the method and process of manually installing the PHP running environment. It requires a certain knowledge of Linux system and compilation and is suitable for use in development and debugging environments. In a production environment, you can use one-click installation packages to quickly build a PHP operating environment to improve efficiency and security.

The above is the detailed content of How to manually install the php runtime environment. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template