2015年8月15日土曜日

Web開発環境(Mac OS X Yosemite+PHP+MySql)の構築 - Apache


はじめに

OS X yosemite では、すでにApache2.4がインストールされています。
1 からのWeb開発環境の構築をしたいので、今回は、インストール済みのApacheはそのままとして、HomebrewでApache2.2をインストールする手順でApacheの環境構築をして行きます。
では、早速実施していきましょう。

Apacheの確認

$ httpd -v
Server version: Apache/2.4.10 (Unix)
Server built:   May 19 2015 09:36:36
$ which httpd
/usr/sbin/httpd
$ apachectl -v
Server version: Apache/2.4.10 (Unix)
Server built:   May 19 2015 09:36:36
$ which apachectl
/usr/sbin/apachectl

Apacheの確認

$ brew search httpd
darkhttpd libmicrohttpd lighttpd mighttpd2
homebrew/devel-only/httpd22  homebrew/emacs/simple-httpd
homebrew/devel-only/httpd24  homebrew/head-only/httpdiff

リポジトリの追加

$ brew tap homebrew/dupes
$ brew tap homebrew/apache

Apacheのインストール

$ brew install httpd22

Apacheのインストール確認

$ httpd -v
Server version: Apache/2.4.10 (Unix)
Server built:   May 19 2015 09:36:36
$ which httpd
/usr/local/bin/httpd
$ apachectl -v
Server version: Apache/2.4.10 (Unix)
Server built:   May 19 2015 09:36:36
$ which apachectl
/usr/local/bin/apachectl

Apache2.2 httpd-conf-の設定

$ sudo vi /usr/local/etc/apache2/2.2/httpd.conf
#LoadModule php5_module libexec/apache2/libphp5.so
↓
LoadModule php5_module libexec/apache2/libphp5.so

Apache2.4 httpd-conf-の設定

$ vi /usr/local/etc/apache2/2.2/httpd.conf
ServerNameの設定
#ServerName www.example.com:8080
↓
ServerName localhost:8080
DocumentRootの設定
#DocumentRoot "/usr/local/var/www/htdocs"
#
↓
DocumentRoot "/Users/ユーザ名/work/MyWebTest"

.htaccessの制御
#AllowOverride None
↓
AllowOverride All
PHPの有効設定

   #DirectoryIndex index.html
 ↓
    DirectoryIndex index.php index.html

バーチャルホストの設定
# Virtual hosts
#Include /usr/local/etc/apache2/2.2/extra/httpd-vhosts.conf
↓
Include /usr/local/etc/apache2/2.2/extra/httpd-vhosts.conf

Apacheの 再起動
$ apachectl restart

Apacheの削除

$ brew remove httpd24
rm -rf /usr/local/etc/apache2/2.2
rm -rf /usr/local/var/log/apache2

Apacheの自動起動

$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

バーチャルホストファイルの設定

$ 
    DocumentRoot "/Users/ユーザ名/work/MyWebTest"
    ServerName mywebtest.localhost
    ErrorLog "/Users/ユーザ名/work/MyWebTest/log/error_log"
    CustomLog "/Users/ユーザ名/work/MyWebTest/log/access_log" common

    
        Options Indexes FollowSymLinks
        AllowOverride All
        Allow from all
    

ホストファイルの設定

$ sudo vi /etc/hosts
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

127.0.0.1       mywebtest.localhost

0 件のコメント:

コメントを投稿