Home >Backend Development >PHP Tutorial >How to successfully compile and install Nginx and PHP

How to successfully compile and install Nginx and PHP

PHPz
PHPzOriginal
2024-02-27 18:42:041243browse

How to successfully compile and install Nginx and PHP

How to successfully compile and install Nginx and PHP

Nginx is a high-performance web server that is often used to build websites and reverse proxy services. PHP, on the other hand, is a popular server-side scripting language used for developing dynamic web pages. This article will introduce the steps on how to successfully compile and install Nginx and PHP, and provide specific code examples. The following are detailed steps:

  1. Prepare the environment:
    Before starting the compilation and installation, ensure that the system has installed the necessary dependent libraries: gcc, make, pcre, zlib, openssl, libxml2, libjpeg, libpng, libmcrypt, etc.
    You can install these dependent libraries through the following commands:

    sudo apt-get install gcc make libpcre3-dev zlib1g-dev openssl libxml2-dev libjpeg-dev libpng-dev libmcrypt-dev
  2. Compile and install Nginx:
    First download the latest stable version of the Nginx source code package, unzip it and enter the directory:

    wget http://nginx.org/download/nginx-x.x.x.tar.gz
    tar -zxvf nginx-x.x.x.tar.gz
    cd nginx-x.x.x

    Configure compilation options and compile and install:

    ./configure --prefix=/usr/local/nginx --with-http_ssl_module
    make
    sudo make install

    After the installation is completed, start Nginx:

    /usr/local/nginx/sbin/nginx
  3. Compile and install PHP:
    Download the latest version of PHP Source code package, unzip and enter the directory:

    wget http://php.net/get/php-x.x.x.tar.gz/from/this/mirror
    tar -zxvf php-x.x.x.tar.gz
    cd php-x.x.x

    Configure compilation options and compile and install:

    ./configure --prefix=/usr/local/php --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-curl
    make
    sudo make install

    After the installation is completed, modify the Nginx configuration file and integrate the PHP parsing engine into Nginx:

    vim /usr/local/nginx/conf/nginx.conf

    Add the following code in the server configuration section:

    location ~ .php$ {
     root           html;
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
    }

    Restart Nginx:

    /usr/local/nginx/sbin/nginx -s reload

    Run PHP:

    /usr/local/php/bin/php -v

Through the above steps, You have successfully compiled, installed and integrated Nginx and PHP. In this way, you can build your own web server and run dynamic web content. Hope the above content is helpful to you!

The above is the detailed content of How to successfully compile and install Nginx and PHP. 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