LoginSignup
15
13

More than 5 years have passed since last update.

MacでXAMPPを使ってApecheサーバーをたてる

Last updated at Posted at 2015-06-16

XAMPPはApacheとMySQLとPHPとPerlがセットになったソフトウェアです。Windows、Linux、Macそれぞれで利用でき、自分のマシンを簡単にWebサーバーにすることが出来ます。

今回はMacの場合の利用方法を書きます。

XAMPPのインストールとセットアップ

XAMPPをインストールする。
XAMPP Installers and Downloads for Apache Friends

/Application/XAMPP 下にインストールされる。
/Application/XAMPP/xamppfiles/etc下にApacheの各種設定ファイルが有る。

httpd.confの設定

/Application/XAMPP/xamppfiles/etc/httpd.conf
Apacheの実行ユーザーを自分に変更

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User niwatako
Group staff
</IfModule>

Apacheが外部に公開するディレクトリ(DocumentRoot)を~/www変更

# 
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/Users/niwatako/www"

ディレクトリ~/wwwについての設定を追加

<Directory "/Users/niwatako/www">
    # ディレクトリに対して使用可能な機能の設定
    ## Indexes          ディレクトリにindexファイルがない時、内容の一覧を表示
    ## FollowSymLinks   シンボリックリンクを許可
    ## ExecCGI          CGIスクリプトの実行を許可
    ## Includes         SSIを有効化
    Options Indexes FollowSymLinks ExecCGI Includes

    # .htaccess での設定の上書きを許可
    AllowOverride All

    # 全てのアクセス元からのリクエストを許可
    Require all granted
    ## IPを叩けばこのサーバーにアクセスできる。
    ## パブリックなLANや勉強会の共有Wi-Fiにつなぐと
    ## 客先に関係するテストページが見えてしまうことになり得るので注意。
    ## 特定IPからの接続のみ許可する場合は
    ## Require ip xxx.xxx.xxx.xxx
</Directory>

index.htmlファイルの作成とApacheの起動

~/www/index.htmlファイルを以下の様な内容で作成

<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="UTF-8">
        <title>テストページ</title>
    </head>
    <body>
        XAMPPサーバーがページを表示しています。
    </body>
</html>

XAMPPを起動して、ApacheをStartしてみましょう。
無事Startさせることができたら、ブラウザでhttp://localhost/へアクセスして、XAMPPサーバーがページを表示しています。というページが表示されるか確認します。

Apacheが起動しない場合

エラーメッセージをヒントに原因を探します。

httpd.confの記載内容に間違いはないですか?タイポや全角スペースなどが混じっていないか気をつけます。

ポート80番が既に利用されていて起動できないことがよく有ります。ポート80を他のアプリが利用していないか確認して下さい。

Skypeなどがポート80番を使用している場合があります(最新版はしていないかも)。確認の上、使用しているアプリがあれば同時起動を避けるか、そのアプリの設定からポートを変更して下さい。

15
13
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
13