−目次
LAMP導入
Apache2 & MySQL & PHPを導入する。
Apache2
インストール
1 | $ sudo yum -y install httpd |
設定
1 | $ sudo vi /etc/httpd/conf/httpd.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # 44行目 サーバー応答ヘッダの内容を制限 ServerTokens Prod # 331行目 Indexes削除(ファイル一覧を非表示) Options Includes FollowSymLinks # 338行目 .htaccessによる上書き許可 AllowOverride All # 536行目 エラー出力時にフッター情報を非表示 ServerSignature Off # 554行目 /var/www/icons/のIndexed削除 Options MultiViews FollowSymLinks # 759行目 デフォルト文字コードを設定しない # AddDefaultCharset UTF-8 |
Apacheの設定ファイル確認
1 | $ sudo apachectl configtest |
起動
1 2 | $ sudo service httpd start $ sudo chkconfig httpd on |
シンボリックリンクを貼る
Apache2のドキュメントルートは/var/www/なのでアクセスしやすいようにする
1 2 | $ cd $ ln -s /var/www |
MySQL
インストール
1 | sudo yum -y install mysql-server |
設定
外部からは接続できないように
1 | sudo vi /etc/my.cnf |
1 2 | # 追加する skip-networking |
起動
1 2 | $ sudo /etc/rc.d/init.d/mysqld start $ sudo chkconfig mysqld on |
rootパスワードの設定
1 | $ sudo mysqladmin -u root password 'パスワード' |
PHP
レポジトリの追加
CentOSはPHPのバージョンが標準では5.3.xしか入らないので5.4.xを入るようにレポジトリを追加する
1 2 3 4 | $ sudo yum -y install wget $ wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm $ sudo rpm -Uvh epel-release-6-8.noarch.rpm remi-release-6.rpm |
追加したレポジトリの制限
1 | $ sudo vi /etc/yum.repos.d/epel.repo |
1 2 | #enabled=1 ← 「1」を「0」に変更 enabled=0 |
インストール
1 | $ sudo yum -y install php php-mysql --enablerepo=remi |
設定
1 | $ sudo vi /etc/php.ini |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # 693行目 デフォルト文字コード default_charset = "UTF-8" # 879行目 タイムゾーン date .timezone = "Asia/Tokyo" # 1658行目 [mbstring] # デフォルト言語 mbstring.language = Japanese # 内部文字エンコーディング mbstring.internal_encoding = UTF-8 # HTTP入力文字エンコーディング mbstring.http_input = UTF-8 # HTTP出力文字エンコーディング mbstring.http_output = pass # 内部文字エンコーディングの有効・無効 mbstring.encoding_translation = Off # 文字コード検出のデフォルト値 mbstring.detect_order = auto # 無効な文字を代替する文字を定義 mbstring.substitute_character = none; |
Apache再起動
1 | $ sudo service httpd restart |
確認
~/www/htmlに下記のphpinfo.phpを置き http://xxx.xxx.xxx.xxx/phpinfo.php にアクセスしMySQLが動いていることを確認
1 2 3 | <?php phpinfo(); ?> |