忘備録
【OS】
今回はCentOS7.2_x86_64版を使用。詳細は以下を参照。
http://www.server-world.info/query?os=CentOS_7&p=install
事前準備
セットアップに必要なパッケージを事前に設定しておく必要がある。以下を全て設定する。
システム変更が発生するので管理者権限が必須。rootにsuしておく事。
【YUMパッケージ管理】
yum -y install yum-plugin-priorities
yum -y update
yum -y groupinstall "Base" "Development tools" "Japanese Support"
[EPELリポジトリ追加]
yum -y install epel-release
[Remiリポジトリ追加]
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[RPMforgeリポジトリ追加]
yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
【Firewall無効】
systemctl stop firewalld
systemctl disable firewalld
【SELinux無効化】
vi /etc/selinux/config
SELINUX=enforcing
SELINUX=disabled ←変更(起動時に無効にする)
【MySQL】
公式サイトよりrpmを入手してインストール
rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-community-devel mysql-community-server
設定
vim /etc/my.cnf
--(以下を最終行に追加)---
default_password_lifetime=0
log_timestamps=SYSTEM
explicit_defaults_for_timestamp=TRUE
skip-character-set-client-handshake
character-set-server=utf8
起動・自動起動
systemctl start mysqld
systemctl enable mysqld
root の初期パスワードの確認
grep password /var/log/mysqld.log
A temporary password is generated for root@localhost: <初期パスワード>
セキュリティ設定
mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: <初期パスワード>
The existing password for the user account root has expired. Please set a new password.
New password: <パスワード>
Re-enter new password: <パスワード>
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : <空エンター>
(略)
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
(略)
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
(略)
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
(略)
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
【Apache関連】
OpenSSL 1.0.2
yum -y install zlib-devel
cd /usr/local/src/
wget https://www.openssl.org/source/openssl-1.0.2e.tar.gz
tar xvzf openssl-1.0.2e.tar.gz
cd openssl-1.0.2e/
./config --prefix=/usr/local/openssl-1.0.2e shared zlib
make
make test
make install
echo /usr/local/openssl-1.0.2e/lib > /etc/ld.so.conf.d/openssl102e.conf
ldconfig
Nghttp2
yum -y install libev-devel
cd /usr/local/src/
wget https://github.com/tatsuhiro-t/nghttp2/releases/download/v1.6.0/nghttp2-1.6.0.tar.gz
tar xvzf nghttp2-1.6.0.tar.gz
cd nghttp2-1.6.0/
autoreconf -i
automake
autoconf
env OPENSSL_CFLAGS="-I/usr/local/openssl-1.0.2e/include" OPENSSL_LIBS="-L/usr/local/openssl-1.0.2e/lib -lssl -lcrypto" ./configure
make
make install
echo /usr/local/lib > /etc/ld.so.conf.d/usr-local-lib.conf
ldconfig
ARP
cd /usr/local/src/
wget http://ftp.riken.jp/net/apache//apr/apr-1.5.2.tar.gz
tar xvzf apr-1.5.2.tar.gz
cd apr-1.5.2/
./configure
make
make install
ARP-util
cd /usr/local/src/
wget http://ftp.riken.jp/net/apache//apr/apr-util-1.5.4.tar.gz
tar xvzf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4/
./configure --with-apr=/usr/local/apr
make
make install
PCRE
yum -y install pcre-devel
Apache 2.4.18
cd /usr/local/src/
wget http://ftp.jaist.ac.jp/pub/apache//httpd/httpd-2.4.18.tar.gz
tar xvzf httpd-2.4.18.tar.gz
cd httpd-2.4.18/
./configure \
--enable-http2 \
--enable-ssl \
--with-ssl=/usr/local/openssl-1.0.2e \
--enable-so \
--enable-mods-shared=all \
--enable-mpms-shared=all
make
make install
【PHP関連】
依存パッケージ
yum -y install \
libxml2-devel \
openssl-devel \
freetype-devel \
libcurl-devel \
net-snmp-devel \
libpng-devel \
libjpeg-turbo-devel \
openldap-devel \
libmcrypt-devel \
readline-devel \
gd-devel \
bzip2-devel \
libicu-devel \
libwebp-devel \
gmp-devel \
libtidy-devel \
libxslt-devel
本体
cd /usr/local/src/
wget https://github.com/php/php-src/archive/php-7.0.1.tar.gz
tar xvzf php-7.0.1.tar.gz
cd php-src-php-7.0.1/
./buildconf --force
./configure \
--with-libdir=lib64 \
--with-pic \
--with-bz2 \
--with-freetype-dir \
--with-png-dir \
--with-xpm-dir \
--enable-gd-native-ttf \
--with-gettext \
--with-gmp \
--with-iconv \
--with-jpeg-dir \
--with-curl \
--with-webp-dir \
--with-png-dir \
--with-openssl \
--with-pcre-regex \
--with-zlib \
--with-layout=GNU \
--enable-exif \
--enable-ftp \
--enable-sockets \
--with-kerberos \
--enable-shmop \
--enable-calendar \
--with-libxml-dir \
--with-mhash \
--with-ldap \
--with-readline \
--with-snmp \
--with-tidy \
--with-xsl \
--with-gnu-ld \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--with-apxs2=/usr/local/apache2/bin/apxs
make
make test
make install
【yum版】
参照
https://webtatic.com/packages/php70/
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w php70w-common php70w-opcache php70w-cli php70w-mbstring php70w-mysql
設定
cp -ip /usr/local/src/php-src-php-7.0.1/php.ini-production /usr/local/etc/php.ini
mkdir /var/log/php
chown daemon /var/log/php
chmod 755 /var/log/php
vim /usr/local/etc/php.ini
expose_php = On
↓
expose_php = Off
;date.timezone =
↓
date.timezone = 'Asia/Tokyo'
;error_log = php_errors.log
↓
error_log = "/var/log/php/php_errors.log"
Apache設定
vim /etc/profile
PATH=$PATH:/usr/local/apache2/bin
source /etc/profile
mv -i /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.org
vim /usr/local/apache2/conf/httpd.conf
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
ServerRoot "/usr/local/apache2"
Timeout 120
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 1
Listen 80
User daemon
Group daemon
ServerAdmin root@localhost
ServerName localhost:80
LoadModule authn_file_module modules/mod_authn_file.so
"#LoadModule authn_dbm_module modules/mod_authn_dbm.so"
"#LoadModule authn_anon_module modules/mod_authn_anon.so"
"#LoadModule authn_dbd_module modules/mod_authn_dbd.so"
"#LoadModule authn_socache_module modules/mod_authn_socache.so"
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
"#LoadModule authz_dbm_module modules/mod_authz_dbm.so"
"#LoadModule authz_owner_module modules/mod_authz_owner.so"
"#LoadModule authz_dbd_module modules/mod_authz_dbd.so"
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
"#LoadModule auth_form_module modules/mod_auth_form.so"
"#LoadModule auth_digest_module modules/mod_auth_digest.so"
"#LoadModule allowmethods_module modules/mod_allowmethods.so"
"#LoadModule file_cache_module modules/mod_file_cache.so"
"#LoadModule cache_module modules/mod_cache.so"
"#LoadModule cache_disk_module modules/mod_cache_disk.so"
"#LoadModule cache_socache_module modules/mod_cache_socache.so"
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
"#LoadModule socache_dbm_module modules/mod_socache_dbm.so"
"#LoadModule socache_memcache_module modules/mod_socache_memcache.so"
"#LoadModule watchdog_module modules/mod_watchdog.so"
"#LoadModule macro_module modules/mod_macro.so"
"#LoadModule dbd_module modules/mod_dbd.so"
"#LoadModule dumpio_module modules/mod_dumpio.so"
"#LoadModule echo_module modules/mod_echo.so"
"#LoadModule buffer_module modules/mod_buffer.so"
"#LoadModule data_module modules/mod_data.so"
"#LoadModule ratelimit_module modules/mod_ratelimit.so"
LoadModule reqtimeout_module modules/mod_reqtimeout.so
"#LoadModule ext_filter_module modules/mod_ext_filter.so"
"#LoadModule request_module modules/mod_request.so"
"#LoadModule include_module modules/mod_include.so"
LoadModule filter_module modules/mod_filter.so
"#LoadModule reflector_module modules/mod_reflector.so"
"#LoadModule substitute_module modules/mod_substitute.so"
"#LoadModule sed_module modules/mod_sed.so"
"#LoadModule charset_lite_module modules/mod_charset_lite.so"
"#LoadModule deflate_module modules/mod_deflate.so"
LoadModule mime_module modules/mod_mime.so
LoadModule http2_module modules/mod_http2.so
LoadModule log_config_module modules/mod_log_config.so
"#LoadModule log_debug_module modules/mod_log_debug.so"
"#LoadModule log_forensic_module modules/mod_log_forensic.so"
"#LoadModule logio_module modules/mod_logio.so"
LoadModule env_module modules/mod_env.so
"#LoadModule mime_magic_module modules/mod_mime_magic.so"
"#LoadModule expires_module modules/mod_expires.so"
LoadModule headers_module modules/mod_headers.so
"#LoadModule usertrack_module modules/mod_usertrack.so"
"#LoadModule unique_id_module modules/mod_unique_id.so"
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
"#LoadModule remoteip_module modules/mod_remoteip.so"
"#LoadModule proxy_module modules/mod_proxy.so"
"#LoadModule proxy_connect_module modules/mod_proxy_connect.so"
"#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so"
"#LoadModule proxy_http_module modules/mod_proxy_http.so"
"#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so"
"#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so"
"#LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so"
"#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so"
"#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so"
"#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so"
"#LoadModule proxy_express_module modules/mod_proxy_express.so"
"#LoadModule session_module modules/mod_session.so"
"#LoadModule session_cookie_module modules/mod_session_cookie.so"
"#LoadModule session_dbd_module modules/mod_session_dbd.so"
"#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so"
"#LoadModule slotmem_plain_module modules/mod_slotmem_plain.so"
LoadModule ssl_module modules/mod_ssl.so
"#LoadModule dialup_module modules/mod_dialup.so"
"#LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so"
"#LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so"
"#LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so"
"#LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so"
"#LoadModule mpm_event_module modules/mod_mpm_event.so"
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
"#LoadModule mpm_worker_module modules/mod_mpm_worker.so"
LoadModule unixd_module modules/mod_unixd.so
"#LoadModule heartbeat_module modules/mod_heartbeat.so"
"#LoadModule heartmonitor_module modules/mod_heartmonitor.so"
"#LoadModule dav_module modules/mod_dav.so"
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
"#LoadModule asis_module modules/mod_asis.so"
"#LoadModule info_module modules/mod_info.so"
"#LoadModule cgid_module modules/mod_cgid.so"
"#LoadModule dav_fs_module modules/mod_dav_fs.so"
"#LoadModule dav_lock_module modules/mod_dav_lock.so"
"#LoadModule vhost_alias_module modules/mod_vhost_alias.so"
"#LoadModule negotiation_module modules/mod_negotiation.so"
LoadModule dir_module modules/mod_dir.so
"#LoadModule actions_module modules/mod_actions.so"
"#LoadModule speling_module modules/mod_speling.so"
"#LoadModule userdir_module modules/mod_userdir.so"
LoadModule alias_module modules/mod_alias.so
"#LoadModule rewrite_module modules/mod_rewrite.so"
LoadModule php7_module modules/libphp7.so
AllowOverride none
Require all denied
DirectoryIndex index.php index.html
Require all denied
ErrorLog "logs/error_log"
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
CustomLog "logs/access_log" combined
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
MIMEMagicFile conf/magic
SetHandler application/x-httpd-php
AddType text/html .php
"# Include conf/extra/httpd-ssl.conf"
ServerName example.com
DocumentRoot "/usr/local/apache2/htdocs"
Options FollowSymLinks
AllowOverride None
Require all granted
ErrorLog "logs/error_log"
CustomLog "logs/access_log" combined
起動スクリプト
cp -ip /usr/local/src/httpd-2.4.18/build/rpm/httpd.init /etc/rc.d/init.d/httpd
vim /etc/rc.d/init.d/httpd
(60行目あたり)
httpd=${HTTPD-/usr/sbin/httpd}
pidfile=${PIDFILE-/var/run/${prog}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
↓
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache2/logs/${prog}.pid}
lockfile=${LOCKFILE-/usr/local/apache2/logs/${prog}}
CONFFILE=/etc/httpd/conf/httpd.conf
↓
CONFFILE=/usr/local/apache2/conf/httpd.conf
起動・自動起動
chkconfig --add httpd
chkconfig --list | grep httpd
chkconfig httpd on
apachectl start
*注意:「service httpd start」や「/etc/init.d/httpd start」を実行すると
systemd に処理が渡ってしまい、Apache が起動できません。
手動での起動や停止は「apachectl」を使います。