Home  >  Article  >  Backend Development  >  unix installation php environment

unix installation php environment

WBOY
WBOYOriginal
2023-05-07 11:22:08446browse

It is quite common to use PHP when developing web applications. Installing the php environment in a Unix environment allows us to develop and test more conveniently. From source code installation to system package managers, this article will take you through the different methods of installing php on Unix systems.

  1. Installation through the system package manager

Most Unix distributions provide a package manager that makes it easy to install and upgrade software packages. Installing php using a package manager is also a very simple method.

  1. Debian/Ubuntu systems:
    Using the apt-get package manager, you can install PHP using the following command:

    sudo apt-get update
    sudo apt-get install php

  2. CentOS / Fedora system:
    Using the yum package manager, you can use the following command to install PHP:

    sudo yum install php

Note that this method installs the preconfigured PHP version of the system, which may not be the latest PHP version, so if you need to run the latest PHP application, you need to use other installation methods.

  1. Installation through source code

If you use source code to install the PHP environment, you need to download the latest PHP source code package and compile and install it. The following are the steps to install using source code:

  1. Necessary dependencies
    First you need to install dependent libraries, including the updated gcc compiler, as well as standard C libraries and development header files. Taking the Ubuntu system as an example, you can use the following command:

    sudo apt-get install gcc libpcre3-dev

CentOS or Fedora systems may require different commands. Please note that compiling on a standalone system requires installation of dependencies.

  1. Download source code
    The new version of PHP code can be downloaded from the official website and can be downloaded through the following command:

    cd /usr/local/src
    sudo wget https://www.php.net/distributions/php-8.0.3.tar.gz
    sudo tar -xzf php-8.0.3.tar.gz
    cd php-8.0.3

  2. Configuration, compilation and installation
    Execute the following command in the source code directory to configure:

    sudo ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --with-zlib
    sudo make
    sudo make install

here , the --prefix parameter will define the PHP installation path. The --with-apxs2 parameter compiles the Apache Portable Runtime (APR) and Apache XML/XSLT libraries into PHP binaries. --with-mysql and --with-zlib will compile with MySQL and zlib support.

  1. Configure PHP
    Installation configuration file:

    cd /usr/local/src
    sudo cp php-8.0.3/php.ini-production /usr/local/php/lib/php.ini

And configure the php.ini file, select the appropriate options for the configuration of the web server and PHP

  1. Use Docker to quickly install

Use Docker containers to quickly build a development environment or run php applications. System administrators or software developers simply install Docker on the host machine and pull the PHP container image from the public Docker Hub repository.

  1. Install Docker
    Install Docker and start the service. The installation methods are different for different Linux versions. Please refer to the official Docker installation documentation.
  2. Pull container image
    Execute the following command to pull the latest php container image from Docker Hub:

    sudo docker pull php

  3. Start container
    Execute the following command to start the php container:

    sudo docker run -p 80:80 -v $PWD:/var/www/html php

Among them, the -p parameter maps the host's port 80 to the container's port 80, and uses the -v parameter to associate the current directory with the container's /var/www/html directory, so that the PHP files in the container can be accessed on the host. .

Summary

There are several different ways to install the php environment on Unix systems. Use your system package manager to quickly install preconfigured versions of php. Installing from source provides more customization options, including the latest version of PHP code and the ability to compile more language modules. Docker containerization can quickly build a development environment or run php applications. Different methods have their own advantages and limitations, and you can choose according to your needs.

The above is the detailed content of unix installation php environment. 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