CentOS7インストール, LAMPP

--------------------------------------------------------------------------------

備考:
  ・Windows10上にVirtualBoxでLinux環境を構築します。
  ・インターネットにつながっていない環境にも対応しています。

--------------------------------------------------------------------------------

・前処理

 ・用意するもの

    Oracle VM VirtualBox

    CentOS-7-x86_64-DVD-1810.iso

    emacs-26.2.tar.gz
    httpd-2.4.39.tar.gz
    mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
    nkf-2.1.5.tar.gz
    perl-5.30.0.tar.gz
    php-7.3.7.tar.gz

 ・準備

  ・マウント: /...Anywhere.../CentOS-7-x86_64-DVD-1810.iso

--------------------------------------------------------------------------------

・Oracle VM VirtualBox マネージャ で 新規作成

 ・名前    t02
 ・タイプ   Linux
 ・バージョン Other Linux (64bit)

 ・メモリサイズ 1024MB
 ・仮想ハードディスクを作成する
 ・ハードディスクのファイルタイプ: VDI(VirtualBox Disk Image)
 ・物理ハードディスクにあるストレージ: 可変サイズ
 ・ファイルの場所とサイズ: t02, 80GB
 ・[作成]

--------------------------------------------------------------------------------

・ネットワーク設定

 ・[設定(S)] - ネットワーク
  ・割り当て(A): ホストオンリーアダプター Host Only Adapter
  ・[OK]

--------------------------------------------------------------------------------

・インストール

 ・起動(T)
 ・Install CentOS 7
  ・Language: English (United States)
  ・DATE & TIME: Asia Tokyo
  ・KEYBOARD: Japanese
  ・SOFTWARE SELECTION: Infrastructure Server
  ・KDUMP: disabled
  ・NETWORK & HOST ; Ethernet = ON;
  ・[Begin Installation]

  ・ROOT PASSWORD
  ・USER CREATION

  ・(処理終了を待つ)

  ・Reboot

  ・固定IP
      # cd /etc/sysconfig/network-scripts
      # cp ifcfg-enp0s3 _ifcfg-enp0s3_
      # vi ifcfg-enp0s3
      # diff _ifcfg-enp0s3_ ifcfg-enp0s3
      4c4,7
      < BOOTPROTO=dhcp
      ---
      > BOOTPROTO=static
      > IPADDR=192.168.137.12
      > NETMASK=255.255.255.0
      > GATEWAY=192.168.137.1
      15c18
      < ONBOOT=no
      ---
      > ONBOOT=yes
      #

      --------------------------------------------------------------------------------

  ・Disable SELINUX
      # cd /etc/selinux
      # vi config
      # grep '^SELINUX=' config
      SELINUX=disabled
      # shutdown -r now

--------------------------------------------------------------------------------

・以降、client端末からsshでログインし、処理します。

--------------------------------------------------------------------------------

・パッケージの構築

 ・クライアント側から、以下のファイルをサーバのどこか(/home/devusr/wrk)にコピー。
    CentOS-7-x86_64-DVD-1810.iso
    emacs-26.2.tar.gz
    httpd-2.4.39.tar.gz
    mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar
    nkf-2.1.5.tar.gz
    perl-5.30.0.tar.gz
    php-7.3.7.tar.gz

 ・サーバ側はrootで処理。

    # mount -o loop -t iso9660 /home/devusr/wrk/CentOS-7-x86_64-DVD-1810.iso /mnt; \
    mkdir /Packages; cd /Packages; \
    cp /mnt/Packages/* .; \
    umount /mnt; rm -f /home/devusr/wrk/CentOS-7-x86_64-DVD-1810.iso

--------------------------------------------------------------------------------

・ソフトウェアのインストール

  ・gcc, c++, cmake, bison
    # cd /Packages; \
    rpm -ivh \
    gcc-4.8.5-36.el7.x86_64.rpm \
    cpp-4.8.5-36.el7.x86_64.rpm \
    glibc-devel-2.17-260.el7.x86_64.rpm \
    libmpc-1.0.1-3.el7.x86_64.rpm \
    mpfr-3.1.1-4.el7.x86_64.rpm \
    glibc-headers-2.17-260.el7.x86_64.rpm \
    kernel-headers-3.10.0-957.el7.x86_64.rpm \
    gcc-c++-4.8.5-36.el7.x86_64.rpm \
    libstdc++-devel-4.8.5-36.el7.x86_64.rpm \
    cmake-2.8.12.2-2.el7.x86_64.rpm \
    libarchive-3.1.2-10.el7_2.x86_64.rpm \
    bison-3.0.4-2.el7.x86_64.rpm \
    m4-1.4.16-10.el7.x86_64.rpm

 ・ImageMagick

    # cd /Packages; \
    rpm -ivh \
    ImageMagick-6.7.8.9-15.el7_2.x86_64.rpm \
    ilmbase-1.0.3-7.el7.x86_64.rpm \
    libICE-1.0.9-9.el7.x86_64.rpm \
    OpenEXR-libs-1.7.1-7.el7.x86_64.rpm \
    libSM-1.2.2-2.el7.x86_64.rpm \
    libX11-1.6.5-2.el7.x86_64.rpm \
    libXext-1.3.3-3.el7.x86_64.rpm \
    libXt-1.1.5-3.el7.x86_64.rpm \
    cairo-1.15.12-3.el7.x86_64.rpm \
    fontconfig-2.13.0-4.3.el7.x86_64.rpm \
    gdk-pixbuf2-2.36.12-3.el7.x86_64.rpm \
    ghostscript-9.07-31.el7.x86_64.rpm \
    jasper-libs-1.900.1-33.el7.x86_64.rpm \
    libjpeg-turbo-1.2.90-6.el7.x86_64.rpm \
    libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm \
    pango-1.42.4-1.el7.x86_64.rpm \
    librsvg2-2.40.20-1.el7.x86_64.rpm \
    libtiff-4.0.3-27.el7_3.x86_64.rpm \
    libwmf-lite-0.2.8.4-41.el7_1.x86_64.rpm \
    libX11-common-1.6.5-2.el7.noarch.rpm \
    libxcb-1.13-1.el7.x86_64.rpm \
    mesa-libEGL-18.0.5-3.el7.x86_64.rpm \
    mesa-libGL-18.0.5-3.el7.x86_64.rpm \
    libXrender-0.9.10-1.el7.x86_64.rpm \
    fontpackages-filesystem-1.44-8.el7.noarch.rpm \
    ghostscript-fonts-5.50-32.el7.noarch.rpm \
    lcms2-2.6-3.el7.x86_64.rpm \
    mesa-libgbm-18.0.5-3.el7.x86_64.rpm \
    cups-libs-1.6.3-35.el7.x86_64.rpm \
    poppler-data-0.4.6-3.el7.noarch.rpm \
    urw-fonts-2.4-16.el7.noarch.rpm harfbuzz-1.7.5-2.el7.x86_64.rpm \
    libXft-2.3.2-2.el7.x86_64.rpm \
    libthai-0.1.14-9.el7.x86_64.rpm \
    jbigkit-libs-2.0-11.el7.x86_64.rpm \
    libXau-1.0.8-2.1.el7.x86_64.rpm \
    libxshmfence-1.2-1.el7.x86_64.rpm \
    libXdamage-1.1.4-4.1.el7.x86_64.rpm \
    libXfixes-5.0.3-1.el7.x86_64.rpm \
    graphite2-1.3.10-1.el7_3.x86_64.rpm \
    mesa-libglapi-18.0.5-3.el7.x86_64.rpm \
    avahi-libs-0.6.31-19.el7.x86_64.rpm \
    xorg-x11-font-utils-7.5-21.el7.x86_64.rpm \
    libXfont-1.5.4-1.el7.x86_64.rpm \
    libfontenc-1.1.3-3.el7.x86_64.rpm \
    gnu-free-mono-fonts-20120503-8.el7.noarch.rpm \
    gnu-free-fonts-common-20120503-8.el7.noarch.rpm \
    dejavu-sans-fonts-2.33-6.el7.noarch.rpm \
    fribidi-1.0.2-1.el7.x86_64.rpm \
    libglvnd-egl-1.0.1-0.8.git5baa1e5.el7.x86_64.rpm \
    libglvnd-glx-1.0.1-0.8.git5baa1e5.el7.x86_64.rpm \
    dejavu-fonts-common-2.33-6.el7.noarch.rpm \
    libwayland-server-1.15.0-1.el7.x86_64.rpm \
    libglvnd-1.0.1-0.8.git5baa1e5.el7.x86_64.rpm \
    libwayland-client-1.15.0-1.el7.x86_64.rpm \
    libXxf86vm-1.1.4-1.el7.x86_64.rpm

 ・emacs

    # cd /Packages; \
    rpm -ivh \
    ncurses-term-5.9-14.20130511.el7_4.noarch.rpm \
    ncurses-devel-5.9-14.20130511.el7_4.x86_64.rpm; \
    cd /usr/local/src; \
    tar xzf /home/devusr/wrk/emacs-26.2.tar.gz; \
    rm -f /home/devusr/wrk/emacs-26.2.tar.gz; \
    cd emacs-26.2; \
    ./configure --with-gnutls=no; \
    make && make install

 ・nkf

    # cd /usr/local/src; \
    tar xzf /home/devusr/wrk/nkf-2.1.5.tar.gz; \
    rm -f /home/devusr/wrk/nkf-2.1.5.tar.gz; \
    cd nkf-2.1.5; \
    make; \
    cp nkf /usr/local/bin

 ・Apache Web Server : HTTPD

    # cd /Packages; \
    rpm -ivh \
    apr-1.4.8-3.el7_4.1.x86_64.rpm \
    apr-devel-1.4.8-3.el7_4.1.x86_64.rpm \
    apr-util-1.5.2-6.el7.x86_64.rpm \
    apr-util-devel-1.5.2-6.el7.x86_64.rpm \
    expat-devel-2.1.0-10.el7_3.x86_64.rpm \
    libdb-devel-5.3.21-24.el7.x86_64.rpm \
    openldap-devel-2.4.44-20.el7.x86_64.rpm \
    cyrus-sasl-devel-2.1.26-23.el7.x86_64.rpm \
    cyrus-sasl-2.1.26-23.el7.x86_64.rpm \
    cyrus-sasl-devel-2.1.26-23.el7.x86_64.rpm \
    pcre-devel-8.32-17.el7.x86_64.rpm; \
    cd /usr/local/src/; \
    tar xzf /home/devusr/wrk/httpd-2.4.39.tar.gz; \
    rm -f /home/devusr/wrk/httpd-2.4.39.tar.gz; \
    cd httpd-2.4.39; \
    ./configure; \
    make && make install

 ・PHP7

    # cd /Packages; \
    rpm -ivh \
    libxml2-devel-2.9.1-6.el7_2.3.x86_64.rpm \
    zlib-devel-1.2.7-18.el7.x86_64.rpm \
    xz-devel-5.2.2-1.el7.x86_64.rpm \
    openssl-devel-1.0.2k-16.el7.x86_64.rpm \
    krb5-devel-1.15.1-34.el7.x86_64.rpm \
    keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm \
    libverto-devel-0.2.5-4.el7.x86_64.rpm \
    libcom_err-devel-1.42.9-13.el7.x86_64.rpm \
    libkadm5-1.15.1-34.el7.x86_64.rpm \
    libselinux-devel-2.5-14.1.el7.x86_64.rpm \
    libsepol-devel-2.5-10.el7.x86_64.rpm \
    bzip2-devel-1.0.6-13.el7.x86_64.rpm \
    libzip-0.10.1-8.el7.x86_64.rpm \
    libcurl-devel-7.29.0-51.el7.x86_64.rpm; \
    cd /usr/local/src; \
    tar xzf /home/devusr/wrk/php-7.3.7.tar.gz; \
    rm -f /home/devusr/wrk/php-7.3.7.tar.gz; \
    cd /usr/local/src/php-7.3.7; \
    ./configure \
    --enable-mbstring \
    --enable-zip \
    --enable-bcmath \
    --enable-pcntl \
    --enable-ftp \
    --enable-exif \
    --enable-calendar \
    --enable-sysvmsg \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-wddx \
    --enable-mysqlnd \
    --with-curl \
    --with-iconv \
    --with-openssl \
    --with-gettext \
    --with-zlib \
    --with-bz2 \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --without-libzip \
    --with-apxs2=/usr/local/apache2/bin/apxs; \
    make && make install

 ・Perl 5.30

    # cd /usr/local/src; \
    tar xzf /home/devusr/wrk/perl-5.30.0.tar.gz; \
    rm -f /home/devusr/wrk/perl-5.30.0.tar.gz; \
    cd perl-5.30.0; \
    ./configure.gnu; \
    make && make install

 ・MySQL

    # cd /Packages; \
    tar xf /home/devusr/wrk/mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar; \
    rm -f /home/devusr/wrk/mysql-8.0.16-2.el7.x86_64.rpm-bundle.tar; \
    rpm -e mariadb-libs postfix; \
    rpm -ivh mysql-community-* \
    perl-Data-Dumper-2.145-3.el7.x86_64.rpm \
    perl-JSON-2.59-2.el7.noarch.rpm



--------------------------------------------------------------------------------

・ミドルウェアの設定

 ・MySQL

    # systemctl enable mysqld
    # systemctl start mysqld
    # grep password /var/log/mysqld.log
    2019-07-18T03:06:45.089426Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: eR01yeGLq<Av
    #

    # mysql -u root -p
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'x@=y1q84Z';
    \s
    \q

    # cp /etc/my.cnf /etc/_my.cnf_
    # vi /etc/my.cnf
    # cat /etc/my.cnf
[mysqld]

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

character-set-server=utf8mb4

sql_mode = ""

[client]

default-character-set=utf8mb4
    #

    # systemctl restart mysqld


 ・Apache WEB Server

    # vi /usr/lib/systemd/system/httpd.service
    # cat /usr/lib/systemd/system/httpd.service
[Unit]
Description=Apache httpd daemon

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl -k start
ExecReload=/usr/local/apache2/bin/apachectl restart -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}

[Install]
WantedBy=multi-user.target
    #

    # systemctl daemon-reload
    # systemctl enable httpd
    # systemctl start httpd
    # cd /usr/local/apache2/conf
    # cp httpd.conf _httpd.conf
    # vi httpd.conf
    # diff _httpd.conf httpd.conf
205c205
<     AllowOverride none
---
>     AllowOverride All
242c242
<     AllowOverride None
---
>     AllowOverride All
255c255
<     DirectoryIndex index.html
---
>     DirectoryIndex index.php index.html
355c355
<     AllowOverride None
---
>     AllowOverride FileInfo
507a508,512
> #
> # PHP
> #
> AddType application/x-httpd-php .php
> AddType application/x-httpd-php-source .phps
    #

    # cp /usr/local/src/php-7.3.7/php.ini-development /usr/local/lib/php.ini
    # vi /usr/local/lib/php.ini
    # diff /usr/local/src/php-7.3.7/php.ini-development /usr/local/lib/php.ini
581a582
> error_log = /var/log/php_error.log
953c954
< ;date.timezone =
---
> date.timezone = Asia/Tokyo
1047c1048
< pdo_mysql.default_socket=
---
> pdo_mysql.default_socket=/var/lib/mysql/mysql.sock
    #

    # touch /var/log/php_error.log
    # chmod 666 /var/log/php_error.log
    
    # systemctl restart httpd

--------------------------------------------------------------------------------

・その他の設定

  ・Webサーバー(http)のサービス(ポート)を永続的に許可
    間違えて設定してしまった場合は「add」の箇所を「remove」にする。

    # firewall-cmd --permanent --add-service=http

  ・httpsサーバーのサービス(ポート)を永続的に許可

    # firewall-cmd --permanent --add-service=https

  ・firewalldを状態の情報を失わずにリロードする。これで設定が有効になる。

    # firewall-cmd --reload

  ・現在有効な機能とゾーンを一覧表示します。

    # firewall-cmd --list-all
    # firewall-cmd --list-all-zones
    # firewall-cmd --list-all --permanent

  ・アクティブゾーンの確認

    # firewall-cmd --get-active-zones

  ・設定内容の確認

    # cat /etc/firewalld/zones/public.xml

  ・設定内容の確認 個別 https

    # ls /usr/lib/firewalld/services
    # less /usr/lib/firewalld/services/https.xml

--------------------------------------------------------------------------------

EOL

--------------------------------------------------------------------------------