ラベル PHP の投稿を表示しています。 すべての投稿を表示
ラベル PHP の投稿を表示しています。 すべての投稿を表示

4.27.2012

WordPress (1)

27th Apr 2012

UbuntuにWordPressをインストールした時のメモ。

cd dev
wget http://wordpress.org/latest.tar.gz
tar zxf latest.tar.gz
rm latest.tar.gz
ls wordpress/
sudo ln -s /home/sotaro/dev/wordpress /var/www/wp
sudo chmod 777 wordpress

mysql> create database wordpress;
mysql> CREATE USER 'wp'@'localhost' IDENTIFIED BY 'wordpress'
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wp'@'localhost';

http://localhost/wp からログイン、DBに関する情報を入力して終了。

と思いきや、、、
テーマの追加を試み、FTPが必要であることが判明。
で、FTP。

sudo apt-get install proftpd
(xinetd or standaloneで xinetd を選ぶ)


ProFTPD warning: cannot start neither in standalone nor in inetd/xinetd mode. Check your configuration.
vi /etc/init.d/proftpd

といことで、/etc/init.d/proftpdを見ると

 49   if egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.conf 2>/dev/null || \
 50      egrep -qi "server[[:space:]]*=[[:space:]]*/usr/sbin/proftpd" /etc/xinetd.d/* 2>/dev/null || \
 51      egrep -qi "^ftp.*/usr/sbin/proftpd" /etc/inetd.conf 2>/dev/null 

そういえば、sshdもあげてないし、xinetdが無いのか!ってことで

sudo apt-get install xinetd
sudo vi /etc/xinetd.d/ftp
cat /etc/xinetd.d/ftp
service ftp
{
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/sbin/proftpd
}
sudo /etc/init.d/xinetd restart

アカウントは

sudo useradd -g www-data -M wordpress
sudo passwd wordpress

で用意し、再度テーマの追加に挑む。が、permissionで色々怒られ

sudo chown -R wordpress:www-data *
sudo find . -type d -exec chmod 775 {} \;
sudo find . -type f -exec chmod 666 {} \;

でようやく完了。

※追記
apacheの設定に下記を追加


  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all

2.16.2012

Zend Framework ~ install & setup on Ubuntu

16 Feb 2012

1. install
Zend Framework 1.11.11 full をインストールする
(参考) http://tutology.net/category/zend-framework/how-install-zend-framework-ubuntu

2. Vitrual host 関連
2.1 enable mod_rewrite
$ cd /etc/apache2/mods-enabled
$ sudo vi rewrite.load
$ cat rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
$ sudo /etc/init.d/apache2 restart

2.2 add virtual host setting
$ cd /etc/apache2/sites-available
$ sudo cp default zf
$ sudo vi zf
$ cat zf

(snip)
<VirtualHost *:80>
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/zf
 ServerName zf.com

 <Directory /var/www/zf/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  DirectoryIndex index.php
  Order allow,deny
  allow from all
 </Directory>

 RewriteEngine Off

 <Location />
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
 </Location>
</VirtualHost>
$ sudo a2ensite zf
$ sudo /etc/init.d/apache2 restart
$ cd /var/www
$ sudo mkdir zf
$ cd zf
$ sudo vi index.php
$ cat index.php
<?php
echo 'hello';
?>
$ sudo vi /etc/hosts
$ cat /etc/hosts | grep zf
127.0.0.1 zf.com
これで準備完了で、いよいよZend Framework。
(参考) http://framework.zend.com/manual/en/learning.quickstart.html


12.04.2011

Getting used to 101

4 Dec 2011

I've been using 106-Key keyboard for over 10 years which is the most common in Japan. It has a nearly same layout with 101-Key keyboard but some keys such as ', @, \, &, are placed differently. Therefore, I need to get used to 101 and tried a practice problem from NZPC, New Zealand Programming Contest.

長年慣れ親しんだ106キーボード、キーの配置は101キーボードのそれとほぼ同じだが、@マークやクォート等、記号の配置が微妙に異なる。半角/全角など、キーを増やすのは分かるが、なぜレイアウトまで変えちゃうのよ?!と小言を言いつつ、NZPC - New Zealand Programming Contestで新しいレイアウトに慣れる。NZPCはIT学科の大学院生が教えてくれたサイトで、その名の通りプログラミングコンテスト。

現在は受付を終了していて、こちらの練習問題、Word Finderに挑戦。

英語の理解にちょっと苦労するが、
1.行列のサイズ
2.行列に配置する単語(順番は、左→右、上→下で行列にぴったり収まる)
3.行列中に存在するか検索する文字列
の3種類のパラメータを標準入力から受け取り、検索文字列の有無、有る場合はその位置(開始・終了)を表示する、という感じ。

で、配列を使って、こんな感じかな?っと何となく取っ掛かりのイメージができた所で、行き当たりばったりのコーディングを開始。書き終えて、ざっと動作確認をして、ソースをきれいにした所で3時間半。もうちょっと(大分)早くできる思ったけど、、、

おかげで新しいキー配置にはかなり慣れることができました。
ソースはこちら。コンテストでは使えないPHPで書いた。

10.10.2010

[PHP]simplexml

Yahoo! Weather の RSS Feed をsimplexmlでパースする。

まずは、
取得したXMLをsimplexml_load_string()でsimplexmlオブジェクトに展開する。
$xml = file_get_contents($rss);
  $w = simplexml_load_string($xml);
後は、
default namespaceの要素を取得するなら、
引数なしでchildren()と実行し、
$ch = $w->channel->children();
namespaceの指定がある要素を取得するなら、
children($namespace) と引数ありで実行するだけ。
$ch = $w->channel->children($namespace);
全体はこんな感じ。
$ cat weather.php
<?php

  $rss = "http://weather.yahooapis.com/forecastrss?w=2348079&u=c";
  $xml = file_get_contents($rss);
  if(!$xml) exit(1);
  $w = simplexml_load_string($xml);

  $yw  = "http://xml.weather.yahoo.com/ns/rss/1.0";
  $geo = "http://www.w3.org/2003/01/geo/wgs84_pos#"

  // default namespace <channel><title>
  $ch = $w->channel->children();
  foreach($ch as $k => $v){
    if($k === "lastBuildDate") $weather[$k] = $v;
  }

  // <channel><yweather>
  $ch = $w->channel->children($yw);
  foreach($ch as $category => $kv){
    foreach($kv->attributes() as $k => $v){ 
      $category = (string)$category;
      $k = (string)$k;
      $v = (string)$v;
      $weather[$category][$k]=$v;
    }
  }

  // <channel><item><geo>
  $ch = $w->channel->item->children($geo);
  foreach($ch as $k => $v){
    $k = (string)$k;
    $v = (string)$v;
    $weather["location"][$k] = $v;
  }

  // <channel><item><yweather>
  $item = $w->channel->item->children($yw);
  foreach($item as $category => $kv){
    foreach($kv->attributes() as $k => $v){
      $category = (string)$category;
      $k = (string)$k;
      $v = (string)$v;
      if($k === "day" && $category === "forecast") $day = $v;
      if($category === "forecast"){
        $weather[$category][$day][$k] = $v;
      }
      else{
        $weather[$category][$k] = $v;
      }
    }
  }

  print_r($weather);
?>
実行すると
$ php weather.php
Array
(
    [location] => Array
        (  
            [city] => Auckland
            [region] =>
            [country] => New Zealand
            [lat] => -36.88
            [long] => 174.77
        )

    [units] => Array
        (  
            [temperature] => C
            [distance] => km
            [pressure] => mb
            [speed] => km/h
        )

    [wind] => Array
        (  
            [chill] => 11
            [direction] => 270
            [speed] => 24.14
        )

    [atmosphere] => Array
        (  
            [humidity] => 94
            [visibility] => 9.99
            [pressure] => 1015.92
            [rising] => 0
        )

    [astronomy] => Array
        (  
            [sunrise] => 6:43 am
            [sunset] => 7:32 pm
        )

    [condition] => Array
        (
            [text] => Rain Shower
            [code] => 11
            [temp] => 11
            [date] => Mon, 11 Oct 2010 2:00 am NZDT
        )

    [forecast] => Array
        (
            [Mon] => Array
                (
                    [day] => Mon
                    [date] => 11 Oct 2010
                    [low] => 8
                    [high] => 13
                    [text] => Showers
                    [code] => 11
                )

            [Tue] => Array
                (
                    [day] => Tue
                    [date] => 12 Oct 2010
                    [low] => 12
                    [high] => 16
                    [text] => Partly Cloudy
                    [code] => 30
                )

        )

)


便利だね、simplexml!!