分类目录归档:PHP

PHP源码,PHP扩展,PHP程序

windows7下安装配置apache

windows7下安装配置apache

在本本升级为windows7后,不得不把开发环境换了,于是手动配置apache,
依据以前在window xp下面的经验,把apache安装好,运行,可以看到It works的相关页面,
然后是配置PHP和网站根目录
据经验:
直接修改C:\Program Files\Apache Software Foundation\Apache2.2\conf下的httpd.conf文件

添加php模块:LoadModule php5_module “D:/work/php/php5apache2_2.dll”

查找”AddType”,新增行,输入允许执行php的文件类型
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html

查找”DirectoryIndex”,更改默认首页为
DirectoryIndex index.php index.html

修改网站根目录
查找”DocumentRoot”,更改默认的站点路径为
DocumentRoot “D:/project”

更改下面的

然后重新启动apache,
然后很神奇的事情出现了:根目录设置无效,PHP无法解析
访问PHP文件,出现神奇的404错误

查看用editplus打开的配置文件,发现是正确的,
查找原因,以为是配置错了,半天没有发现问题,然后重装,重新配置,还是有问题。
查找错误日志,发现访问的还是apache默认的网站根目录下面的文件。
以为根目录设置有问题,发现貌似没有错

百思不得其解,然后在一不小心使用记事本打开了配置文件,发现其内容和editplus打开的内容不是一样的。
奇怪了。

问一服务器组的哥们,那哥们说咱不用win系统,都是*unix系统。一般来说:这个是权限问题,不过咱们的系统会告诉我们不能修改。
恍然,文件上点开右键发现有一个使用管理员身份打开,打开后修改,重启apache

over了

神奇了,window也有权限了!

判断一个字符串是否经过了base64_encode加密

判断一个字符串是否经过了base64_encode加密
遇到这样一个问题,之前就是将字符串先解密再加密,判断所得的字符串是否是之前的那个
此方法在如下情况下无效:
当字符串没有加密,并且此字符串与其它某字符串加密后是一样的情况!
觉得在其它方法下也应该不能区分,他本来就是一加密后字符串嘛

简单实现代码如下:
【方法一】

1
2
3
4
5
6
7
$str = "ssssffdfds";
 
if ($str == base64_encode(base64_decode($str))) {
    echo 'yes';
}else{
    echo 'no';
}

如果从base64加密的本身算法来研究,也没有找到相关的算法,如果有哪位高人有其它方法,请告知!谢谢

在windows7下配置nginx的过程和一些问题

最近心血来潮,在windows下使用nginx做为服务器进行开发,由于对这东西十分陌生,所以出了一些问题。
配置过程十分简单,但是对于我这样的新手来说,貌似比较辛苦。
简单来说:
1、到nginx for windows由第三方编译的nginx Windows 版本下载
2、下载非安装版的php
3、将下载下来的nginx-0.7.59.zip包解压到你想到的位置(文件夹路径不能包含中文名)
4、直接运行nginx.exe,在浏览器中输入http://localhost,可以看到nginx的欢迎页面
5、配置nginx
我的配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#user  nobody;
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  185;
 
    #gzip  on;
 
    server {
        listen       80;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   D:/project;#网站根目录 需要与下面的fastcgi_param 对应
            index  index.html index.htm index.php;
        }
 
        #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  D:/project$fastcgi_script_name; #这个需要注意
            include        fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
 
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
 
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
 
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_timeout  5m;
 
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
}

6、使用RunHiddenConsole 隐藏php-cgi.exe的命令行,写一个批处理如下:

1
2
3
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole D:\work\php\php-cgi.exe -b 127.0.0.1:9000 -c  D:\work\php\php.ini

7、关闭批处理

1
2
3
4
5
6
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit

其它可以参考

http://hi.baidu.com/rokaye/blog/item/3a44f6cbaf45dc19be09e6fd.html

【其它问题】
1、nginx网站根目录设置问题
fastcgi_param 和root 需要对应

2、The page you are looking for is temporarily unavailable.
打开某些页面时可能会出现The page you are looking for is temporarily unavailable.问题,在错误日志中可以看到
upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading response header from upstream, client: 127.0.0.1, server: localhost, request: “GET
解决方案:修改 keepalive_timeout 185;

【补充说明】
在 Windows 下自动安装 Nginx 的项目:Farseer
这是淘宝 UED 部门的 明城 捣鼓的一个自动安装工具工具。地址:http://code.google.com/p/gracecode/wiki/Farseer