Nginx + PHP configuration

Source: Internet
Author: User
Tags php debugger php development environment

Configure a simple nginx + PhP Development Environment on Mac. For nginx, refer to the previous article. For PHP installation instructions, refer to this article.

Original article: http://www.cnblogs.com/jsckdao/archive/2011/05/05/2038265.html

After setting up the PHP environment for more than N times, there are many methods on the Internet, but there are always some discrepancies in actual operations. Many Errors often make me confused. after my illness became a doctor, I gradually summed up some experiences. I feel good about myself.

This method is not a popular method for running Apache with php_module. I use nginx as a web server and run php In FastCGI mode.

Compile in Linux:

Nginx I am still used to choosing version 8.54. Its compilation depends on the following software packages, decompress these source code packages, and set the source code paths in configure, during nginx compilation, they will be compiled by themselves:

PCRE: Mainly used for rewrite and other modules

Zlib: not to mention this.

OpenSSL: If you still know https, you know it ~~~ (Of course you do not need this function)

MD5/sha1: both of them are hiha algorithms used to generate information summarization. These two items are not necessary, however, I found that if one of them is not selected, OpenSSL will not be compiled into nginx

The following is an installation script written by myself. All the compilation options with the word temp-path are set to the path of the temporary file generated during nginx running, PID-path, lock-path is also a temporary file path, and log-path is a log file path. You need to set it because of some permissions on your machine. in general, these are unnecessary. By default, nginx stores all the generated files in its own installation directory.

TMP =/tmp/nginx

Log =/home/jsckdao/log

PCRE = ~ /Downloads/pcre-8.02

Zlib = ~ /Downloads/zlib-1.2.5-src

OpenSSL = ~ /Downloads/openssl-0.9.8q

MD5 = ~ /Downloads/md5-1.3.0

./Configure -- prefix =/usr/local/nginx \

-- Http-proxy-temp-path =$ {TMP}/nginx-proxy.tmp \

-- Http-FastCGI-temp-path =$ {TMP}/nginx-fcgi.tmp \

-- Http-uwsgi-temp-path =$ {TMP}/nginx-uwsgi.tmp \

-- Http-scgi-temp-path =$ {TMP}/nginx-scgi.tmp \

-- Http-client-body-temp-path =$ {TMP}/nginx-client.tmp \

-- PID-path =$ {TMP}/nginx. PID \

-- Lock-path =$ {TMP}/nginx. Lock \

-- Http-log-path =$ {log}/HTTP. log \

-- Error-log-path =$ {log}/http-error.log \

-- With-PCRE = $ PCRE \ # path of the PCRE source package

-- With-zlib = $ zlib \ # path of the zlib source package

-- With-http_ssl_module \ # Starting with SSL support

-- With-OpenSSL = $ OpenSSL # OpenSSL source package path

Make

Make install

PHP (5.2) Compilation can be complex or simple, because the main purpose of PHP compilation is to compile its Script Engine and some core libraries, many peripheral things do not have to be added during PHP compilation. You can compile them into extension libraries and modify the configuration files to load them as needed.

My compilation code is as follows:

./Configure -- prefix =/usr/local/PHP \

-- With-mysql =/usr/local/MySQL \ # Set the installation path of MySQL

-- Enable-FastCGI \ # enable FastCGI support

-- Enable-Debug # debugging supported

Make

Make install

In fact, the MySQL statement can be avoided, but I am too lazy to compile the MySQL extension again, so I will compile it directly into PHP, the premise is that you must install MySQL first.

Note: When compiling PHP, you must ensure that libxml2 and libxml2-dev are available in the system, because PHP will compile the XML function by default, therefore, XML support is essential. Another is the Autoconf command. when compiling the extension, phpize will call this command in the system to generate the configure file of the extension package. Without it, you cannot perform expansion, this is also worth remembering. After all, PHP in Linux has compiled all the extensions in advance, unlike in windows.

As for nginx under window, PHP installation is no longer difficult. The next zip package can be decompressed. You only need to configure it slightly.

Configuration:

If you only want PHP to run, enter the following command:

./PHP-CGI-B 3344

In this way, the FastCGI process of PHP is enabled. The-B parameter is used to bind the listening port of the process. You can simply enter a useless port. The port bound here is 3344.

Then add the following lines to the nginx configuration file:

Location ~ \. Php $ {

Root/home/jsckdao/WWW; # This is the root directory of your website

Fastcgi_pass 127.0.0.1: 3344; # specify the port on which the FastCGI process listens. nginx interacts with PHP here.

Fastcgi_index index. php;

Fastcgi_param script_filename $ document_root/$ fastcgi_script_name;

Include fastcgi_params;

}

If you want to change the listening port of nginx, find the "listen" option. Run nginx and write a test file test. php In the/home/jsckdao/WWW directory:

<? PHP

Phpinfo ();

?>

Access http: // localhost: 8080/test. php. If the configuration information of PHP is displayed, there is basically no problem. You can use this environment to write some PHP code.

I chose xdebug for the PHP debugger. When loading xdebug, the syntax in the configuration file may vary depending on the system. In Linux: zend_extension_debug = <path>. There are two types of DLL loaded in the window. One file name contains the suffix of TS. To do this, you need to write the following code: zend_extension_ts = <path> another method is as follows: zend_extension = <path>. The path must be an absolute path. Although I am not quite clear about the meaning of TS, these settings must not be wrong.

After the configuration, run php-CGI again, and then access test. php again. If the xdebug part appears, it will be successful.

Of course, this is a very simple configuration. It only allows you to run php. To make it into the development environment you need, you also need to modify the configuration files of PHP and nginx as needed, these configurations involve a lot of content and I am still learning them.

Note that the PHP configuration file contains two in its source code package: PHP. ini-Dist and PHP. ini-recommended, which is used to configure the production environment and development environment respectively. you need to rename one of them to PhP. ini. view the phpinfo () page after restart. There is a "loaded configuration file" on the top. If the value is your php. INI path, then there is no problem, if not, look at the above "configuration file (PHP. INI) path ", you put your php. the INI file can be moved to this directory and restarted. because PHP will search for PHP in this path by default. ini. of course, you can also set your php when running PHP-CGI. INI path, for example:

Php-CGI-B 3344-C/home/jsckdao/PHP. ini

In this way, the/home/jsckdao/PHP. ini file is used as the configuration file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.