How to successfully compile and install Nginx and PHP

PHPz
Release: 2024-02-27 18:44:02
Original
1233 people have browsed it

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
    Copy after login
  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
    Copy after login

    Configure compilation options and compile and install:

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

    After the installation is completed, start Nginx:

    /usr/local/nginx/sbin/nginx
    Copy after login
  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
    Copy after login

    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
    Copy after login

    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
    Copy after login

    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;
    }
    Copy after login

    Restart Nginx:

    /usr/local/nginx/sbin/nginx -s reload
    Copy after login

    Run PHP:

    /usr/local/php/bin/php -v
    Copy after login

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!

Related labels:
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