欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

RG100A-AA-openwrt+nginx+php+mysql

程序员文章站 2022-06-11 12:25:50
...
RG100A-AA内存为32M,flash为16M,主频为300MHZ,较小的内存和较低的主频,这决定了在搭建服务器时,必须考虑硬件条件的局限性。《Lighttpd+PhP5+MYSQL标准教程》中说内存最低为64M,这显然不符合现有硬件需求。因此需要寻找开销更小的方案。可以参考http://www.right.com.cn/forum/thread-89216-1-1.html 和 http://tieba.baidu.com/p/2950214737方案进行尝试配置。

RG100A-AA搭载 OpenWrt-DreamBox 20120201配置Nginx+PHP5+MySql步骤:

1、安装相关软件包:

opkg update

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 mysql-server nginx spawn-fcgi zoneinfo-core zoneinfo-asia shadow-groupadd shadow-useradd

遇到的问题:

Unknown package 'php5-mod-zip';Unknown package 'zoneinfo-core';Unknown package 'zoneinfo-asia';

Collected errors:

* opkg_install_cmd: Cannot install package php5-mod-zip.

* opkg_install_cmd: Cannot install package zoneinfo-core.

* opkg_install_cmd: Cannot install package zoneinfo-asia.

此种情况是由于软件包的源长时间没有更新,需要更换软件包源,找一个与本处理器型号相同的软件包源地址。在/etc/opkg.conf中

root@DreamBox:/# vi /etc/opkg.conf

#src/gz packages http://downloads.openwrt.org.cn/backfire/10.03.1/brcm63xx/packages

src/gz packages http://downloads.openwrt.org/attitude_adjustment/12.09/brcm63xx/generic/packages

dest root /

dest ram /tmp

lists_dir ext /var/opkg-lists

option overlay_root /overlay

红色字体为原来的软件包源地址,绿色字体为新的源地址,注释掉红色配置行,保存后重新执行opkg update;opkg install php5-mod-zip zoneinfo-core zoneinfo-asia。

2、建立操作用户

mkdir /html

groupadd www
useradd -g www www
chown -R www:www /html

3、建立数据库文件夹

mkdir -p /mnt/data /mnt/data/mysql /mnt/data/tmp

4、创建默认数据库

/usr/bin/mysql_install_db --force

报错:Installing MySQL system tables...

/usr/bin/mysqld: can't resolve symbol 'pthread_setschedprio'

Installation of system tables failed! Examine the logs in

/mnt/data/mysql/ for more information.

这个错误是安装的mysql-server有一个小bug,这个bug的介绍在http://bugs.mysql.com/bug.php?id=4 2599 中有详细说明。

解决办法:

(1)卸载mysql-server :opkg remove mysql-server;

(2)更换opkg源,取消opkg.conf第一行注释,注释第二行。

(3)opkg update;opkg install mysql-server

(4)/usr/bin/mysql_install_db --force

出现如下绿色字体,说明已经安装正确的mysql-server了。

Installing MySQL system tables...

OK

Filling help tables...

OK

(5)启动mysqld:/etc/init.d/mysqld start

5、启动mysql,并且创建root密码,密码设置为123,如果真正使用,建议设置复杂点的密码:

/usr/bin/mysqladmin -u root password 123456

6、连接上mysql后,创建数据库:

mysql > create database discuz;

查看当前可用数据库:

mysql > show databases;

查看数据库状态:

mysql > \s;

7、修改/etc/nginx/nginx.conf:

user www;

worker_processes 1;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

# '$status $body_bytes_sent "$http_referer" '

# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen 88;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.php index.html index.htm;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /html$fastcgi_script_name;

include fastcgi_params;

}

}

8、修改、/etc/php.ini

short_open_tag = on

#doc_root = "/html"


extension=ctype.so

extension=curl.so

extension=gd.so

extension=mbstring.so

extension=mcrypt.so

extension=mysql.so

extension=pdo.so

extension=pdo_mysql.so

extension=session.so

extension=sockets.so

extension=tokenizer.so

extension=xml.so


[Date]

date.timezone = Asia/Shanghai


[MySQL]

mysql.default_socket = /var/run/mysqld.sock

}

9、启动spawn-fcgi(如需开机自动运行,可将命令添加到/etc/rc.local)

usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 2 -f /usr/bin/php-cgi

10、启动nginx

/etc/init.d/nginx start

11、在/html目录下建立php测试文件:

#cd /html

#touch test.php

#chown www:www test.php

#vi test.php

phpinfo();

?>

在浏览器上输入192.168.1.11:88/test.php,就可以看到php的配置信息了。

12、可以下载雅黑探针到/html目录,雅黑探针php文件名为tz.php,在浏览器中输入192.168.1.11:88/tz.php就可以看到web服务器的配置详情了。

13、建立discuz论坛