LoginSignup
2
2

More than 5 years have passed since last update.

Raspberry Pi 2(略してパイ2)でLAMP

Posted at

概要

Raspberry Pi 2でLAMP環境を構築します。

Apacheのインストール

apache2.2系をインストールする場合はapache2パッケージをインストールします。

$ sudo apt-get install apache2

インストール完了後にバージョンを確認しておきます。
ブラウザからアクセスすれば「It works!」が表示されればOKです。

$ sudo apache2ctl -V
    Server version: Apache/2.2.22 (Debian)
    Server built:   Aug 18 2015 16:29:10
    Server's Module Magic Number: 20051115:30
    Server loaded:  APR 1.4.6, APR-Util 1.4.1
    Compiled using: APR 1.4.6, APR-Util 1.4.1
    Architecture:   32-bit
    Server MPM:     Worker
      threaded:     yes (fixed thread count)
        forked:     yes (variable process count)
    Server compiled with....
     -D APACHE_MPM_DIR="server/mpm/worker"
     -D APR_HAS_SENDFILE
     -D APR_HAS_MMAP
     -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
     -D APR_USE_SYSVSEM_SERIALIZE
     -D APR_USE_PTHREAD_SERIALIZE
     -D APR_HAS_OTHER_CHILD
     -D AP_HAVE_RELIABLE_PIPED_LOGS
     -D DYNAMIC_MODULE_LIMIT=128
     -D HTTPD_ROOT="/etc/apache2"
     -D SUEXEC_BIN="/usr/lib/apache2/suexec"
     -D DEFAULT_PIDLOG="/var/run/apache2.pid"
     -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
     -D DEFAULT_ERRORLOG="logs/error_log"
     -D AP_TYPES_CONFIG_FILE="mime.types"
     -D SERVER_CONFIG_FILE="apache2.conf"

MySQLのインストール

mysql5.5系をインストールする場合はmysql-serverパッケージをインストールします。

$ sudo apt-get install mysql-server

mysqlコマンドで接続確認を行います。
つながればOKでしょう。

$ mysql -u root -h localhost -p
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 43
    Server version: 5.5.44-0+deb7u1 (Debian)

    Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    3 rows in set (0.00 sec)

    mysql> quit
    Bye

PHPのインストール

php5.4系をインストールする場合はphp5パッケージをインストールします。

$ sudo apt-get install php5

インストールが完了したらコマンドからバージョンを確認しておきましょう。

$ php -v
    PHP 5.4.45-0+deb7u1 (cli) (built: Sep 13 2015 17:25:45)
    Copyright (c) 1997-2014 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

PHPからMySQLが扱えるようにphp5-mysqlパッケージもインストールしておきます。

$ sudo apt-get install php5-mysql

最後にテスト用のPHPプログラムを配置して最終確認を行います。
デフォルトのドキュメントルートは「/var/www/」になっているため、そこにtest.phpを作成します。

$ sudo vi /var/www/test.php
<?php
    phpinfo();

ブラウザからアクセスすれば、phpinfoが表示されるはずです。
内容を確認し問題なければ完了です。

最後に、確認用に作成したtest.phpは削除しておきましょう。
これが公開されたままになっているサイトを見かけますが、バージョン情報等がバレてしまうため、セキュリティ的にまずいです。

$ sudo rm /var/www/test.php
2
2
0

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
2
2