环境ubuntu 12.04 server+nginx 1.4.1 nginx安装教程 PHP编译参数列表 http://www.php.net/manual/en/configure.about.php中文的,http://php.net/manual/zh/configure.about.php,我这被和谐了。 tar zvxf php-5.4.15.tar.gz cd php-5.4.15 ./configure --prefix=/home/server/php-5.4.15 --enable-fpm --enable-mbstring --enable-ftp --with-bz2 --with-jpeg-dir --with-png-dir --with-freetype-dir --with-libxml-dir --with-xmlrpc --with-zlib-dir --with-curl --with-curlwrappers --enable-calendar --enable-sockets --enable-exif --enable-magic-quotes make make install configure时如果提示xml2-config not found,安装libxml2和libxml2-dev 提示configure: error: Please reinstall the BZip2 distribution 安装libbz2-dev 提示Please reinstall the libcurl distribution 安装 libcurl4-gnutls-dev make时,如果报undefined reference to libiconv_*' 需要安装libconv库,下载地址http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz configure加上参数 –with-iconv=/usr/local/lib安装完, vi /home/server/php-5.4.15/etc/php-fpm.conf 这里主要是修改user和group,我这改成wwwuser = www group = www把pid = run/php-fpm.pid前的分号删掉,这样在php-fpm运行时会生成相应的pid文件。 启动php-fpm:/home/server/php-5.4.15/sbin/php-fpm 修改/home/server/nginx-1.4.1/conf/nginx.conf: server下增加root /home/www; location ~ .php$ { root /home/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }删除:location / { root /home/www; index index.html index.htm; }设置静态文件缓存: location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\\.(js|css)?$ { expires 12h; } 默认没有生成php.ini,从源代码里拷一个: cp /root/download/php-5.4.15/php.ini-production /home/server/php-5.4.15/lib/php.ini 2013-09-08更新: 如果要让php支持GD库,需要在编译PHP前先安装 zlib([http://www.zlib.net/](http://www.zlib.net/)) libpng([http://sourceforge.net/projects/libpng/](http://sourceforge.net/projects/libpng/)) freetype([http://download.savannah.gnu.org/releases/freetype/](http://download.savannah.gnu.org/releases/freetype/)) libJpeg([http://www.ijg.org/files/](http://www.ijg.org/files/)) gd([https://bitbucket.org/libgd/gd-libgd/downloads](https://bitbucket.org/libgd/gd-libgd/downloads) 安装方法参考INSTALL文档,基本上都是:./configure make make install编译PHP的时候,在原参数后加上--with-gd --enable-gd-native-ttf 如果编译报错:checking for png_write_image in -lpng… no configure: error: Problem with libpng.(a|so) or libz.(a|so). Please check config.log for more information.基本上是libpng有问题,重新安装,或换一个版本,我之前用1.6.3就一直有这个问题,换了1.6.4rc后,解决. 记录一下编译参数:./configure –prefix=/home/fhp/server/php –enable-fpm –enable-mbstring –enable-ftp –with-bz2 –with-jpeg-dir –with-png-dir –with-freetype-dir –with-libxml-dir –with-xmlrpc –with-zlib-dir –with-curl –enable-calendar –enable-sockets –enable-exif –with-gd –enable-gd-native-ttf –with-iconv=/usr/local/lib`
Ubuntu下安装Webbench
Webbench是一款web压力测试工具. tar zxvf webbench-1.5.tar.gz cd webbench-1.5 make sudo make install 如果make时提示 cc -Wall -ggdb -W -O -c -o webbench.o webbench.c webbench.c: 在函数‘alarm_handler’中: webbench.c:77:31: 警告: 未使用的参数‘signal’ [-Wunused-parameter] cc -Wall -ggdb -W -O -o webbench webbench.o ctags *.c /bin/sh: 1: ctags: not found make: [tags] 错误 127 (忽略) 需要安装exuberant-ctags 使用: webbench -c 500 -t 10 http://192.168.3.191/ c是并发数量,t是时间,单位秒
Linux下 编译安装Nginx 1.4.1
环境是ubuntu12.04 server,安装nginx 1.4.1和ngx_cache_purge模块,ngx_cache_purge功能是当nginx作为反向代理时,可以删除指定url的缓存,如果nginx作http服务器,可以不装. 先装PCRE library,nginx依赖这个库,下载:http://sourceforge.net/projects/pcre/files/pcre/,当前最新版8.32 unzip pcre-8.32.zip cd pcre-8.32 ./configure make make install 创建www用户组和www用户,并创建/home/www目录 groupadd www useradd -g www -s /sbin/nologin -M www mkdir /home/www chown -R www:www /home/www 下载好 nginx-1.4.1.tar.gz,ngx_cache_purge-2.1.tar.gz tar zxvf nginx-1.4.1.tar.gz tar zxvf ngx_cache_purge-2.1.tar.gz cd nginx-1.4.1 ./configure --user=www --group=www --add-module=../ngx_cache_purge-2.1 --prefix=/home/server/nginx-1.4.1 --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_sub_module --with-http_dav_module make make install prefix参数是nginx的安装位置,with-http_stub_status_module是打开status模块(查看nginx当前状态) http_realip_module 作为代理服务器时,服务端可获取到用户真实的IP http_addition_module 可在响应前后添加一个过滤器 http_gzip_static_module 预压缩文件传前检查,防止文件被重复压缩 http_random_index_module 随机主页 如果在指定的location中指定,将为每一个请求扫描指定目录中的文件,并且随机选择一个代替index.html,但是不会选择以“.”开头的文件。 http_sub_module 反向代理时替换URL http_dav_module 开启WebDAV扩展动作模块,可为文件和目录指定权限 以上模块根据自己需要添加,官方模块列表:http://wiki.nginx.org/Modules 修改nginx.conf配置: vi /home/server/nginx-1.4.1/conf/nginx.conf 头部添加 user www www; 使用www组的www用户启动nginx 找到server location,修改www根目录 location / { root /home/www; index index.html index.htm; } 启动nginx: /home/server/nginx-1.4.1/sbin/nginx 这个时候,一般会报错,提示: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory 建立链接: 32位系统: ln -s /usr/local/lib/libpcre.so.1 /lib 64位系统: ln -s /usr/local/lib/libpcre.so.1 /lib64
Ubuntu配置DNS服务器
直接修改/etc/resolv.conf,重启后就会失效,这个文件会被清空。 编辑/etc/resolvconf/resolv.conf.d/base,这个文件默认是空的 加入DNS服务器 nameserver 8.8.8.8 nameserver 8.8.4.4 保存,执行 resolvconf -u 重启后不失效
VirtualBox虚拟机Linux(Ubuntu)无法找到网卡的解决
ifconfig看不到eth0,找不到网卡,有一个原因是你改了网卡的mac地址,而ubuntu绑定了之前的mac地址,删除原配置,重启即可。 rm /etc/udev/rules.d/70-persistent-net.rules
Android开发 PackageManager.installPackage安装成功没有回调的解决
通过调用隐藏Api,PackageManager.installPackage(Uri packageURI, IPackageInstallObserver observer, int flags, String installerPackageName); 可以实现静默安装应用,根据参数说明observer是在安装完成后(成功或失败)回调的,第一次我在调用installPackage的Activity里实现IPackageInstallObserver接口,再把它当作IPackageInstallObserver传给installPackage方法,奇怪的是,不管安装成功或失败,都没有回调IPackageInstallObserver的packageInstalled,也没找到这部分的源代码(在源代码里只看到一个aidl文件).网上看到一篇文章,传入的参数是IPackageInstallObserver.Stub,一个实现IPackageInstallObserver接口的抽象类。改成IPackageInstallObserver.Stub,确实收到了回调。暂时不知道为什么直接实现IPackageInstallObserver不行,但是IPackageInstallObserver.Stub继承了android.os.Binder,而IPackageInstallObserver也有一个抽象的asBinder方法,估计是需要先在asBinder里做些处理,没看到源代码,不好判断。
Android开发 mm编译 Android.mk添加第三方jar包
下面的例子,加了两个包,一个是gson,一个是androidannotations LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_STATIC_JAVA_LIBRARIES := gson androidannotations LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := Update LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE) include $(CLEAR_VARS) LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := gson:libs/gson-2.2.2.jar \ androidannotations:libs/androidannotations-api-2.7.jar include $(BUILD_MULTI_PREBUILT) LOCAL_STATIC_JAVA_LIBRARIES 是别名,可以随便取,与下面对应即可
VirtualBox 虚拟机在NAT模式下做商品映射
在NAT网络模式下,虚拟机可以访问主机,但是主机是不能访问虚拟机的,只能通过端口映射。 映射: VBoxManage modifyvm "webserver1" --natpf1 "guestssh,tcp,,222,,22" webserver1是虚拟机名,guestssh是映射规则名,协议tcp,主机端口222,虚拟机端口22 删除映射: VBoxManage modifyvm "webserver1" --natpf1 delete "guestssh" 最后提一句,其实有图形化设置界面,在网络那,展开高级,选择端口转发。
解决mongoDB启动找不到data/db目录
data/db目录,必须建在mongoDB所在分区的根目录下!!
Android开发 调用系统隐藏API
Android中有些Api被隐藏了,比如开关机,重启,如果要在应用中调用,要么用反射,要么就是直接在Android源代码下编译。如果用Eclipse用IDE,尽管调用隐藏API的代码能顺利在Android源码下通过编译,但Eclipse找不到相应的类,会报错,为了写代码时方便点,我们可以把相关的包加到eclipse中。 先下载Android源码(本站有提供4.2.2的打包下载链接,自己找找),编译一次,找到out/target/common/obj/JAVA_LIBRARIES/fmradioif_intermediates/classes.jar,在Eclispe中加到我们自己项目的构建路径中,这样就可以调用到相关的类了。另外,这个包里的有些类和方法,跟android.jar是有冲突的,我们得手工调整优先级,打开项目属性,找到Java构建路径,排序和导出,把刚刚添加的classes.jar放到最顶上。 另外,我们需要调用的API,源代码都在frameworks/base/core/java下,根据包名找。 下面的例子是关机的,项目名为PowerOff。
package com.example.poweroff;
import android.app.Activity;
import android.os.Bundle;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
IPowerManager power=IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
if(power!=null)
{packages/apps
try {
/**
* 查看frameworks/base/core/java/android/os/IPowerManager.aidl
* void shutdown(boolean confirm, boolean wait);
* 所以,第一个是是否让用户确认,第二个是是否等待
*/
power.shutdown(false,false);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
AndroidManifest.xml:需要重启权限
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.poweroff"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<!-- 加入这条,Eclipse会报错,提示Permission is only granted to system apps,只有系统app才能调用,没关系,反正我们不用eclipse编译 -->
<uses-permission android:name="android.permission.REBOOT" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.poweroff.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
项目根目录下,创建一个Android.mk文件,内容如下: LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := PowerOff LOCAL_CERTIFICATE := platform include $(BUILD_PACKAGE) 注意LOCAL_MODULE_TAGS := optional,可能有四个值user,eng,tests,optional,对应你编译Android源码时的参数,optional兼容所有。 另外,布局的xml中,android:text属性要用引用,先写到strings.xml里,直接hard code会报错. 编译: 切到android源代码根目录,设环境变量 执行/build/envsetup.sh 把项目拷到packages/apps目录下,切换到packages/apps/PowerOff目录,把Eclipse自动生成的gen目录删除,执行mm开始编译。 成功后,会提示Install: out/target/product/maguro/system/app/PowerOff.apk 但是正常能安装的文件在 out/target/product/maguro/obj/APPS/PowerOff_intermediates/package.apk,如果安装上面那个,可能会出现INSTALL_FAILED_DEXOPT错误 再用 adb install装上,成功关机. 有一点需要注意,我的手机是Galaxy Nexus,刚刚刷上自己用源码编译的Rom,如果是其他手机,还是需要系统签名先。