找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 116796|回复: 158

openwrt安装nginx+php+mysql教程

 火... [复制链接]
本帖最后由 99010 于 2013-10-13 11:01 编辑
  1. opkg update

  2. opkg install php5 php5-mod-gd php5-mod-session php5-mod-pdo php5-mod-pdo-mysql php5-mod-mysql 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 php5-mod-sqlite3 php5-mod-tokenizer php5-mod-zip

  3. opkg install mysql-server

  4. opkg install nginx spawn-fcgi zoneinfo-core zoneinfo-asia

  5. opkg install shadow-groupadd shadow-useradd

  6. groupadd www
  7. useradd -g www www
  8. chown -R www:www /mnt/sda1/web
复制代码
修改/etc/my.cnf
  1. datadir                = /mnt/sda1/data/mysql/

  2. tmpdir                = /mnt/sda1/data/tmp/
复制代码
创建数据库文件夹
  1. mkdir -p /mnt/sda1/data /mnt/sda1/data/mysql /mnt/sda1/data/tmp
复制代码
创建默认的数据库
  1. /usr/bin/mysql_install_db --force
复制代码
启动mysql
  1. /etc/init.d/mysqld start
复制代码
输入如下命令创建mysql的密码
  1. /usr/bin/mysqladmin -u root password 123456
复制代码
登陆数据库
  1. mysql -u root -p
复制代码
连接上mysql之后,创建数据库(可以自己定义,记住就行了,之后会用到)
  1. create database abcd
  2. \g
复制代码
查看当前可用数据库
  1. show databases
  2. \g
复制代码
退出mysql
quit

修改/etc/nginx/nginx.conf
  1. user www www;
  2. worker_processes  1;
  3. pid        /var/run/nginx.pid;
  4. error_log  /var/log/nginx_error.log;
  5. events {
  6.         use epoll;
  7.         worker_connections  1024;
  8. }

  9. http {
  10.         include mime.types;
  11.         default_type application/octet-stream;
  12.         sendfile on;
  13.         tcp_nopush on;
  14.         #keepalive_timeout 0;
  15.         keepalive_timeout 65;
  16.         gzip on;
  17.         access_log   off;
  18.    
  19.         include       vhost.conf;
  20. }
复制代码
修改/etc/nginx/fastcgi_params,解决Nginx文件类型错误解析漏洞
  1. if ($request_filename ~* (.*)\.php) {
  2.     set $php_url $1;
  3. }
  4. if (!-e $php_url.php) {
  5.     return 403;
  6. }

  7. fastcgi_param  QUERY_STRING       $query_string;
  8. fastcgi_param  REQUEST_METHOD     $request_method;
  9. fastcgi_param  CONTENT_TYPE       $content_type;
  10. fastcgi_param  CONTENT_LENGTH     $content_length;

  11. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  12. fastcgi_param  REQUEST_URI        $request_uri;
  13. fastcgi_param  DOCUMENT_URI       $document_uri;
  14. fastcgi_param  DOCUMENT_ROOT      $document_root;
  15. fastcgi_param  SERVER_PROTOCOL    $server_protocol;

  16. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  17. fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

  18. fastcgi_param  REMOTE_ADDR        $remote_addr;
  19. fastcgi_param  REMOTE_PORT        $remote_port;
  20. fastcgi_param  SERVER_ADDR        $server_addr;
  21. fastcgi_param  SERVER_PORT        $server_port;
  22. fastcgi_param  SERVER_NAME        $server_name;

  23. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  24. fastcgi_param  REDIRECT_STATUS    200;
复制代码
添加/etc/nginx/vhost.conf
  1. server {
  2.         listen       80;
  3.         server_name  localhost;
  4.         root  /mnt/sda1/web;
  5.         index  index.html index.htm index.php default.php;
  6.         error_page   500 502 503 504  /50x.html;

  7.         location = /50x.html {
  8.         root html;
  9.         }

  10.         location ~* ^.+\.php(\/.*)*$ {
  11.         fastcgi_pass   127.0.0.1:9000;
  12.         fastcgi_index  index.php;
  13.         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  14.         include        fastcgi_params;
  15.     }
  16. }
复制代码
修改/etc/php.ini
  1. short_open_tag = on
  2. #doc_root = "/mnt/www"

  3. extension=ctype.so
  4. extension=curl.so
  5. extension=gd.so
  6. extension=mbstring.so
  7. extension=mcrypt.so
  8. extension=mysql.so
  9. extension=pdo.so
  10. extension=pdo_mysql.so
  11. extension=session.so
  12. extension=sockets.so
  13. extension=tokenizer.so
  14. extension=xml.so

  15. [Date]
  16. date.timezone = Asia/Shanghai

  17. [MySQL]
  18. mysql.default_socket = /var/run/mysqld.sock
复制代码
启动spawn-fcgi(如需开机自动运行,可将命令添加到/etc/rc.local)
  1. /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 2 -f /usr/bin/php-cgi
复制代码
启动nginx
  1. /etc/init.d/nginx enable
  2. /etc/init.d/nginx start
复制代码
附送一个owncloud私有云的nginx配置文件。
  1. #参考https://www.right.com.cn/forum/thread-89216-1-1.html安装组件,还需安装php5-mod-dom、php5-mod-simplexml
  2. #由于cpu运算性能不足,只能运行owncloud4.5系列版本,想被坑爹的可以去用owncloud5.0系列版本
  3. #如果owncloud程序是刚上传的,建议修改owncloud文件夹权限chown -R www:www /mnt/sda1/web/owncloud
  4. #这个是/etc/nginx/vhost.conf配置
  5. #如果没有按照下面的设置owncloud WebDAV等,会出现owncloud布局混乱

  6. ####################################################
  7. #               owncloud
  8. ####################################################
  9. server {
  10.     listen       80;  #修改你需要的端口,因为uhttpd已经使用80端口,这里无法使用80端口,或者你修改uhttpd的端口
  11.     server_name  localhost; #你的服务器域名,你可以填写你的动态域名
  12.     root  /mnt/sda1/web/owncloud; #网站目录
  13.     index index.php;
  14.     client_max_body_size 20M; # 最大上传文件大小 还需要改php.ini的upload_max_filesize

  15. # 不允许访问的目录
  16.     location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
  17.       deny all;
  18.     }

  19. # default try order
  20.     location / {
  21.         try_files $uri $uri/ @webdav;
  22.     }


  23. # owncloud WebDAV
  24.     location @webdav {
  25.       fastcgi_split_path_info ^(.+\.php)(/.*)$;
  26.       fastcgi_pass 127.0.0.1:9000;
  27.       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  28.       include fastcgi_params;
  29.     }

  30. # enable php
  31.     location ~ \.php$ {
  32.       try_files $uri = 404;
  33.       fastcgi_pass 127.0.0.1:9000;
  34.       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  35.       include fastcgi_params;
  36.     }
  37. }
复制代码

评分

参与人数 6恩山币 +8 收起 理由
mu*** + 1 强大的恩山!(以下重复1万次)
hiboyhi*** + 3 亲,你太牛逼了,走,我请你吃鳇鱼头去~~~
7ge*** + 1 一看就是觉得高端、大气、上档次!
xiao*** + 1 楼主威武—我就想问问挖掘机技术哪家强?
qzhan*** + 1 赞一个,你是我的呕像!
sz*** + 1 泥马,真给力,我要顶!

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
 楼主| | 显示全部楼层
本帖最后由 99010 于 2012-7-26 23:23 编辑

php探针截图。。。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

我x,楼主牛人呀。。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

人生出品,必属精品,顶一个。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

学习一下,这东西安wordpress不知道运行快不快,lighttpd太慢,比apache还快把?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

我是来顶贴的。。。。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

顶顶更健康  大神牛帖
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

大师又出精品了,顶!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

laoyangjp 发表于 2012-7-26 10:59
学习一下,这东西安wordpress不知道运行快不快,lighttpd太慢,比apache还快把?

lighttpd太慢?你说反了把
apache才慢呢!又臃肿
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

mrqian7188 发表于 2012-7-26 12:17
lighttpd太慢?你说反了把
apache才慢呢!又臃肿

搭个wordpress 不知道哪种能运行起来快点。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

機器跑的動嗎??真是懷疑呀
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

请问怎么加载在外接u盘上呀
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

请问怎么加载在外接u盘上呀
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| | 显示全部楼层
li809 发表于 2012-7-28 13:42
请问怎么加载在外接u盘上呀

修改/etc/nginx/vhost.conf配置里面的路径
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-27 03:24

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表