2016年1月26日火曜日

個人用マクロブック

個人用マクロブック(VBA)

同じマクロを何度も作成している場合は、自分のコンピューターに保存されている Personal.xlsb という特別なブックにマクロをコピーしておくことができます。

ブック毎に、マクロを作っていたのが、一元管理ができる。


2016年1月19日火曜日

Excelにバーコードを表示

コントロールパネル-フォントに、バーコードフォントというフォントを導入。
参考:http://excel-magic.com/post-10/

2016年1月16日土曜日

CakePHP インストール時エラーの対処

CakePHP2.xをダウンロードして、FTPでCentOSの公開フォルダに持って行って、ブラウザからアクセス。

エラーがたくさん出たのであとで直そっと。
参考ページ


Warning: _cake_core_ cache was unable to write 'cake_dev_ja' to File cache in /var/www/html/cakephp/lib/Cake/Cache/Cache.php on line 328

Warning: /var/www/html/cakephp/app/tmp/cache/persistent/ is not writable in /var/www/html/cakephp/lib/Cake/Cache/Engine/FileEngine.php on line 385

Fatal error: Uncaught exception 'CacheException' with message 'Cache engine "_cake_core_" is not properly configured. Ensure required extensions are installed, and credentials/permissions are correct' in /var/www/html/cakephp/lib/Cake/Cache/Cache.php:186 Stack trace: #0 /var/www/html/cakephp/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_') #1 /var/www/html/cakephp/app/Config/core.php(373): Cache::config('_cake_core_', Array) #2 /var/www/html/cakephp/lib/Cake/Core/Configure.php(72): include('/var/www/html/c...') #3 /var/www/html/cakephp/lib/Cake/bootstrap.php(431): Configure::bootstrap(true) #4 /var/www/html/cakephp/app/webroot/index.php(98): include('/var/www/html/c...') #5 /var/www/html/cakephp/index.php(41): require('/var/www/html/c...') #6 {main} thrown in /var/www/html/cakephp/lib/Cake/Cache/Cache.php on line 18



phpMyAdminのインストール

phpMyAdminをインストール
sudo yum -y install phpMyAdmin

設定ファイルを phpMyAdminフォルダに移して多く
mv /etc/phpMyAdmin/config.inc.php /usr/share/phpMyAdmin

ディレクトリにシンボリックリンクを張っておく
cd /var/www/html
ln -s /usr/share/phpMyAdmin/ phpMyAdmin


http://IPアドレス/phpMyAdminでログイン画面が表示さえることを確認


/etc/httpd/conf.dにあるphpMyAdmin.confファイルのDeny from Allをコメントアウト

   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     #Igarashi 20160111
     #Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>

2016年1月14日木曜日

Apatche mod_rewirteモジュール サンプル

シンプルなリダイレクト例

/hoge/ を /fuga/ に rewrite(リダイレクト)する。

RewriteEngine on
RewriteRule ^/hoge/$ /fuga/
/hoge/ 以下を /fuga/ 以下にまとめて rewrite(リダイレクト)する。
RewriteEngine on
RewriteRule ^/hoge/(.*)$ /fuga/$1
/hoge/ 以下で末尾が .jpg のリクエストのみを /fuga/ 以下に rewrite(リダイレクト)する。
RewriteEngine on
RewriteRule ^/hoge/(.*.jpg)$ /fuga/$1
/hoge/ 以下で末尾が .jpg か .gif のリクエストのみを /fuga/ 以下に rewrite(リダイレクト)する。
RewriteEngine on
RewriteRule ^/hoge/(.*).(jpg|gif)$ /fuga/$1.$2
/cgi-bin/hoge/fuga を /cgi-bin/example.cgi?q=hoge&opt=fuga に rewrite(リダイレクト)(いわゆる、動的アドレスを静的アドレスに変換するってやつ)
RewriteEngine on
RewriteRule ^/cgi-bin/([0-9A-Za-z]+)/([0-9A-Za-z]+)$ /cgi-bin/example.cgi?q=$1&opt=$2

リダイレクト時のブラウザのURL欄

mod_rewrite で rewrite(リダイレクト)処理を行ったとき、以下のようにサーバパスで rewrite(リダイレクト)させると、ブラウザのURL欄は書き換わらない。
RewriteEngine on
RewriteRule ^/hoge/$ /fuga/
例えば、
http://www.example.com/hoge/ にアクセスすると、
http://www.example.com/fuga/ の中身が、
URL欄は http://www.example.com/hoge/ のまま表示される。
しかし、以下の例では、リダイレクトと同時にURL欄が書き換わる。
RewriteEngine on
RewriteRule ^/hoge/$ /fuga/ [R=301]
RewriteEngine on
RewriteRule ^/hoge/$ /fuga/ [R=302]
RewriteEngine on
RewriteRule ^/hoge/$ http://www.example.com/fuga/
最後の URL にリダイレクトさせるパターンは、同じサーバ内の URL であっても、飛び先を URL で記述するとブラウザのURL欄が書き換わります
同一サーバ内であれば、URLにリダイレクトさせると無駄にログも増えるのであまりオススメしません。

アクセスを拒否する

どこかにリダイレクトするのではなく、特定のアクセスにエラーを返せます。
.htaccess へのアクセスを拒否する。
RewriteEngine On
RewriteRule .htaccess – [F]
/hoge/ 以下へのアクセスに 403 Forbidden を返します。
RewriteEngine On
RewriteRule ^/hoge/.* [F]
/hage/ 以下へのアクセスに 410 Gone を返します。
RewriteEngine On
RewriteRule ^/hage/.* [G]

複数の RewriteRule

RewriteRule は複数かけます。
/hoge/ 以下を /fuga/ 以下にリダイレクとした上に /fuga/hage/ 以下のものは /foo/ 以下にリダイレクトする。
RewriteEngine On
RewriteRule ^/hoge/(.*) /fuga/$1
RewriteRule ^/fuga/hage/(.*) /foo/$1
上の例で、/hoge/ 以下を /fuga/ 以下にリダイレクとさせた時点で処理を終わらせる、つまり次のリダイレクトを実行させないようにするには [L] を付加します
RewriteEngine On
RewriteRule ^/hoge/(.*) /fuga/$1 [L]
RewriteRule ^/fuga/hage/(.*) /foo/$1

RewriteRule のオプション

これ以外にもいろいろありますが。
HTTPステータスコードを吐く [R=ステータスコード]
RewriteEngine On
RewriteRule ^/hoge/(.*) /fuga/$1 [L,R=301]
RewriteRule ^/fuga/hage/(.*) /foo/$1
大文字、小文字を区別しない [NC]
RewriteEngine On
RewriteRule ^/hoge/(.*) /fuga/$1 [NC,L]
RewriteRule ^/fuga/hage/(.*) /foo/$1

ある条件が揃ったらリダイレクト

RewriteCond を使えば、ある条件に合致したときだけリダイレクトするということも、もちろん可能です。
HTTP_HOST が www.example.com だったら RewriteRule を適用する。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^/(.*) /$1
HTTP_HOST が www.example.com じゃなかったら RewriteRule を適用する。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^/(.*) /$1
HTTP_HOST が www.example.com で HTTP_USER_AGENT に MSIE が含まれていたら RewriteRule を適用する。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{HTTP_USER_AGENT} MSIE
RewriteRule ^/(.*) /$1
RewriteCond を複数並べると AND でつながっていく。OR にしたい場合は [OR] をつける
HTTP_HOST が www.example.com であるか、または HTTP_USER_AGENT に MSIE が含まれていたら RewriteRule を適用する。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com[OR]
RewriteCond %{HTTP_USER_AGENT} MSIE
RewriteRule ^/(.*) /$1
RewriteCond の条件で大文字、小文字を区別しない場合は [NC] をつける。
HTTP_USER_AGENT に MSIE や msie や MsIe や MSiE などが含まれていたら RewriteRule を適用する。
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} MSIE [NC]
RewriteRule ^/(.*) /$1
RewriteCond で対象となる変数には以下のようなものがあります。
HTTP_USER_AGENT / HTTP_REFERER / HTTP_COOKIE / HTTP_FORWARDED / HTTP_HOST / HTTP_PROXY_CONNECTION / HTTP_ACCEPT
REMOTE_ADDR / REMOTE_HOST / REMOTE_USER / REMOTE_IDENT / REQUEST_METHOD / SCRIPT_FILENAME / PATH_INFO / QUERY_STRING / AUTH_TYPE
DOCUMENT_ROOT / SERVER_ADMIN / SERVER_NAME / SERVER_ADDR / SERVER_PORT / SERVER_PROTOCOL / SERVER_SOFTWARE
TIME_YEAR / TIME_MON / TIME_DAY / TIME_HOUR / TIME_MIN / TIME_SEC / TIME_WDAY / TIME
API_VERSION / THE_REQUEST / REQUEST_URI / REQUEST_FILENAME / IS_SUBRE

参考ページ

vagrant+virtualboxでお手軽Linux

vagrant エラー
virtual box 5.0 から 4.1.xxにして、Virtual BoxのGUIを使う設定にてあげればできた。


# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "bento/centos-6.7"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
   config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
   config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
   config.vm.provider "virtualbox" do |vb|
     # Display the VirtualBox GUI when booting the machine
     vb.gui = true
 
     # Customize the amount of memory on the VM:
     vb.memory = "1024"
   end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   sudo apt-get update
  #   sudo apt-get install -y apache2
  # SHELL
end