[Openwrt Project Development Notes] series of article portals: www.cnblogs.comdouble-winp3888399.html body: in the previous section, we have built a MySQL database, so in this section, I will mainly explain the installation of php and the installation of Nginx in the php runtime environment. See (www.right.com. cnforumth
[Openwrt Project Development Notes] series of article portals: http://www.cnblogs.com/double-win/p/3888399.html body: in the previous section, we have built a MySQL database, so in this section, I will mainly explain the installation of php and the installation of Nginx in the php runtime environment. Reference (http://www.right.com.cn/forum/th
[Openwrt Project Development Notes] Article series Portal: http://www.cnblogs.com/double-win/p/3888399.html
Body:
In the previous section, we have set up a MySQL database. Therefore, in this section, I will mainly explain how to install php and install Nginx in the php runtime environment. Reference (http://www.right.com.cn/forum/thread-89216-1-1.html)
I. PHP installation
1. Install the php software package.
opkg update
opkg install php5 php5-mod-apc opkg install php5-mod-gd php5-mod-session opkg install php5-mod-pdo-mysql php5-mod-pdo php5-mod-mysql opkg install php5-mod-mcrypt php5-mod-mbstring php5-fastcgi php5-cgi php5-mod-xml php5-mod-ctype php5-mod-curl php5-mod-exif php5-mod-ftp php5-mod-iconv php5-mod-json php5-mod-sockets
In the above list, I have installed a lot of php extension support. These packages can be added as needed. Not all php extension packages need to be installed.
Here, I will list several important extensions:
Php5: Needless to say, the main framework software package of php is not installed, and other software packages below are useless.
Php5-mod-apc: Alternative PHP Cache (APC) is an effective open-source high-speed buffer storage tool for PHP. It can Cache the php intermediate code of opcode. By installing APC, You can greatly speed up Website access.
Php5-mod-mysql/php-mod-pdo/php5-mod-pdo-mysql: These are required to use MySQL.
Php5-mod-cgi/php5-mod-fastcgi: The Key To webpage interaction.
Php5-mod-xml: Xml Parsing
Php5-mod-json: Json support
If you think there is enough space, you can install all php5-related packages once and for all (not recommended:
opkg updateopkg install php5*
2. Configure php
After the php package is installed, a php. ini file is generated under/etc, which is the configuration file of php. We can make necessary configurations according to our own needs. Modify php. ini:
Short_open_tag = on # If php displays "not found", comment the following line # doc_root = "/mnt/sda3/www" # in the Dynamic extension Section, remove ";" 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] # modify the time zone date. timezone = Asia/Chongqing [MySQL] # modify MySQL settings. default_socket =/var/run/mysqld. sock
Tips: When you modify the time zone, you need to add zoneinfo, that is, the software package zoneinfo-asia.opkg and zoneinfo-core.opkg mentioned above, if you do not add support, an error will be reported after the modification.
My backfire does not contain the above two packages.
Ii. Install Nginx
1. Install the Nginx Software Package
opkg updateopkg install nginx
2. Modify the Nginx configuration file (/etc/nginx. conf)
Preparations:
(1) Create the Nginx working directory:
mkdir /mnt/sda3/www
(2) Add Nginx users and user groups:
Opkg install shadow-useradd shadow-groupadd
# Add a user group
Groupadd www
# Add a user to the User Group www
Useradd-g www
# Bind the Nginx working directory to the www user
Chown-R www: www/mnt/sda3/www
(3) modify the Nginx configuration file (/etc/nginx. conf ):
The original Nginx configuration file is a bit complex. It is divided into different configuration files according to different functions:
User www; # Set the user and Its username worker_processes 1; # Number of allowed threads pid/var/run/nginx. pid; # specify the pid storage location error_log/var/log/nginx_error.log; # specify error. log location events {use epoll; worker_connections 1024; # specify the maximum number of connections} http {include mime. types; default_type application/octet-stream; access_log/var/log/nginx/access. log main; # access. log sendfile on; tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; gzip on; include vhost. conf; # server configuration file}
(4) Create the host configuration file vhost. conf in the/ect/nginx folder.
Server {listen 8000; # httpd listening 80 server_name localhost; root/mnt/sda3/www; # index index.html index.htm index of the website's working directory. php default. php; # redirect server error pages to the static page/50x.html error_page 500 502 503 504/50 x.html; # error page redirection location =/50x.html {root html ;} # pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000 location ~ \. Php $ {# pass the php script to FastCGIserver fastcgi_pass 127.0.0.1: 9000; # FastCGI server fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME/mnt/sda3/www/$ fastcgi_script_name; # fastcgi parameter include fastcgi_params; # fastcgi specific configuration file }}
(5) Specific FastCGI configuration:/etc/nginx/fastcgi_param
# Resolving file type parsing errors if ($ request_filename ~ * (. *) \. Php) {set $ php_url $1 ;}if (! -E $ php_url.php) {return 403;} specify QUERY_STRING $ query_string; required REQUEST_METHOD $ request_method; required CONTENT_TYPE $ content_type; fastcgi_param CONTENT_LENGTH $ content_length; required SCRIPT_NAME $ response; # parameters in the following annotations: Script Name. Note the settings. Valid for test: # response SCRIPT_FILENAME $ document_root/$ response; fastcgi_param SCRIPT_FILENAME/mnt/sda3/www/$ response; Response REQUEST_URI $ request_uri; Response DOCUMENT_URI $ document_uri; Response DOCUMENT_ROOT $ document_root; using SERVER_PROTOCOL $ server_protocol; using GATEWAY_INTERFACE CGI/1.1; using SERVER_SOFTWARE nginx/$ nginx_version; Using Dynamic $ scheme; using REMOTE_PORT $ remote_port; using SERVER_ADDR $ server_addr; using SERVER_PORT $ server_port; fastcgi_param SERVER_NAME $ server_name; # PHP only, required if PHP was built with -- enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;
(6) Enable the Nginx service:
It is troublesome to enable the Nginx service. First, enable the fastcgi service:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 2 -f /usr/bin/php-cgi
If you want to start the instance, place the preceding command under the/etc/rc. local script.
If exit 0 exists in rc. local, comment it out, otherwise it will not start listening to port 9000. This problem has been around for a long time ....
Enable Nginx Service
/etc/init.d/nginx enable/etc/init.d/nginx start
Iii. Testing Nginx + php + MySQL
Put the following files in the/mnt/sda3/www folder for testing:
During the test, remember to combine the Nginx log file:
/var/log/nginx/acesss.log/var/log/nginx/error.log
1. index.html (test whether the Nginx service is enabled properly)
this is a test file this is a html file
Display result:
2. index. php (used to test whether fastcgi works properly)
Display result:
3. 1.php (test whether the file name is interpreted as normal)
5. Problems and Solutions
1. Problem: "no input file specified" is displayed on the page when you test whether fastcgi is working ".
Solution: I have found various solutions on the network. I will write several useful articles for me and share them with you:
(1) fastcgi_param SCRIPT_FILENAME/scripts $ fastcgi_script_name; changed:
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; # the test result is invalid.
Then change: fastcgi_param SCRIPT_FILENAME/mnt/sda3/www/$ fastcgi_script_name; #/mnt/sda3/www is the website's working directory.
(2) fastcgi: port 9000 is not enabled properly
Run the following command:
Netstat-ant | grep 9000
Port 9000 is not enabled. That is to say, the fastcgi service is not enabled. Manually enable:
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 2 -f /usr/bin/php-cgi
The test is effective.
OK: The Nginx + PHP + MySQL development environment is successfully transplanted to the Openwrt platform.
--------------------------------------------------------------------------
Notice: Next chapter introduces VPN! (At the requirements of one student)
Htttp: // www.cnblogs.com/double-win/ thank you!