VPSセットアップガイド #2:Webサーバのインストール

Apacheのインストール

$ sudo yum install httpd
$ sudo systemctl enable httpd
$ sudo systemctl start httpd
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
$ sudo firewall-cmd reload

初期設定

$ sudo vim /etc/httpd/conf.d/welcome.conf
- <LocationMatch "^/+$">
-    Options -Indexes
-     ErrorDocument 403 /error/noindex.html
- </LocationMatch>
+ #<LocationMatch "^/+$">
+ #   Options -Indexes
+ #    ErrorDocument 403 /error/noindex.html
+ #</LocationMatch>
$ sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak # backup
$ sudo vim /etc/httpd/conf/httpd.conf
- Options Indexes FollowSymLinks
+ Options -Indexes +FollowSymLinks
$ sudo apachectl graceful

VirtualHost

$ sudo vim /etc/httpd/conf/httpd.conf
- ServerName www.example.com:80
+ #ServerName www.example.com:80

- #NameVirtualHost *:80
+ NameVirtualHost *:80

- ServerTokens OS
+ ServerTokens Prod
$ sudo apachectl graceful
$ sudo vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
    ServerName [Addr]
    DocumentRoot /var/www/html/[Addr]
    ServerAlias [AliasAddr] # redirect to [Addr]
    AddDefaultCharset UTF-8
    CustomLog logs/nyaruko_server_access_log common
    ErrorLog  logs/nyaruko_server_error_log
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot /var/www/html/www.ibuki2003.yokohama
    ServerName www.ibuki2003.yokohama

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/[host]/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/[host]/privkey.pem
</VirtualHost>

DocumentRoot

DocumentRoot [DocRoot]

Redirect

Redirect /(path) [dest]

Proxy

ProxyPass /(path) [proxyAddr]
<Location /(path)>
    ProxyPassReverse [proxyAddr]
    ProxyPassReverseCookieDomain localhost [domain]/[path]
    ProxyPassReverseCookiePath / /[path]
    Order allow,deny
    Allow from all
</Location>

PHPのインストール

sudo yum install epel-release
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo yum install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-mysqlnd php-pdo php-gd php-xml php-mcrypt

初期設定

sudo vim /etc/php.ini
- short_open_tag = Off
+ short_open_tag = On

- expose_php = On
+ expose_php = Off

MariaDB

$ sudo yum install mariadb-server
$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb
$ mysql_secure_installation

最終更新: 2019/08/06 23:00