インストール
Apache
本体をインストールします。
# yum install httpd24
SSL通信モジュールをインストールします。
# yum install mod24_ssl
PHP
本体をインストールします。
# yum install php70
OPCache+APCu 高速化するためのモジュールをインストールします。
# yum install php70-opcache php70-pecl-apcu
必要になる可能性が高いモジュールをインストールします。
# yum install php70-gd php70-mbstring php70-mcrypt php70-pdo
MySQL
本体をインストールします。
# yum install mysql56-server
設定
Apache
セキュリティ設定を入れます。Apacheバージョン情報を非表示にします。
# cd /etc/httpd/conf # cp httpd.conf httpd.conf.org # vi httpd.conf
末尾に追加します
# Apache バージョン非表示 ServerTokens Prod
SSLの設定を行います。

Amazon Linux + Apache + Let's Encrypt のインストール
事前準備インストールは自動化されていますので、動かすための必要パッケージをインストールをします。# yum -y install gitLet's Encryptのインストール# cd /etc# git clone SSL証明書の取得既に...
PHP
セキュリティ設定を入れます。X-Powered-ByからPHPバージョン情報を非表示にします。
# cd /etc/ # cp php.ini php.ini.org # vi php.ini
# PHP バージョン非表示 expose_php = Off
MySQL
mysqlの初期設定
「root」ユーザパスワード設定、「anonymous」ユーザ、「test」データベースなどを削除します。
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): <-- 「Enter」キーを押下 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y <-- 「y」 New password: <-- rootユーザパスワード設定 Re-enter new password: <-- 再入力 Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y <-- 「y」 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y <-- 「y」 By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y <-- 「y」 - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y <-- 「y」 Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
設定ファイルの変更
文字コードと各種パラメータを変更します。
[mysqld] character-set-server = utf8 innodb_buffer_pool_size = 512M query_cache_size = 64M
動作確認
Apache、PHP、MySQLが動くか確認します。
テストデータ
MySQLにテストデータと投入します。
# mysql -u root -p Enter password: mysql> GRANT ALL PRIVILEGES ON test.* TO "test"@"localhost" IDENTIFIED BY "password"; mysql> FLUSH PRIVILEGES; mysql> create table test (id integer, name varchar(30)); mysql> insert into test values(1, 'test1'); mysql> insert into test values(2, 'test2');
PHPコード
PHPのテストコードを作成します。
# cd /var/www/html # vi index.php
<?php $dsn = 'mysql:dbname=test;host=localhost;charset=utf8'; $user = 'test'; $pwd = 'test'; //DB接続 try { $pdo = new PDO($dsn, $user, $pwd); } catch (PDOException $e) { die('DB接続失敗:' . $e->getMessage()); } $sql = 'SELECT * FROM sample;'; $stmt = $pdo->query($sql); if (!$stmt) { $err = $pdo->errorInfo(); die('SELECT 失敗:' . $err[2]); } //結果取得 while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { print_r($data); } ?>
ブラウザからアクセスして確認します。