Zend Framework環境構築

来週から仕事でZend Framework + MySQLを使うことになったので開発環境を作ったメモ。

MySQLインストール

mysqlユーザ作成
groupadd -g 2008 mysql
useradd -u 2008 -g mysql -d /home/mysql -m -s /bin/bash mysql
mysqlインストール
apt-get install mysql-server mysql-client libmysqlclient-dev
my.cnf編集
vi /etc/mysql/my.cnf
[mysqld]
# 追記
character-set-server = utf8
skip-character-set-client-handshake
collation-server = utf8_general_ci
init-connect = SET NAMES utf8

[mysql]
# 追記
default-character-set = utf8
MySQL再起動、初期設定
/etc/init.d/mysql restart
mysql_secure_installation

PHPインストール

基本的には以下のページと同じ手順。
configure optionは以下のとおり。

./configure --enable-mbstring --enable-soap --enable-zend-multibyte --enable-mbregex --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --with-pdo-mysql --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr

PHPインストール - i2bsの日記

Zend Frameworkダウンロード

ダウンロードはここから。(登録が必要)
Zend Framework

Zend Framework配置

cd /usr/local/lib
tar zxvf /tmp/ZendFramework-1.11.11-minimal.tar.gz
ln -s /usr/local/lib/ZendFramework-1.11.11-minimal /usr/local/lib/zend
cp -pi ZendFramework-1.11.11-minimal/bin/zf.php /usr/local/bin/.
cp -pi ZendFramework-1.11.11-minimal/bin/zf.sh /usr/local/bin/.
ln -s /usr/local/bin/zf.sh /usr/local/bin/zf

php.ini編集

vi /usr/local/lib/php.ini
default_charset = "UTF-8"
include_path = ".:/usr/local/lib/zend/library"

mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = pass
mbstring.encoding_translation = Off
mbstring.detect_order = SJIS,EUC-JP,JIS,UTF-8,ASCII
mbstring.substitute_character = none;

プロジェクト作成

zf create project /usr/local/zend_app
rm /usr/local/zend_app/public/.htaccess

vhosts作成

mkdir -p /usr/local/apache/vhosts/xxx.com/{logs,ssl.crt,ssl.key}
vi /usr/local/apache/conf/conf.d/xxx.com.conf
<VirtualHost xx.xx.xx.xx:80>
    ServerName xxx.com
    DocumentRoot /usr/local/zend_app/public
    ErrorLog /usr/local/apache/vhosts/xxx.com/logs/error_log
    CustomLog "/usr/local/apache/vhosts/xxx.com/logs/access_log" combined

    RewriteEngine off
 
    <Location />
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} -s [OR]
        RewriteCond %{REQUEST_FILENAME} -l [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^.*$ - [NC,L]
        RewriteRule ^.*$ /index.php [NC,L]
    </Location>
</VirtualHost>

#<VirtualHost xx.xx.xx.xx:443>
#    ServerName xxx.com
#    DocumentRoot /usr/local/apache/vhosts/xxx.com/htdocs
#    ErrorLog /usr/local/apache/vhosts/xxx.com/logs/ssl_error_log
#    CustomLog "/usr/local/apache/vhosts/xxx.com/logs/ssl_access_log" combined
#
#    SSLEngine on
#    SSLCertificateFile /usr/local/apache/vhosts/xxx.com/ssl.crt/server.crt
#    SSLCertificateKeyFile /usr/local/apache/vhosts/xxx.com/ssl.key/server.key
#
#    RewriteEngine off
#
#    <Location />
#        RewriteEngine On
#        RewriteCond %{REQUEST_FILENAME} -s [OR]
#        RewriteCond %{REQUEST_FILENAME} -l [OR]
#        RewriteCond %{REQUEST_FILENAME} -d
#        RewriteRule ^.*$ - [NC,L]
#        RewriteRule ^.*$ /index.php [NC,L]
#    </Location>
#</VirtualHost>

<Directory /usr/local/zend_app/public>
    Options Includes ExecCGI FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Apache再起動

/usr/local/bin/httpd -t
/usr/local/bin/apachectl graceful