[Openwrt Project Development Note]:php+nginx installation (vii)

Source: Internet
Author: User
Tags apc log log

In the previous section, we have built the MySQL database, so in this section, I mainly explain the installation of PHP, as well as the PHP operating environment Nginx installation. Reference (http://www.right.com.cn/forum/thread-89216-1-1.html)

One, PHP installation

1. Install the PHP package.

OPKG Update
opkg Install php5 php5-mod-apc opkg install php5 opkg install php5 opkg install php5-mod- C6>PHP5

In the list above, I have installed a lot of PHP extension support, these packages can be added according to their own needs, not all of the PHP expansion pack needs to be installed.

Here, I cite a few more important extensions:

php5: This needless to say, PHP's main framework package, the software does not install, the following other packages are useless.

PHP5-MOD-APC: Alternative PHP cache (APC) is a valid open source Cache tool for PHP that caches opcode PHP intermediate codes. By installing APC, you can greatly speed up website access.

php5-mod-mysql / php-mod-pdo / php5-mod-pdo-mysql: These are necessary to use MySQL.

php5-mod-cgi/php5-mod-fastcgi: The key to web interaction.

php5-mod-xml: XML parsing

Php5-mod-json: JSON support

If you feel that you have enough space, you can install all PHP5-related packages once and for all (not recommended):

opkg updateopkg Install php5*

2. Configure PHP

After the installation of the PHP package, a php.ini file is generated in/etc, which is the PHP configuration file. We can make the necessary configuration according to our own needs. Modify PHP.ini:

Short_open_tag =on#如果php显示 ' not found ', the following line is commented #doc_root="/mnt/sda3/www" #在Dynamic The extension section, remove the annotations for the extensions we need to add ";"extension=ctype.soextension=curl.soextension=gd.soextension=mbstring.soextension=mcrypt.soextension=mysql.soextension=pdo.soextension=pdo_mysql.soextension=session.soextension=sockets.soextension=tokenizer.soextension=Xml.so[date]#修改时区date.timezone= asia/Chongqing[mysql]#修改MySQL的设置mysql.default_socket= /var/run/mysqld.sock

Tips: When you modify the time zone, you need to add zoneinfo, that is, the package zoneinfo-asia.opkg and zoneinfo-core.opkg mentioned earlier, if you do not add support, after the change will be an error.

I use the backfire inside is not with the above two packages.

Second, Nginx installation

1. Installing the Nginx Package

opkg updateopkg Install Nginx

2. Modify Nginx configuration file (/etc/nginx.conf)

Preparatory work:

(1) Create an nginx working directory:

Mkdir/mnt/sda3/www

(2) Add Nginx Users and user groups:

Opkg Install Shadow-useradd Shadow-groupadd

#添加用户组
Groupadd www
#添加用户到用户组www
Useradd-g www www
#将Nginx的工作目录绑定到www用户
Chown-r www:www/mnt/sda3/www

(3) Modify Nginx configuration file (/etc/nginx/nginx.conf):

The original Nginx configuration file is somewhat complex and splits it into different configuration files according to different functions:

User www www;#set user and user nameworker_processes1;#number of threads allowedPID/var/run/nginx.pid;#specify where the PID is storederror_log/var/Log/nginx_error.Log;#Specify the location of the Error.logEvents { UseEpoll; Worker_connections1024x768;#Specify the maximum number of connections}http {include MIME.types; Default_type Application/octet-stream; Access_log/var/Log/nginx/access.LogMain#Access.log Logsendfile on;    Tcp_nopush on; #keepalive_timeout 0;Keepalive_timeout $;    gzip on; Include Vhost. conf;#Server configuration file}

(4) Create the host configuration file under the/ect/nginx folder: vhost.conf

server {Listen       8000;#the original httpd monitoring Systemserver_name localhost; Root/mnt/sda3/www;#working directory of the website    Index  Index. htmlIndex. htmIndex. PHP Default.PHP; #Redirect Server error pages to the static page/50x.htmlError_page - 502 503 504/50x.html;#error page RedirectionLocation =/50x.HTML {root HTML; }    #Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000Location ~\.php$ {#passing PHP scripts to FastcgiserverFastcgi_pass127.0.0.1:9000;#FastCGI's serverFastcgi_indexIndex.PHP; Fastcgi_param Script_filename/mnt/sda3/www/$fastcgi _script_name;#parameters of the fastcgiInclude Fastcgi_params;#fastcgi specific configuration files    }}

(5) fastcgi specific configuration:/etc/nginx/fastcgi_param

#resolves an issue with file type resolution errorsif($request _filename~* (.*)\.PHP) {Set$php _url$1;}if(!-E$php _url.PHP) {        return 403;} Fastcgi_param query_string$query _string; Fastcgi_param Request_method$request _method; Fastcgi_param Content_Type$content _type; Fastcgi_param content_length$content _length; Fastcgi_param Script_name$fastcgi _script_name;#the parameters in the following comment: The script name, and its settings need to be noted. Pro-Test effective #fastcgi_param script_filename$document _root/$fastcgi _script_name; Fastcgi_param Script_filename/mnt/sda3/www/$fastcgi _script_name; Fastcgi_param Request_uri$request _uri; Fastcgi_param Document_uri$document _uri; Fastcgi_param Document_root$document _root; Fastcgi_param Server_protocol$server _protocol; Fastcgi_param gateway_interface CGI/1.1; Fastcgi_param server_software nginx/$nginx _version; Fastcgi_param remote_addr$remote _addr; Fastcgi_param Remote_port$remote _port; Fastcgi_param server_addr$server _addr; Fastcgi_param Server_port$server _port; Fastcgi_param server_name$server _name;#PHP only, required if PHP is built with--enable-force-cgi-redirectFastcgi_param Redirect_status $;

(6) Open Nginx Service:

The opening of the Nginx service is a bit of a hassle. The first thing to do is open the FASTCGI service:

127.0. 0.1 9000 2 -f/usr/bin/php-cgi

If you want to boot up, place the above instruction under the/etc/rc.local script

If you have exit 0 in Rc.local, remember to comment it out, or you won't start listening on port 9000. This problem has been a long time ...

Open Nginx Service

/etc/init.d/nginx enable/etc/init.d/nginx start

Third, Nginx+php+mysql test

Under the/mnt/sda3/www folder, place the following files for testing:

When testing, remember to combine nginx log files:

/var/log/nginx/acesss. log/var/log/nginx/error. Log

1, index.html (test nginx service is normal open)

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>This is a test file</title></Head><Body>    <span>This is a HTML file</span></Body></HTML>

Show Results:

2. index.php (used to test whether the fastcgi is working properly)

<? php    phpinfo (); ?>

Show Results:

3.1.php (test file name is interpreted as normal)

<? PHP     Echo Date ("Y-m-d h:i:s",Time());? >

V. Problems encountered, and solutions

1. Question: When testing whether the fastcgi is working, the page displays "No input file specified".

Solution: Looking for a variety of solutions on the Web, I will write some of my useful articles and share them with you:

(1) Fastcgi_param script_filename/scripts$fastcgi_script_name; Switch

Fastcgi_param script_filename $document _root$fastcgi_script_name; #经测试无效.

Then change: Fastcgi_param script_filename /mnt/sda3/www/$fastcgi _script_name; #/mnt/sda3/www The working directory for the site

(2) fastcgi:9000 port does not open properly

Use the following command:

Netstat-ant |grep 9000

Port 9000 is not turned on. This means that the FASTCGI service is not turned on. Open manually:

127.0. 0.1 9000 2 -f/usr/bin/php-cgi

The pro-test is effective.

The Ok:nginx+php+mysql development environment was successfully ported to the OpenWrt platform.

--------------------------------------------------------------------------

Trailer: The next chapter about VPN! (upon request of a classmate)

Reprint please indicate source: htttp://www.cnblogs.com/double-win/Thank you!

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.