2012年6月4日月曜日

emacs定義ファイル

~/.emacs.d/init.elのメモ
;(setq make-backup-files nil)
;(setq auto-save-default nil)

(autoload 'php-mode "php-mode")
(setq auto-mode-alist
      (cons '("\\.php\\'" . php-mode) auto-mode-alist))
(setq php-mode-force-pear t)
(add-hook 'php-mode-user-hook
  '(lambda ()
     (setq php-manual-path "/usr/local/share/php/doc/html")
     (setq php-manual-url "http://www.phppro.jp/phpmanual/")))

PHP Warning: file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0

エラーメッセージ PHP Warning: file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /var/www/html/blog/wp-content/themes/lumiukko/make_newrelease_amazon.php on line 9 /etc/php.iniファイルを編集。
allow_url_fopen = On

php Cache_Liteをインストール

phpでキャッシュを使いたいので、Cache_Liteライブラリをインストール。 その前に、pearがインストールされていない場合には、そちらを先に。
# yum -y install php53u-pear
Loaded plugins: fastestmirror, priorities, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
 * ius: mirror.rackspace.com
 * sl: ftp.riken.jp
 * sl-security: ftp.riken.jp
103 packages excluded due to repository priority protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php53u-pear.noarch 1:1.9.4-3.ius.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================
 Package                     Arch                   Version                             Repository           Size
==================================================================================================================
Installing:
 php53u-pear                 noarch                 1:1.9.4-3.ius.el6                   ius                 384 k

Transaction Summary
==================================================================================================================
Install       1 Package(s)

Total download size: 384 k
Installed size: 2.2 M
Downloading Packages:
php53u-pear-1.9.4-3.ius.el6.noarch.rpm                                                     | 384 kB     00:01     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:php53u-pear-1.9.4-3.ius.el6.noarch                                                           1/1 

Installed:
  php53u-pear.noarch 1:1.9.4-3.ius.el6                                                                            

Complete!
続いてCache_Lite
# pear install Cache_Lite
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
downloading Cache_Lite-1.7.12.tgz ...
Starting to download Cache_Lite-1.7.12.tgz (30,469 bytes)
.........done: 30,469 bytes
install ok: channel://pear.php.net/Cache_Lite-1.7.12

WordPressの引越し

引越しの流れは以下の通り。
  1. 引越し先にWordPressをインストール
  2. プラグインをインストール
  3. テーマをインストール
  4. バックアップ
  5. リストア

バックアップ取得

databaseと画像などのアップロードファイルをバックアップ。
$ mysqldump --user=hide --password=yukizou5 --host=localhost --databases blog >wp_db.sql
$ (cd /var/www/html/blog/wp-content/uploads/; tar cf - .) | gzip -c >wp_uploads.tgz
2つのファイルを引っ越先のサーバーのアップロード。
$ sftp -o Port=2022 49.212.129.72
Connecting to 49.212.129.72...
hoge@49.212.129.72's password:

sftp> put wp_db.sql
sftp> put wp_uploads.tgz

リストア

wp_db.sqlとwp_uploads.tgzをリストア。
$ mysql -u hide -p blog <wp_db.sql
Enter password: 
$ cd /var/www/html/blog/wp-content/uploads
$ tar zxf /home/hoge/wp_uploads.tgz

mysqlのインストールと設定

インストール

# yum -y install mysql-server mysql
Loaded plugins: fastestmirror, priorities, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
 * ius: archive.linux.duke.edu
 * sl: ftp.riken.jp
 * sl-security: ftp.riken.jp
103 packages excluded due to repository priority protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.61-1.el6_2.1 will be installed
---> Package mysql-server.x86_64 0:5.1.61-1.el6_2.1 will be installed
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.61-1.el6_2.1.x86_64
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.61-1.el6_2.1.x86_64
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.61-1.el6_2.1.x86_64
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package                  Arch             Version                     Repository             Size
===================================================================================================
Installing:
 mysql                    x86_64           5.1.61-1.el6_2.1            sl-security           881 k
 mysql-server             x86_64           5.1.61-1.el6_2.1            sl-security           8.1 M
Installing for dependencies:
 perl-DBD-MySQL           x86_64           4.013-3.el6                 sl                    133 k
 perl-DBI                 x86_64           1.609-4.el6                 sl                    704 k

Transaction Summary
===================================================================================================
Install       4 Package(s)

Total download size: 9.8 M
Installed size: 28 M
Downloading Packages:
(1/4): mysql-5.1.61-1.el6_2.1.x86_64.rpm                                    | 881 kB     00:00     
(2/4): mysql-server-5.1.61-1.el6_2.1.x86_64.rpm                             | 8.1 MB     00:02     
(3/4): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm                                | 133 kB     00:00     
(4/4): perl-DBI-1.609-4.el6.x86_64.rpm                                      | 704 kB     00:00     
---------------------------------------------------------------------------------------------------
Total                                                              3.2 MB/s | 9.8 MB     00:03     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : perl-DBI-1.609-4.el6.x86_64                                                     1/4 
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                               2/4 
  Installing : mysql-5.1.61-1.el6_2.1.x86_64                                                   3/4 
  Installing : mysql-server-5.1.61-1.el6_2.1.x86_64                                            4/4 

Installed:
  mysql.x86_64 0:5.1.61-1.el6_2.1              mysql-server.x86_64 0:5.1.61-1.el6_2.1             

Dependency Installed:
  perl-DBD-MySQL.x86_64 0:4.013-3.el6                 perl-DBI.x86_64 0:1.609-4.el6                

Complete!

起動設定

自動起動の設定。
# chkconfig mysqld on

初期設定

/etc/my.cnfファイルを編集。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8
skip-name-resolve
skip-innodb
default-storage-engine=MyISAM

key_buffer = 128M
max_allowed_packet = 16M
join_buffer = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 768K
thread_stack = 192K
thread_cache_size = 512
max_connections = 300
table_cache = 1024
tmp_table_size = 16M
thread_concurrency = 4
query_cache_limit = 4M
query_cache_size = 64M
query_cache_min_res_unit= 4k
query_cache_type = 1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
default-character-set = utf8

[isamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M
mysqldを起動。
# service mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h 49.212.129.72 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]
mysql_secure_installationを実行し、セキュリティ設定を行う。
# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

php-fpmのインストールと設定

インストール

# yum -y install php53u-common php53u-fpm php53u-mysql php53u-gd php53u-mbstring php53u-xml
Loaded plugins: fastestmirror, priorities, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
 * ius: mirror.rackspace.com
 * sl: ftp.riken.jp
 * sl-security: ftp.riken.jp
103 packages excluded due to repository priority protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php53u-common.x86_64 0:5.3.10-1.ius.el6 will be installed
---> Package php53u-fpm.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Processing Dependency: php53u = 5.3.10-1.ius.el6 for package: php53u-fpm-5.3.10-1.ius.el6.x86_64
---> Package php53u-gd.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Processing Dependency: libt1.so.5()(64bit) for package: php53u-gd-5.3.10-1.ius.el6.x86_64
---> Package php53u-mbstring.x86_64 0:5.3.10-1.ius.el6 will be installed
---> Package php53u-mysql.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Processing Dependency: php53u-pdo for package: php53u-mysql-5.3.10-1.ius.el6.x86_64
---> Package php53u-xml.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Running transaction check
---> Package php53u.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Processing Dependency: php53u-cli = 5.3.10-1.ius.el6 for package: php53u-5.3.10-1.ius.el6.x86_64
--> Processing Dependency: httpd-mmn = 20051115 for package: php53u-5.3.10-1.ius.el6.x86_64
--> Processing Dependency: libtool-ltdl for package: php53u-5.3.10-1.ius.el6.x86_64
---> Package php53u-pdo.x86_64 0:5.3.10-1.ius.el6 will be installed
---> Package t1lib.x86_64 0:5.1.2-6.el6_2.1 will be installed
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-15.sl6.1 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-15.sl6.1 for package: httpd-2.2.15-15.sl6.1.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-15.sl6.1.x86_64
---> Package libtool-ltdl.x86_64 0:2.2.6-15.5.el6 will be installed
---> Package php53u-cli.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Running transaction check
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.x86_64 0:2.2.15-15.sl6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package                   Arch             Version                    Repository             Size
===================================================================================================
Installing:
 php53u-common             x86_64           5.3.10-1.ius.el6           ius                   525 k
 php53u-fpm                x86_64           5.3.10-1.ius.el6           ius                   1.5 M
 php53u-gd                 x86_64           5.3.10-1.ius.el6           ius                   108 k
 php53u-mbstring           x86_64           5.3.10-1.ius.el6           ius                   457 k
 php53u-mysql              x86_64           5.3.10-1.ius.el6           ius                    80 k
 php53u-xml                x86_64           5.3.10-1.ius.el6           ius                   102 k
Installing for dependencies:
 apr-util-ldap             x86_64           1.3.9-3.el6_0.1            sl                     15 k
 httpd                     x86_64           2.2.15-15.sl6.1            sl-security           812 k
 httpd-tools               x86_64           2.2.15-15.sl6.1            sl-security            69 k
 libtool-ltdl              x86_64           2.2.6-15.5.el6             sl                     43 k
 php53u                    x86_64           5.3.10-1.ius.el6           ius                   1.5 M
 php53u-cli                x86_64           5.3.10-1.ius.el6           ius                   2.9 M
 php53u-pdo                x86_64           5.3.10-1.ius.el6           ius                    63 k
 t1lib                     x86_64           5.1.2-6.el6_2.1            sl-security           159 k

Transaction Summary
===================================================================================================
Install      14 Package(s)

Total download size: 8.2 M
Installed size: 26 M
Downloading Packages:
(1/14): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm                            |  15 kB     00:00     
(2/14): httpd-2.2.15-15.sl6.1.x86_64.rpm                                    | 812 kB     00:00     
(3/14): httpd-tools-2.2.15-15.sl6.1.x86_64.rpm                              |  69 kB     00:00     
(4/14): libtool-ltdl-2.2.6-15.5.el6.x86_64.rpm                              |  43 kB     00:00     
(5/14): php53u-5.3.10-1.ius.el6.x86_64.rpm                                  | 1.5 MB     00:02     
(6/14): php53u-cli-5.3.10-1.ius.el6.x86_64.rpm                              | 2.9 MB     00:03     
(7/14): php53u-common-5.3.10-1.ius.el6.x86_64.rpm                           | 525 kB     00:01     
(8/14): php53u-fpm-5.3.10-1.ius.el6.x86_64.rpm                              | 1.5 MB     00:02     
(9/14): php53u-gd-5.3.10-1.ius.el6.x86_64.rpm                               | 108 kB     00:00     
(10/14): php53u-mbstring-5.3.10-1.ius.el6.x86_64.rpm                        | 457 kB     00:01     
(11/14): php53u-mysql-5.3.10-1.ius.el6.x86_64.rpm                           |  80 kB     00:00     
(12/14): php53u-pdo-5.3.10-1.ius.el6.x86_64.rpm                             |  63 kB     00:00     
(13/14): php53u-xml-5.3.10-1.ius.el6.x86_64.rpm                             | 102 kB     00:00     
(14/14): t1lib-5.1.2-6.el6_2.1.x86_64.rpm                                   | 159 kB     00:00     
---------------------------------------------------------------------------------------------------
Total                                                              389 kB/s | 8.2 MB     00:21     
警告: rpmts_HdrFromFdno: ヘッダ V4 DSA/SHA1 Signature, key ID 9cd4953f: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
Importing GPG key 0x9CD4953F:
 Userid : IUS Community Project 
 Package: ius-release-1.0-10.ius.el6.noarch (installed)
 From   : /etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : php53u-common-5.3.10-1.ius.el6.x86_64                                          1/14 
  Installing : t1lib-5.1.2-6.el6_2.1.x86_64                                                   2/14 
  Installing : php53u-pdo-5.3.10-1.ius.el6.x86_64                                             3/14 
  Installing : php53u-cli-5.3.10-1.ius.el6.x86_64                                             4/14 
  Installing : libtool-ltdl-2.2.6-15.5.el6.x86_64                                             5/14 
  Installing : httpd-tools-2.2.15-15.sl6.1.x86_64                                             6/14 
  Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                           7/14 
  Installing : httpd-2.2.15-15.sl6.1.x86_64                                                   8/14 
  Installing : php53u-5.3.10-1.ius.el6.x86_64                                                 9/14 
  Installing : php53u-fpm-5.3.10-1.ius.el6.x86_64                                            10/14 
  Installing : php53u-mysql-5.3.10-1.ius.el6.x86_64                                          11/14 
  Installing : php53u-gd-5.3.10-1.ius.el6.x86_64                                             12/14 
  Installing : php53u-mbstring-5.3.10-1.ius.el6.x86_64                                       13/14 
  Installing : php53u-xml-5.3.10-1.ius.el6.x86_64                                            14/14 

Installed:
  php53u-common.x86_64 0:5.3.10-1.ius.el6         php53u-fpm.x86_64 0:5.3.10-1.ius.el6             
  php53u-gd.x86_64 0:5.3.10-1.ius.el6             php53u-mbstring.x86_64 0:5.3.10-1.ius.el6        
  php53u-mysql.x86_64 0:5.3.10-1.ius.el6          php53u-xml.x86_64 0:5.3.10-1.ius.el6             

Dependency Installed:
  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1            httpd.x86_64 0:2.2.15-15.sl6.1                 
  httpd-tools.x86_64 0:2.2.15-15.sl6.1              libtool-ltdl.x86_64 0:2.2.6-15.5.el6           
  php53u.x86_64 0:5.3.10-1.ius.el6                  php53u-cli.x86_64 0:5.3.10-1.ius.el6           
  php53u-pdo.x86_64 0:5.3.10-1.ius.el6              t1lib.x86_64 0:5.1.2-6.el6_2.1                 

Complete!

設定

/etc/php.iniの基本設定。
post_max_size = 15M
upload_max_filesize = 15M

allow_url_fopen = On

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Asia/Tokyo"
/etc/php-fpm.d/www.confを編集。
listen = /var/run/php-fpm.sock
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
user = nginx
group = nginx

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
細かなチューニングは後で実施。

起動設定

自動起動に設定し、サービスを起動。
# chkconfig php-fpm on
# service php-fpm start
php-fpm を起動中:                                          [  OK  ]

WordPress install memo

準備

WordPressをインストールするために、必要なパッケージをインストール。

データベース作成

WordPress用にデータベースを作成。
# mysql -u root -p

mysql> create database blog;
Query OK, 1 row affected (0.00 sec)

mysql> grant all privileges on blog.* to "hoge"@"localhost" identified by "password";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

ダウンロードと展開

# wget http://ja.wordpress.org/wordpress-3.3.1-ja.tar.gz
# tar -xzvf wordpress-3.3.1-ja.tar.gz
# mv wordpress /var/www/html/blog
# chown -R hoge.hoge /var/www/html/blog

設定

wp-config.phpファイルを作成。
$ mv wp-config-sample.php wp-config.php
$ vi wp-config.php

インストール

ブラウザから、http://blog.lumiukko.jp/wp-admin/install.phpにアクセスしてインストール。