2014年12月18日 星期四

[Tool]測試網站是否被萬里長城GFW 封鎖 ??



Checks whether a site is blocked by the Great Firewall of China.

http://www.viewdns.info/chinesefirewall/

2014年11月22日 星期六

使用google analytics統計ajax內容重載

1.在js中加入

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

2.在ajax function的success中加入


    _gaq.push(['_setAccount', 'UA-XXXXXX']);
    _gaq.push(['_trackPageview']);

在aws ec2 使用php mail功能寄信(ubuntu 14.04)

1.確認port 25沒被擋:

在VPC中的subnets與Security Groups確認SMTP (25) outbound 是否有開啟?



2.安裝 snedmail:

sudo apt-get install sendmail


參考資料:
http://stackoverflow.com/questions/19858457/send-mail-using-amazon-ec2-instance

2014年11月19日 星期三

mobile-friendly pages (defined by Google)

Google 將在行動裝置搜尋結果,加入mobile-friendly標籤。

符合以下條件會被加入標籤:
  • Avoids software that is not common on mobile devices, like Flash
  • Uses text that is readable without zooming
  • Sizes content to the screen so users don't have to scroll horizontally or zoom
  • Places links far enough apart so that the correct one can be easily tapped

Google測試:

Mobile-Friendly Test


資料來源:

Helping users find mobile-friendly pages

[連結備份]links that will show you what Google knows about you

凡走過必留下痕跡@@


1. Find out how Google sees you

Google attempts to create a basic profile of you, your age, gender, interests. They use this data to serve you relevant ads. You can review how Google sees you here:


2. Find out your location history

If you use Android, your mobile device may be sending your location as well as velocity data to Google. You can see your entire location history and export it here:


3. Find out your entire Google Search history

Google saves every single search you have ever done. On top of that, they record every Google ad you have clicked on. This log is available to you here:


4. Find out every device that has accessed your Google account

If you worry that someone else might be using your account, you can find a list of all devices that have accessed your Google account, their IP address and approximate location here:


5. Find out all the apps and extensions that are accessing your Google data

This is a list of all the apps that have any type of access to your data. You can see the exact type of permissions granted to the app and revoke access to your data here:


6. Export all of your data out of Google

Google let’s you export all your data: bookmarks, emails, contacts, drive files, profile info, your youtube videos, photos and more here:


 資料來源:
https://medium.com/productivity-in-the-cloud/6-links-that-will-show-you-what-google-knows-about-you-f39b8af9decc

2014年11月3日 星期一

configure: error: failed to recognize APR_INT64_T_FMT on this platform

configure: Configuring python swig binding
checking for Python includes... -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
checking for compiling Python extensions... cc -arch x86_64 -arch i386 -pipe
checking for linking Python extensions... cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. -framework Python
checking for linking Python libraries... -bundle -undefined dynamic_lookup -Wl,-F. -framework Python
checking for apr_int64_t Python/C API format string...
configure: error: failed to recognize APR_INT64_T_FMT on this platform


在mac os 10.10的solution為:

$ xcode-select --install

2014年10月30日 星期四

mac OSX 10.10 安裝PHP pcntl extension

1.抓取php 5.5.14 source code

http://tw1.php.net/get/php-5.4.24.tar.bz2/from/a/mirror

2.Build the PHP pcntl extension

tar -jxvf  PHP-5.5.14.tar.bz2

cd php-5.5.14/ext/pcntl/

/usr/bin/phpize

./configure

make

sudo make install

3.Enable the extension

編輯 /etc/php.ini  並加入

extension=pcntl.so

4.Restart apache
 
sudo /usr/sbin/apachectl restart

AWS RDS mysql 慢查詢 (slow query log)

以下為官方文件

The MySQL slow query log and the general log can be written to a file or a database table by setting parameters in your DB parameter group. For information about creating and modifying a DB parameter group, see Working with DB Parameter Groups. You must set these parameters before you can view the slow query log or general log in the Amazon RDS console or by using the Amazon RDS API, Amazon RDS CLI, or AWS SDKs.
You can control MySQL logging by using the parameters in this list:
  • slow_query_log: To create the slow query log, set to 1. The default is 0.
  • general_log: To create the general log, set to 1. The default is 0.
  • log_output: To write the general and slow query logs to the file system, set to FILE. The default is TABLE, which writes general queries to the mysql.general_log table, and slow queries to the mysql.slow_log table. To disable logging, set to NONE.
  • long_query_time: To prevent fast-running queries from being logged in the slow query log, specify a value for the shortest query execution time to be logged, in seconds. The default is 10 seconds, the minimum is 0. If log_output = FILE, you can specify a floating point value that goes to microsecond resolution. If log_output = TABLE, you must specify an integer value with second resolution. Only queries whose execution time exceeds the long_query_time value are logged. For example, setting long_query_time to 0.1 prevents any query that runs for less than 100 milliseconds from being logged.
  • log_queries_not_using_indexes: To log all queries that do not use an index to the slow query log, set to 1. The default is 0. Queries that do not use an index are logged even if their execution time is less than the value of the long_query_time parameter.



    資料來源
  • http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html
  •  http://dev.mysql.com/doc/refman/5.6/en/slow-query-log.html

2014年10月29日 星期三

mac os 10.10 mysql 慢查詢 (slow query log)


1.可由以下query得知相關參數

show variables like "%slow_query_log%

Variable_nameValue
slow_query_logOFF
slow_query_log_file/usr/local/mysql/data/server-slow.log


2.開啟慢日誌(slow query log)

vi /usr/local/mysql/my.cnf

加入

slow_query_log=on #開啟
slow_query_log_file=mysql-slow #檔案名稱
long_query_time=2 #2s


3.慢查詢分析方法

官方:MySQLdumpslow
其他: pt-query-digest

4.log_queries_not_using_indexes

Command-Line Format--log-queries-not-using-indexes
System Variable Namelog_queries_not_using_indexes
Variable ScopeGlobal
Dynamic VariableYes
 Permitted Values
Typeboolean
DefaultOFF
Whether queries that do not use indexes are logged to the slow query log.

2014年10月22日 星期三

install apache subversion on mac os 10.10

1.download apache subversion source code

2.build subversion

cd ~/Downloads/subversion-1.8.10

./configure

make

3.複製.so到apache

sudo cp subversion/mod_dav_svn/.libs/mod_dav_svn.so /usr/libexec/apache2

sudo cp subversion/mod_authz_svn/.libs/mod_authz_svn.so /usr/libexec/apache2



Note:

svn的設定檔在以下位置

/Library/Server/Web/Config/apache2/other/svn.conf

2014年10月14日 星期二

mysql fulltext常用參數...

再my.conf加入下列參數,可分別將stopword關掉與min length設成1

以下為MyISAM
ft_min_word_len=1
ft_stopword_file=''


以下為InnoDB

innodb_ft_min_token_size=1
innodb_ft_server_stopword_table = ''
innodb_ft_enable_stopword=FALSE


官方說明

ft_min_word_len
Command-Line Format--ft_min_word_len=#
System Variable Nameft_min_word_len
Variable ScopeGlobal
Dynamic VariableNo
Permitted Values
Typenumeric
Default4
Min Value1
The minimum length of the word to be included in a FULLTEXT index.
Note
FULLTEXT indexes must be rebuilt after changing this variable. Use REPAIR TABLE tbl_name QUICK.


ft_stopword_file
Command-Line Format--ft_stopword_file=file_name
System Variable Nameft_stopword_file
Variable ScopeGlobal
Dynamic VariableNo
Permitted Values
Typefile name
The file from which to read the list of stopwords for full-text searches. The server looks for the file in the data directory unless an absolute path name is given to specify a different directory. All the words from the file are used; comments are not honored. By default, a built-in list of stopwords is used (as defined in the storage/myisam/ft_static.c file). Setting this variable to the empty string ('') disables stopword filtering. See also Section 12.9.4, “Full-Text Stopwords”.
Note:
FULLTEXT indexes must be rebuilt after changing this variable or the contents of the stopword file. Use REPAIR TABLE tbl_name QUICK.

innodb_ft_min_token_size
Introduced5.6.4
Command-Line Format--innodb_ft_min_token_size=#
System Variable Nameinnodb_ft_min_token_size
Variable ScopeGlobal
Dynamic VariableNo
Permitted Values
Typenumeric
Default3
Min Value0
Max Value16
Minimum length of words that are stored in an InnoDB FULLTEXT index. Increasing this value reduces the size of the index, thus speeding up queries, by omitting common word that are unlikely to be significant in a search context, such as the English words a and to. For content using a CJK (Chinese, Japanese, Korean) character set, specify a value of 1.

 innodb_ft_server_stopword_table
Introduced5.6.4
Command-Line Format--innodb_ft_server_stopword_table=db_name/table_name
System Variable Nameinnodb_ft_server_stopword_table
Variable ScopeGlobal
Dynamic VariableYes
Permitted Values
Typestring
DefaultNULL
Name of the table containing a list of words to ignore when creating an InnoDB FULLTEXT index, in the format db_name/table_name.
Note:
The stopword table must be an InnoDB table, containing a single VARCHAR column named VALUE. The stopword table must exist before you specify its name in the configuration option value.

 innodb_ft_enable_stopword
Introduced5.6.4
Command-Line Format--innodb_ft_enable_stopword=#
System Variable Nameinnodb_ft_enable_stopword
Variable ScopeGlobal
Dynamic VariableYes
Permitted Values
Typeboolean
DefaultON
Specifies that a set of stopwords is associated with an InnoDB FULLTEXT index at the time the index is created. If the innodb_ft_user_stopword_table option is set, the stopwords are taken from that table. Else, if the innodb_ft_server_stopword_table option is set, the stopwords are taken from that table. Otherwise, a built-in set of default stopwords is used.


ERROR! The server quit without updating PID file (/usr/local/mysql/data/server.local.pid).

當開啟mysql時遇到以下error
Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/server.local.pid).

在網路上查了很多總解法都無效....

後來把ib_logfile0與ib_logfile1砍掉就搞定了
sudo rm -rf /usr/local/mysql/data/ib_logfile0
sudo rm -rf /usr/local/mysql/data/ib_logfile1

2014年8月25日 星期一

mysql upgarde on mac osx 10.9

停止mysql服務
sudo /usr/local/mysql/support-files/mysql.server stop

mysql官網抓取安裝程式
在此安裝了mysql 5.6.20

點選下載下來的.pkg檔案,安裝MySQL Server
 
確認/usr/local/mysql是否指定新版的sql
1.ls -al /usr/local/mysql
2.lrwxr-xr-x  1 root  wheel  27  8 24 23:36 /usr/local/mysql -> mysql-5.6.20-osx10.8-x86_64

將舊版本data複製到新版
1.cd /usr/local
2.sudo cp -rf mysql-5.5.27-osx10.6-x86_64/data/  mysql-5.6.20-osx10.8-x86_64/data/
3.確認權限是否正確,如果不對,利用sudo chown -R 更改權限
 
啟動新版本的MySQL
sudo /usr/local/mysql/support-files/mysql.server start
 
執行升級程序 
1.sudo /usr/local/mysql/bin/mysql_upgrade
2.sudo /usr/local/mysql/support-files/mysql.server restart 
 
更新密碼 
/usr/local/mysql/bin/mysqladmin -u root password 'password' 
 
 
Note:
官方說明文件 

2014年8月14日 星期四

mac OSX 10.9安裝PHP extension

1.抓取php 5.4.24 source code

http://tw1.php.net/get/php-5.4.24.tar.bz2/from/a/mirror

2.Build the PHP XXX extension

cd ~/Downloads
unzip PHP-5.4.17.zip
cd php-src-PHP-5.4.17/ext/XXX/
/usr/bin/phpize
./configure
make
sudo make install

3.Enable the extension

編輯 /etc/php.ini file 並加入
extension=XXX.so

4.Restart apache

2014年7月19日 星期六

The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'

function my_session_start()
{
    $sn = session_name();

    if (isset($_COOKIE[$sn])) {
        $sessid = $_COOKIE[$sn];
    } else if (isset($_GET[$sn])) {
        $sessid = $_GET[$sn];
    } else {
        return session_start();
    }

    if (!preg_match('/^[a-zA-Z0-9,\-]{22,40}$/', $sessid)) {
        return false;
    }

    return session_start();
}

if ( !my_session_start() ) {
    session_id( uniqid() );
    session_start();
    session_regenerate_id();
}

參考來源:
http://stackoverflow.com/questions/3185779/the-session-id-is-too-long-or-contains-illegal-characters-valid-characters-are

2014年7月16日 星期三

Apache Virtual Hosts on Ubuntu 14.04

1.建立新資料夾(放置web source)

預設document root在 /var/www,所以在此目錄下建一個新目錄:
sudo mkdir /var/www/example.com/


2.Grant Permissions


sudo chown -R $USER:$USER /var/www/example.com/
($USER設呈現在登入的user name)

sudo chmod -R 755 /var/www/example.com/

3.建立新的Virtual Host Files

sudo vi /etc/apache2/sites-available/example.com.conf
檔案內容如下:

ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


4.Enable the New Virtual Host Files

sudo a2ensite example.com.conf

5.Apache重新載入設定:

sudo service apache2 reload
or
sudo service apache2 restart

apache支援.htaccess rewrite (ubuntu 14.04)

如果mod_rewrite.so已經載入,在 /etc/apache2/apache2.conf中,將


Options Indexes FollowSymLinks
AllowOverride None
Require all granted


改成


Options Indexes FollowSymLinks
AllowOverride ALL
Require all granted

就可以了。

Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

ubuntu apache 有下列error
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

1.開啟rewrite module
sudo a2enmod rewrite

2.重開apache
service apache2 restart

2014年7月15日 星期二

Install pcntl extension on ubuntu 14.04


1.抓php source code來編譯pcntl.so

mkdir tmp/phpsource
cd /tmp/phpsource
apt-get source php5
cd /tmp/phpsource/php5-*/ext/pcntl
phpize
./configure
make


2.將編好的pcntl.so複製到php lib裡


cd modules
cp pcntl.so /usr/lib/php5//


3.新增pcntl.ini


vi /etc/php5/mods-available/pcntl.ini
加入下列此行
extension=pcntl.so

4.link to mods-available/

cd /etc/php5/apache2/conf.d
ln -s /etc/php5/mods-available/pcntl.ini 20-pcntl.ini


5.編輯php.ini.


memory_limit  = 256M
找到下列這行,並再前方加上;(註解掉此行)
disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,

Install Apache + PHP on Ubuntu 14.04

1.更新apt-get
sudo apt-get update

2.安裝apache
sudo apt-get install apache2 libapache2-mod-auth-mysql


3.安裝php以及所需extension:
sudo apt-get install php5 php5-mysql php5-mcrypt php5-curl


4.重開apache service
sudo service apache2 restart


其他一些常用設定路徑:

1.Configuration File Path
/etc/php5/apache2/php.ini

2.Loaded Configuration File
/etc/apache2/apache2.conf

3.The default Ubuntu document root
/var/www/html

By default, Ubuntu does not allow access through the web browser to any file apart of those located in/var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.

The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www. This is different to previous releases which provides better security out of the box.