LoginSignup
9
8

More than 5 years have passed since last update.

サーバー構築

Last updated at Posted at 2016-02-16

AWSサーバー構築

サーバー構築の記事とかそのへんにたくさん転がってるので、完全個人メモです。
途中ハマりつつやったところもあるので、間違い等あるかも。
全てrootユーザーになってからの作業です。

php5.6を入れる。

MySQL・PHPインストール

yum install php56 php56-mbstring php56-mysql mysql-server php56-pear httpd-devel curl-devel php56-ldap php56-xml php56-mcrypt php56-gd php56-apc php56-imap php56-pecl-imagick

Zendframeworkインストール

yum install -y php-ZendFramework*

memcashdインストール

yum install -y memcached memcached-devel php-pecl-memcached

MySQL設定

config設定

/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql

# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
#---- ADD SETTING
key_buffer_size=256M
innodb_buffer_pool_size=512M
table_cache=256
thread_cache_size=16
innodb_flush_log_at_trx_commit=2
max_allowed_packet=1M
sort_buffer_size=1M
long_query_time=1
join_buffer_size = 131072
max_connections=2000
character-set-server=utf8mb4
old-passwords=1
interactive_timeout=900
wait_timeout=900
skip-character-set-client-handshake
expire_logs_days=10
log-bin=mysql-bin
server-id = 1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
default-character-set=utf8mb4

[client]
default-character-set=utf8mb4

初期テーブルを作成

mysql_install_db --datadir=/var/lib/mysql --user=mysql

rootのパスワードを変更

/usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h ホスト名 password 'new-password'

MySQL,memcacheの設定、起動

  • 起動時に起動させるようにする
chkconfig mysqld  on
chkconfig memcached  on
  • 手動で一旦サービスを起動させる
service mysqld start
service memcached start

phpの設定

※ phpのバージョン確認

php -v

いざという時困るんで、デフォルトのphp.iniのバックアップを取っておきます。

cp /etc/php.ini /etc/php.ini.org 

php.iniの編集

vim /etc/php.ini
#セッションIDの名前変更
session.name = 名前
session.use_only_cookies = 1

disable_functions = phpinfo
allow_url_fopen = Off
session.hash_function = 1
session.entropy_length = 16
post_max_size = 16M
memory_limit = -1
date.timezone = Asia/Tokyo
; session.save_handler = files // コメントアウト
; session.save_path = "/var/lib/php/session" // コメントアウト

こちらもバックアップを取っておきます。

cp /etc/php.d/memcached.ini /etc/php.d/memcached.ini.org 
vim /etc/php.d/memcached.ini
session.save_handler = memcached // コメントアウトをはずす
session.save_path = "tcp://localhost:11211" // 追記
WEBサーバが増えた場合はカンマ区切り追記していく。
session.save_path = "tcp://localhost:11211,tcp://otherserver.com:11211"

時間変更

cp /usr/share/zoneinfo/Japan /etc/localtime

※追記
AmazonLinuxの場合は、以下も設定する。
vim /etc/sysconfig/clock

ZONE="Asia/Tokyo"
UTC=true

ホスト名変更

hostname samplehost

再起動しても変更したい場合
/etc/sysconfig/network のHOSTNAMEを変更。

ファイルが無い場合は作成する。

HOSTNAME=samplehost

変更した場合は以下も設定する。

vim /etc/hosts
127.0.0.1  samplehost localhost.localdomain localhost
vim /etc/httpd/conf/httpd.conf
#ServerName www.example.com:80
ServerName samplehost:80

参考:

Apache の httpd: apr_sockaddr_info_get() failed for エラー

Apacheのエラー:Could not reliably determine the server’s fully qualified domain name…

vhostの設定

vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
    ServerName sample.jp
    DocumentRoot /usr/local/src/sample
    AllowEncodedSlashes On
    <Directory /usr/local/src/sample>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

※Apache 2.2と2.4では書き方が変わるので注意が必要です。

参考:

Apache2.4ではconfの書き方が変わりました。
Apacheのバージョン確認方法

9
8
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
9
8