2015年5月26日 星期二

apache 虛擬目錄設定

系統:
Win 7 ( XAMPP )

程式路徑: E:\www\project_name
phpmyadmin路徑: C:\xampp\phpMyAdmin

目的:
http://localhost  訪問該程式
http://localhost/phpmyadmin 訪問phpmyadmin

解法:
使用Alias ( 我是加在vhost中 )
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "E:\www\project_name"
    ServerName localhost
    ErrorLog "logs/localhost-error.log"
    CustomLog "logs/localhost-access.log" common
    Alias /phpmyadmin C:\xampp\phpMyAdmin
    <Directory "E:\www\project_name">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

參考資料:
http://stackoverflow.com/questions/5552081/using-a-directory-in-virtualhost-servername

(vhost)解決403 Access Forbidden 錯誤
https://superuser.com/a/714183
Directory 裡面新增 Require all granted
<VirtualHost *:80>
    ServerAdmin webmaster@test.example.com
    DocumentRoot "C:\test"
    ServerName test.example.com
    ErrorLog "logs/test.example.com-error.log"
    CustomLog "logs/test.example.com-access.log" common
    <Directory "C:\test">
        Require all granted
    </Directory>
</VirtualHost>








Collabnet SVN Edge 心得

起源:
某日 svn 的網址忽然打不開 ( http://192.168.x.x:18080/svn/project/trunk/ )
登錄csvn後台 https://192.168.x.x:4434/csvn/ 後顯示錯誤:
Unable to browse repositories, as the Subversion server is not running.

然而csvn的管理帳號admin又找不到密碼登不進去

主機系統:
CentOS 6.6 

解法:
重置 Collabnet SVN 的admin密碼
1. 關閉Collabnet SVN服務。找到csvn的資料夾 ( 該主機csvn放在 /home/data/csvn ) 然後執行資料夾下的
# ./bin/csvn stop
2. 找csvn資料夾下的 csvn-production-hsqldb.script 檔案並編輯,該主機放在 ./data/csvn-production-hsqldb.script
3. 在csvn-production-hsqldb.script搜索admin,找到類似下面這一行
INSERT INTO USER VALUES(1,8,'9cdb7018925e8f3ada81b1e475f111b9',TRUE,'admin','admin@example.com','admin user','Super Administrator')
4. 將密碼欄位 '9cdb7018925e8f3ada81b1e475f111b9' 改成 '21232f297a57a5a743894a0e4a801fc3' 
5. 重啟csvn服務 ./bin/csvn start ,然後就可以用 帳號:admin,密碼:admin 登錄csvn後台
6. 用管理帳號admin登錄後台後點擊啟動svn服務,這樣svn 的網址 ( http://192.168.x.x:18080/svn/project/trunk/ ) 就能重新訪問了


註:
該台主機上沒裝svn,只裝csvn也能在主機上跑svn 的主機服務

參考資料:

2015年5月1日 星期五

phpmyadmin常見問題


錯誤訊息:
缺少 mcrypt 擴充套件。請檢查 PHP 設定。
解法:
先檢查伺服器有無安裝php5-mcrypt
$ dpkg --get-selections | grep mcrypt
啟用
# php5enmod mcrypt
重新啟動apache
# service apache2 restart
參考資料:
http://reader.roodo.com/jaytech/archives/32814872.html

將datetime預設值為NOW()
將欄位Type改成TIMESTAMP ,然後Default設 CURRENT_TIMESTAMP ,但Mysql一張表只能有一個TIMESTAMP,如這樣表有兩個欄位,如new_time和update_time,則其中一個在insert時只能手動寫NOW() 到SQL上

連線遠端資料庫
http://stackoverflow.com/questions/16801573/how-to-access-remote-server-with-local-phpmyadmin-client
編輯 config.inc.php ,在檔案最底下加入
$i++;
$cfg['Servers'][$i]['host'] = '192.168.x.x:3306'; //provide hostname and port if other than default
$cfg['Servers'][$i]['user'] = 'root';   //user name for your remote server
$cfg['Servers'][$i]['password'] = 'password';  //password
$cfg['Servers'][$i]['auth_type'] = 'config';       // keep it as config
勿直接改 上面 First server (本機)裡面的設定,否則會報錯:
#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist

移動欄位順序
http://stackoverflow.com/questions/1962448/php-myadmin-change-field-order-move-up-or-down
在瀏覽結構頁籤時,下方有 Move columns( 移动字段 ) 這邊有GUI可以操作
或直接下SQL:
ALTER TABLE `table_name` MODIFY `column_you_want_to_move` DATATYPE AFTER `column`

最新版線上測試
http://demo.phpmyadmin.net/STABLE/
http://demo.phpmyadmin.net/QA_4_5/  ( https://github.com/phpmyadmin/phpmyadmin 上的QA_4_5 branch )
帳號: root
密碼:  (空)
https://wiki.phpmyadmin.net/pma/Release_Targets
A QA branch is created with the first release candidate for each version (for instance, QA_4_0 was created for the release of 4.0.0-rc1). Bug fixes for that release should target the QA branch.
We try to fix bugs in the most recent QA branch, ...
什麼是QA分支?他是每個版本第一個發佈的候選人,bug在最近的QA分支上修復...

連結docker mysql:5.6
下載docker mysql 5.6
# docker pull mysql:5.6
啟動docker mysql:5.6,將mysql的port對應到master的3307 port,可先在master 檢查3307 有沒有被其他進程佔用( $ ps aux | grep 3307 )
# docker run -t -i -p 3307:3306 mysql:5.6 bash
因為docker mysql:5.6 root的預設密碼為空,但沒開放給別的ip連,如果要讓別台機器連docker mysql:5.6
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' ;
在phpmyadmin的 config.inc.php 設定docker mysql:5.6的連線方式後出現錯誤:
無法連線: 設定錯誤.
解法:
開一個有密碼的使用者去連
mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%';
然後在phpmyadmin config.inc.php 最下面加入下面設定
$i++;
$cfg['Servers'][$i]['host'] = '192.168.169.147:3307'; //provide hostname and port if other than default
$cfg['Servers'][$i]['user'] = 'user';   //user name for your remote server
$cfg['Servers'][$i]['password'] = 'password';  //password
$cfg['Servers'][$i]['auth_type'] = 'config';       // keep it as config

最後即可以phpmyadmin訪問 docker mysql:5.6的資料庫了

#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist 和 #1146 - Table 'phpmyadmin.pma__recent' doesn't exist 錯誤
事情是這樣子的,我虛擬機的MySQL移除後重裝Percona 5.7版本,所以把datadir/var/lib/mysql/ 直接砍掉重建,但沒備份phpmyadmin這個db(不確定原本有沒有)
這時候裝好Percona 5.7 打開phpmyadmin左側菜單想要看新建的sbtest表,結果報錯
#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist

http://stackoverflow.com/questions/24055394/1146-table-phpmyadmin-pma-tracking-doesnt-exist
直接執行 create_tables.sql 報錯
#1146 - Table 'phpmyadmin.pma__recent' doesn't exist
解法:在console 上進mysql 建立phpmyadmin表後,先手動執行以下SQL
CREATE TABLE IF NOT EXISTS `pma__tracking` (
  `db_name` varchar(64) NOT NULL,
  `table_name` varchar(64) NOT NULL,
  `version` int(10) unsigned NOT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  `schema_snapshot` text NOT NULL,
  `schema_sql` text,
  `data_sql` longtext,
  `tracking` set('UPDATE','REPLACE','INSERT','DELETE','TRUNCATE','CREATE DATABASE','ALTER DATABASE','DROP DATABASE','CREATE TABLE','ALTER TABLE','RENAME TABLE','DROP TABLE','CREATE INDEX','DROP INDEX','CREATE VIEW','ALTER VIEW','DROP VIEW') default NULL,
  `tracking_active` int(1) unsigned NOT NULL default '1',
  PRIMARY KEY  (`db_name`,`table_name`,`version`)
)
  COMMENT='Database changes tracking for phpMyAdmin'
  DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

再到phpmyadmin執行SQL  create_tables.sql
或使用
http://stackoverflow.com/questions/12760394/1146-table-phpmyadmin-pma-recent-doesnt-exist
$ sudo dpkg-reconfigure phpmyadmin  (未嘗試)