Non-mainstream configuration method for implementing nginx&php server Configuration _nginx

Source: Internet
Author: User
Tags md5 openssl php server php code php debugger phpinfo nginx server
Non-mainstream configuration method for implementing Php&nginx server Configuration
This method is not the previous popular Apache plus Php_module way to run, I was using Nginx as a Web server to fastcgi the way to run PHP.

Linux Compile:

Nginx I am still accustomed to choose version 8.54, its compilation relies on the following several packages, unzip these source packs, set up the path of these source code in configure, Nginx compile the time they will compile their own in:

Pcre: Mainly used for rewrite and other modules
Zlib: That's not to mention.
OpenSSL: If you also know https this thing, then you know ~ ~ ~ (Of course you can not need this function)
MD5/SHA1: Both are Syrah algorithms for generating information digests, these two things are not necessary, but I find that if you do not choose one, then OpenSSL will not be successfully compiled into Nginx
The following is a setup script that I wrote myself, and the compilation options with Temp-path typeface are set by the path of the temporary file Nginx at run time, Pid-path,lock-path is also the temporary file path, Log-path is the log file path, I have some permissions on the machine, so I want to set it. In general, these are not necessary, nginx by default will be all the generated files in their own installation directory.
Copy Code code as follows:

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 #pcre Source package path
--with-zlib= $zlib #zlib Source package path
--with-http_ssl_module #起用ssl支持
--with-openssl= $openssl #openssl Source package path
Make
Make install

PHP (5.2) can be more complex to compile, can also be simple, because we compile PHP when the main purpose is to compile its script engine and some core libraries, a lot of peripheral things do not have to be added in the compilation of PHP, you can compile them into an extension library when needed, and then modify the configuration file to load them.
My compiled code is as follows:
Copy Code code as follows:

./configure--prefix=/usr/local/php
--with-mysql=/usr/local/mysql #设置mysql的安装路径
--enable-fastcgi #开启fastcgi支持
--enable-debug #支持调试
Make
Make install

In fact, that a word about MySQL can not, but I am too lazy to compile a MySQL extension, so it directly compiled into PHP, the premise is that you must first install MySQL.
There are some caveats: when compiling PHP, you must make sure that you have LIBXML2 and Libxml-dev packages in the system, because PHP defaults to compile XML functionality, so XML support is essential. Another is autoconf this command, when compiling the extension, Phpize will invoke this command in the system to generate the expansion package configure file, you can not expand without it, this is also to be remembered, After all, Linux PHP does not compile all the extensions in advance, as Windows does.
As for the Windows under the installation of nginx,php is no difficulty, the next zip package, decompression can be used, as long as a little configuration can be.
Configuration:
If you just want PHP to work, enter the command directly:
./php-cgi-b 3344
This opens the PHP fastcgi process, the-b parameter is bound to the process of listening port, just find a useless port to fill it, here is bound to 3344.
Then add a few lines to the Nginx configuration file:
Copy Code code as follows:

Location ~. php$ {
root/home/jsckdao/www.3ppt.com; #这是你网站的根目录
Fastcgi_pass 127.0.0.1:3344; #这里指定了fastcgi进程侦听的端口, Nginx is here to interact with PHP.
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root/$fastcgi _script_name;
Include Fastcgi_params;
}

If you want to change the Nginx listening port to find "Listen" Such an item, the change is. Run Nginx, write a test file in the/home/jsckdao/www directory test.php:
Copy Code code as follows:

<?php
Phpinfo ();
?>

Access to http://localhost:8080/test.php, if the display of PHP so configuration information, then basically no problem, already can use this environment to write some PHP code.
As for PHP debugger I choose Xdebug, not why, the habit caused. When loading a xdebug, the wording in the configuration file seems to be different depending on the system. Linux is: Zend_extension_debug=<path>,window loaded in two types of DLLs, a filename will have a TS suffix, this should be like to write: Zend_extension_ts=<path > Another way:zend_extension=<path& gt;,path must write an absolute path. I'm not sure what TS means, but these settings are definitely not going to be wrong.
After you set it up, rerun the php-cgi, and then visit test.php again, and if there's a xdebug, it's a success.
Of course this is a very simple configuration, can only let you run PHP, to really make the development environment you need, you need to modify the PHP and Nginx configuration files according to your own needs, these configuration contents are many, I am also in the study, it is not much to say.
Another thing to note is that the PHP configuration file has two in its source code: Php.ini-dist and Php.ini-recommended, The configuration is for the build environment and the development environment respectively. You need to change one of the names to php.ini. To view the page of Phpinfo () after the reboot, there is a "loaded configuration file", which is the value of your php.ini path, Then no problem, if not, take a look at the above "configuration file (php.ini) path", You can move your php.ini file to this directory and restart it. Because PHP will find php.ini on this path by default. Of course you can also set your php.ini path when running php-cgi, such as:
Php-cgi-b 3344-c/home/jsckdao/php.ini
This is the/home/jsckdao/php.ini file as a 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.