CentOS 7 Source LAMP install

OS :  CentOS Linux release 7.4.1708

APACHE : 2.4.37

Mariadb : 10.3.8

PHP : 7.2.12

Apache 2.4.37 설치

설치된 apache 패키지를 제거 합니다.

[root@CentOS7 ~]# yum remove -y httpd httpd-*

 

Source 설치에 필요한 패키지를 설치 합니다.

[root@CentOS7 ~]# yum install -y make gcc g++ gcc-c++ autoconf automake libtool pkgconfig \
findutils oepnssl openssl-devel openldap-devel pcre-devel libxml2-devel lua-devel \
curl curl-devel libcurl-devel expat-devel flex

 

패키지를 다운로드 합니다.

 (http://mirror.apache-kr.org/httpd/ , http://mirror.apache-kr.org/apr/ , https://sourceforge.net/projects/pcre/files/pcre/)

[root@CentOS7 ~]# wget http://mirror.apache-kr.org/httpd/httpd-2.4.37.tar.gz
[root@CentOS7 ~]# wget http://mirror.apache-kr.org/apr/apr-1.6.5.tar.gz
[root@CentOS7 ~]# wget http://mirror.apache-kr.org/apr/apr-util-1.6.1.tar.gz
[root@CentOS7 ~]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz

 

Apache Source 설치

apr-1.6.5 설치 
[root@CentOS7 apm]# tar xvf apr-1.6.5.tar.gz
[root@CentOS7 apm]# cd apr-1.6.5/
[root@CentOS7 apr-1.6.5]# ./configure --prefix=/usr/local/apr
[root@CentOS7 apr-1.6.5]# make && make install

apr-util-1.6.1 설치 
[root@CentOS7 apm]# tar xvf apr-util-1.6.1.tar.gz
[root@CentOS7 apm]# cd apr-util-1.6.1/
[root@CentOS7 apr-util-1.6.1]# ./configure --with-apr=/usr/local/apr/
[root@CentOS7 apr-util-1.6.1]# make && make install

pcre-8.42 설치 
[root@CentOS7 apm]# tar xvf pcre-8.42.tar.gz
[root@CentOS7 pcre-8.42]# ./configure --prefix=/usr/local/pcre
[root@CentOS7 pcre-8.42]# make && make install


httpd-2.4.37 설치 
[root@CentOS7 apm]# tar xvf httpd-2.4.37.tar.gz
[root@CentOS7 apm]# cd httpd-2.4.37/
[root@CentOS7 httpd-2.4.37]# ./configure --enable-module=so --enable-mods-shared=most --enable-maintainer-mode \
--enable-deflate --enable-headers --enable-rewrite --enable-ssl --enable-proxy --enable-proxy-http \
--enable-proxy-ajp --enable-proxy-balance --with-mpm=worker --with-apr=/usr/local/apr \
--with-pcre=/usr/local/pcre --prefix=/usr/local/apache2
[root@CentOS7 httpd-2.4.37]# make && make isntall

 

Apache 유저/구릅 생성 및 권한 추가

[root@CentOS7 ~]# groupadd apache
[root@CentOS7 ~]# useradd -g apache -d /usr/local/apache2 -s /sbin/nologin apache
[root@CentOS7 ~]# chown -R apache:apache /usr/local/apache2/

 

Apache 실행 Test

[root@CentOS7 ~]# vi /usr/local/apache2/conf/httpd.conf
ServerName www.example.com:80
[root@CentOS7 ~]# /usr/local/apache2/bin/apachectl start

[root@CentOS7 ~]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1082/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1305/master
tcp        0     64 192.168.0.25:22         192.168.0.1:9938        ESTABLISHED 1417/sshd: root@pts
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd
tcp6       0      0 :::80                   :::*                    LISTEN      54092/httpd
tcp6       0      0 :::22                   :::*                    LISTEN      1082/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1305/master
[root@CentOS7 ~]#

 

Systemd Service 파일 생성

[root@CentOS7 ~]# vi /etc/systemd/system/httpd.service
[Unit]
Description=The Apache HTTP Server
 
[Service]
Type=forking
#EnvironmentFile=/usr/local/apache2/bin/envvars
PIDFile=/usr/local/apache2/logs/httpd.pid
ExecStart=/usr/local/apache2/bin/apachectl start
ExecReload=/usr/local/apache2/bin/apachectl graceful
ExecStop=/usr/local/apache2/bin/apachectl stop
KillSignal=SIGCONT
PrivateTmp=true
 
 
[Install]
WantedBy=multi-user.target

[root@CentOS7 ~]# systemctl daemon-reload
[root@CentOS7 ~]# systemctl enable httpd

 

방화벽 추가

[root@CentOS7 ~]# firewall-cmd --permanent --add-port=80/tcp
[root@CentOS7 ~]# firewall-cmd --permanent --add-port=443/tcp
[root@CentOS7 ~]# firewall-cmd --reload

 

Mariadb 설치

 

mysql 유저생성

[root@CentOS7 ~]# useradd mysql

 

Cmake 3.12 설치

[root@CentOS7 ~]# cd /usr/local/src/
[root@CentOS7 src]# wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz
[root@CentOS7 src]# tar xvf cmake-3.12.0.tar.gz
[root@CentOS7 src]# cd cmake-3.12.0/
[root@CentOS7 cmake-3.12.0]# ./configure
[root@CentOS7 cmake-3.12.0]# gmake && make install
[root@CentOS7 cmake-3.12.0]# rm -f CMakeCache.txt

 

ncruse 6.1 설치

[root@CentOS7 ~]# cd /usr/local/src/
[root@CentOS7 ~]# wget http://ftp.gnu.org/gnu/ncurses/ncurses-6.1.tar.gz
[root@CentOS7 src]# tar xvf ncurses-6.1.tar.gz
[root@CentOS7 src]# cd ncurses-6.1/
[root@CentOS7 ncurses-6.1]# ./configure --with-shared
[root@CentOS7 ncurses-6.1]# make && make install

 

Mariadb 10.3.8 설치

[root@CentOS7 ~]# cd /usr/local/src
[root@CentOS7 src]# wget --trust-server-names https://downloads.mariadb.org/f/mariadb-10.3.8/source/mariadb-10.3.8.tar.gz/from/http%3A//ftp.kaist.ac.kr/mariadb/?serve
[root@CentOS7 src]# tar xvf mariadb-10.3.8.tar.gz
[root@CentOS7 src]# cd mariadb-10.3.8/


[root@CentOS7 mariadb-10.3.8]# BUILD/autorun.sh
[root@CentOS7 mariadb-10.3.8]# export OPENSSL_ROOT_DIR=/usr/local/ssl
[root@CentOS7 mariadb-10.3.8]# export OPENSSL_INCLUDE_DIR=/usr/local/ssl/include    
[root@CentOS7 mariadb-10.3.8]# export OPENSSL_LIBRARIES=/usr/local/ssl/lib
[root@CentOS7 mariadb-10.3.8]# export OPENSSL_ROOT_DIR=/usr/local/ssl



[root@CentOS7 mariadb-10.3.8]# cmake \
-DPLUGIN_TOKUDB=NO \
-OPENSSL_ROOT_DIR=/usr/local/ssl \
-OPENSSL_INCLUDE_DIR=/usr/local/ssl/include \
-OPENSSL_LIBRARIES=/usr/local/ssl/lib \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci


[root@CentOS7 mariadb-10.3.8]# make install
[root@CentOS7 mariadb-10.3.8]# chown mysql:mysql -R /usr/local/mysql/


참고!!! cmake 를 다시 해야 하는경우 
[root@CentOS7 mariadb-10.3.8]# rm -f CMakeCache.txt

 

mysql_install_db (DB 파일 생성)

[root@CentOS7 mariadb-10.3.8]# su - mysql
[mysql@CentOS7 ~]$ cd /usr/local/mysql
[mysql@CentOS7 mysql]$ scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[mysql@CentOS7 mysql]$ exit
[root@CentOS7 ~]# usermod -s /sbin/nologin mysql

 

Systemd 스크립트 작성

[root@CentOS7 ~]# vi /usr/lib/systemd/system/mariadb.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/mariadb.service",
# containing
#   .include /lib/systemd/system/mariadb.service
#   ...make your changes here...
# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file mariadb.service itself is parsed.
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#   [Service]
#   LimitNOFILE=10000

# Note: /usr/lib/... is recommended in the .include line though /lib/... 
# still works.
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload

[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql

ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/usr/local/mysql/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

# Place temp files in a secure directory, not /tmp
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

mariadb-wait-ready

[root@CentOS7 ~]# vi /usr/libexec/mariadb-wait-ready

#!/bin/sh

# This script waits for mysqld to be ready to accept connections
# (which can be many seconds or even minutes after launch, if there's
# a lot of crash-recovery work to do).
# Running this as ExecStartPost is useful so that services declared as
# "After mysqld" won't be started until the database is really ready.

# Service file passes us the daemon's PID (actually, mysqld_safe's PID)
daemon_pid="$1"

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
    result=`/usr/local/mysql/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
    if [ -z "$result" ]; then
        # not found, use default
        result="$3"
    fi
}

# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/usr/local/mysql/data"
datadir="$result"
get_mysql_option mysqld socket "/usr/local/mysql/data/mysql.sock"
socketfile="$result"

# Wait for the server to come up or for the mysqld process to disappear
ret=0
while /bin/true; do
    if ! [ -d "/proc/$daemon_pid" ] ; then
            ret=1
            break
    fi
    RESPONSE=`/usr/local/mysql/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
    mret=$?
    if [ $mret -eq 0 ]; then
        break
    fi
    # exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
    # anything else suggests a configuration error
    if [ $mret -ne 1 -a $mret -ne 11 ]; then
        ret=1
        break
    fi
    # "Access denied" also means the server is alive
    echo "$RESPONSE" | grep -q "Access denied for user" && break

    sleep 1
done

exit $ret

 

mariadb-prepare-db-dir

[root@CentOS7 ~]# vi /usr/libexec/mariadb-prepare-db-dir

#!/bin/sh

# This script creates the mysql data directory during first service start.
# In subsequent starts, it does nothing much.

# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
        result=`/usr/local/mysql/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
        if [ -z "$result" ]; then
            # not found, use default
            result="$3"
        fi
}

# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/usr/local/mysql/data"
datadir="$result"
get_mysql_option mysqld_safe log-error "/usr/local/mysql/data/mariadb.log"
errlogfile="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"

# Absorb configuration settings from the specified systemd service file,
# or the default "mysqld" service if not specified
SERVICE_NAME="$1"
if [ x"$SERVICE_NAME" = x ]
then
    SERVICE_NAME=mysqld.service
fi

myuser=`systemctl show -p User "${SERVICE_NAME}" |
  sed 's/^User=//'`
if [ x"$myuser" = x ]
then
    myuser=mysql
fi

mygroup=`systemctl show -p Group "${SERVICE_NAME}" |
  sed 's/^Group=//'`
if [ x"$mygroup" = x ]
then
    mygroup=mysql
fi

# Set up the errlogfile with appropriate permissions
touch "$errlogfile"
chown "$myuser:$mygroup" "$errlogfile"
chmod 0640 "$errlogfile"
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"

# We check if there is already a process using the socket file,
# since otherwise this systemd service file could report false
# positive result when starting and mysqld_safe could remove
# a socket file, which actually uses a different daemon.
if fuser "$socketfile" &>/dev/null ; then
    echo "Socket file $socketfile exists." >&2
    echo "Is another MySQL daemon already running with the same unix socket?" >&2
    exit 1
fi

# Make the data directory
if [ ! -d "$datadir/mysql" ] ; then
    # First, make sure $datadir is there with correct permissions
    # (note: if it's not, and we're not root, this'll fail ...)
    if [ ! -e "$datadir" -a ! -h "$datadir" ]
    then
        mkdir -p "$datadir" || exit 1
    fi
    chown "$myuser:$mygroup" "$datadir"
    chmod 0755 "$datadir"
    [ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"

    # Now create the database
    echo "Initializing MySQL database"
    /usr/local/mysql/scripts/mysql_install_db --datadir="$datadir" --user="$myuser"
    ret=$?
    if [ $ret -ne 0 ] ; then
        echo "Initialization of MySQL database failed." >&2
        echo "Perhaps /etc/my.cnf is misconfigured." >&2
        # Clean up any partially-created database files
        if [ ! -e "$datadir/mysql/user.frm" ] ; then
            rm -rf "$datadir"/*
        fi
        exit $ret
    fi
    # In case we're running as root, make sure files are owned properly
    chown -R "$myuser:$mygroup" "$datadir"
fi

exit 0

 

mysql_install_db

[root@CentOS7 ~]# vi /usr/libexec/mysql_install_db

#!/bin/sh
# Copyright (c) 2000, 2013, Oracle and/or its affiliates.
# Copyright (c) 2009, 2013, Monty Program Ab
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

# This scripts creates the MariaDB Server system tables
#
# All unrecognized arguments to this script are passed to mysqld.

basedir="/usr/local/mysql"
builddir=""
ldata="/usr/local/mysql/data"
langdir=""
srcdir=""

args=""
defaults=""
mysqld_opt=""
user=""

force=0
in_rpm=0
ip_only=0
cross_bootstrap=0

usage()
{
  cat <<EOF
Usage: $0 [OPTIONS]
  --basedir=path       The path to the MariaDB installation directory.
  --builddir=path      If using --srcdir with out-of-directory builds, you
                       will need to set this to the location of the build
                       directory where built files reside.
  --cross-bootstrap    For internal use.  Used when building the MariaDB system
                       tables on a different host than the target.
  --datadir=path       The path to the MariaDB data directory.
  --defaults-extra-file=name
                       Read this file after the global files are read.
  --defaults-file=name Only read default options from the given file name.
  --force              Causes mysql_install_db to run even if DNS does not
                       work.  In that case, grant table entries that
                       normally use hostnames will use IP addresses.
  --help               Display this help and exit.                     
  --ldata=path         The path to the MariaDB data directory. Same as
                       --datadir.
  --no-defaults        Don't read default options from any option file.
  --defaults-file=path Read only this configuration file.
  --rpm                For internal use.  This option is used by RPM files
                       during the MariaDB installation process.
  --skip-name-resolve  Use IP addresses rather than hostnames when creating
                       grant table entries.  This option can be useful if
                       your DNS does not work.
  --srcdir=path        The path to the MariaDB source directory.  This option
                       uses the compiled binaries and support files within the
                       source tree, useful for if you don't want to install
                       MariaDB yet and just want to create the system tables.
  --user=user_name     The login username to use for running mysqld.  Files
                       and directories created by mysqld will be owned by this
                       user.  You must be root to use this option.  By default
                       mysqld runs using your current login name and files and
                       directories that it creates will be owned by you.

All other options are passed to the mysqld program

EOF
  exit 1
}

s_echo()
{
  if test "$in_rpm" -eq 0 -a "$cross_bootstrap" -eq 0
  then
    echo "$1"
  fi
}

link_to_help()
{
  echo
  echo "The latest information about mysql_install_db is available at"
  echo "https://mariadb.com/kb/en/installing-system-tables-mysql_install_db"
}

parse_arg()
{
  echo "$1" | sed -e 's/^[^=]*=//'
}

parse_arguments()
{
  # We only need to pass arguments through to the server if we don't
  # handle them here.  So, we collect unrecognized options (passed on
  # the command line) into the args variable.
  pick_args=
  if test "$1" = PICK-ARGS-FROM-ARGV
  then
    pick_args=1
    shift
  fi

  for arg
  do
    case "$arg" in
      --force) force=1 ;;
      --basedir=*) basedir=`parse_arg "$arg"` ;;
      --builddir=*) builddir=`parse_arg "$arg"` ;;
      --srcdir=*)  srcdir=`parse_arg "$arg"` ;;
      --ldata=*|--datadir=*|--data=*) ldata=`parse_arg "$arg"` ;;
      --user=*)
        # Note that the user will be passed to mysqld so that it runs
        # as 'user' (crucial e.g. if log-bin=/some_other_path/
        # where a chown of datadir won't help)
        user=`parse_arg "$arg"` ;;
      --skip-name-resolve) ip_only=1 ;;
      --verbose) verbose=1 ;; # Obsolete
      --rpm) in_rpm=1 ;;
      --help) usage ;;
      --no-defaults|--defaults-file=*|--defaults-extra-file=*)
        defaults="$arg" ;;

      --cross-bootstrap|--windows)
        # Used when building the MariaDB system tables on a different host than
        # the target. The platform-independent files that are created in
        # --datadir on the host can be copied to the target system.
        #
        # The most common use for this feature is in the Windows installer
        # which will take the files from datadir and include them as part of
        # the install package.  See top-level 'dist-hook' make target.
        #
        # --windows is a deprecated alias
        cross_bootstrap=1 ;;

      *)
        if test -n "$pick_args"
        then
          # This sed command makes sure that any special chars are quoted,
          # so the arg gets passed exactly to the server.
          # XXX: This is broken; true fix requires using eval and proper
          # quoting of every single arg ($basedir, $ldata, etc.)
          #args="$args "`echo "$arg" | sed -e 's,\([^a-zA-Z0-9_.-]\),\\\\\1,g'`
          args="$args $arg"
        fi
        ;;
    esac
  done
}

# Try to find a specific file within --basedir which can either be a binary
# release or installed source directory and return the path.
find_in_basedir()
{
  case "$1" in
    --dir)
      return_dir=1; shift
      ;;
  esac

  file=$1; shift

  for dir in "$@"
  do
    if test -f "$basedir/$dir/$file"
    then
      if test -n "$return_dir"
      then
        echo "$basedir/$dir"
      else
        echo "$basedir/$dir/$file"
      fi
      break
    fi
  done
}

cannot_find_file()
{
  echo
  echo "FATAL ERROR: Could not find $1"

  shift
  if test $# -ne 0
  then
    echo
    echo "The following directories were searched:"
    echo
    for dir in "$@"
    do
      echo "    $dir"
    done
  fi

  echo
  echo "If you compiled from source, you need to run 'make install' to"
  echo "copy the software into the correct location ready for operation."
  echo
  echo "If you are using a binary release, you must either be at the top"
  echo "level of the extracted archive, or pass the --basedir option"
  echo "pointing to that location."
  link_to_help
}

# Ok, let's go.  We first need to parse arguments which are required by
# my_print_defaults so that we can execute it first, then later re-parse
# the command line to add any extra bits that we need.
parse_arguments PICK-ARGS-FROM-ARGV "$@"

#
# We can now find my_print_defaults.  This script supports:
#
#   --srcdir=path pointing to compiled source tree
#   --basedir=path pointing to installed binary location
#
# or default to compiled-in locations.
#
if test -n "$srcdir" && test -n "$basedir"
then
  echo "ERROR: Specify either --basedir or --srcdir, not both."
  link_to_help
  exit 1
fi
if test -n "$srcdir"
then
  if test -z "$builddir"
  then
    builddir="$srcdir"
  fi
  print_defaults="$builddir/extra/my_print_defaults"
elif test -n "$basedir"
then
  print_defaults=`find_in_basedir my_print_defaults bin extra`
  if test -z "$print_defaults"
  then
    cannot_find_file my_print_defaults $basedir/bin $basedir/extra
    exit 1
  fi
else
  print_defaults="/usr/local/mysql/bin/my_print_defaults"
fi

if test ! -x "$print_defaults"
then
  cannot_find_file "$print_defaults"
  exit 1
fi

# Now we can get arguments from the groups [mysqld] and [mysql_install_db]
# in the my.cfg file, then re-run to merge with command line arguments.
parse_arguments `"$print_defaults" $defaults --mysqld mysql_install_db`
parse_arguments PICK-ARGS-FROM-ARGV "$@"

# Configure paths to support files
if test -n "$srcdir"
then
  basedir="$builddir"
  bindir="$basedir/client"
  extra_bindir="$basedir/extra"
  mysqld="$basedir/sql/mysqld"
  langdir="$basedir/sql/share/english"
  pkgdatadir="$srcdir/scripts"
  scriptdir="$srcdir/scripts"
elif test -n "$basedir"
then
  bindir="$basedir/bin"
  extra_bindir="$bindir"
  mysqld=`find_in_basedir mysqld libexec sbin bin`
  if test -z "$mysqld"
  then
    cannot_find_file mysqld $basedir/libexec $basedir/sbin $basedir/bin
    exit 1
  fi
  langdir=`find_in_basedir --dir errmsg.sys share/english share/mysql/english`
  if test -z "$langdir"
  then
    cannot_find_file errmsg.sys $basedir/share/english $basedir/share/mysql/english
    exit 1
  fi
  pkgdatadir=`find_in_basedir --dir fill_help_tables.sql share share/mysql`
  if test -z "$pkgdatadir"
  then
    cannot_find_file fill_help_tables.sql $basedir/share $basedir/share/mysql
    exit 1
  fi
  scriptdir="$basedir/scripts"
else
  basedir="/usr"
  bindir="/usr/bin"
  extra_bindir="$bindir"
  mysqld="/usr/libexec/mysqld"
  pkgdatadir="/usr/share/mysql"
  scriptdir="/usr/bin"
fi

# Set up paths to SQL scripts required for bootstrap
fill_help_tables="$pkgdatadir/fill_help_tables.sql"
create_system_tables="$pkgdatadir/mysql_system_tables.sql"
create_system_tables2="$pkgdatadir/mysql_performance_tables.sql"
fill_system_tables="$pkgdatadir/mysql_system_tables_data.sql"

for f in "$fill_help_tables" "$create_system_tables" "$create_system_tables2" "$fill_system_tables"
do
  if test ! -f "$f"
  then
    cannot_find_file "$f"
    exit 1
  fi
done

if test ! -x "$mysqld"
then
  cannot_find_file "$mysqld"
  exit 1
fi

if test -n "$langdir"
then
  if test ! -f "$langdir/errmsg.sys"
  then
    cannot_find_file "$langdir/errmsg.sys"
    exit 1
  fi
  mysqld_opt="--lc-messages-dir=$langdir/.."
else
  mysqld_opt="--lc-messages=en_US"
fi


# Try to determine the hostname
hostname=`hostname`

# Check if hostname is valid
if test "$cross_bootstrap" -eq 0 -a "$in_rpm" -eq 0 -a "$force" -eq 0
then
  resolved=`"$extra_bindir/resolveip" $hostname 2>&1`
  if test $? -ne 0
  then
    resolved=`"$extra_bindir/resolveip" localhost 2>&1`
    if test $? -ne 0
    then
      echo "Neither host '$hostname' nor 'localhost' could be looked up with"
      echo "'$extra_bindir/resolveip'"
      echo "Please configure the 'hostname' command to return a correct"
      echo "hostname."
      echo "If you want to solve this at a later stage, restart this script"
      echo "with the --force option"
      link_to_help
      exit 1
    fi
    echo "WARNING: The host '$hostname' could not be looked up with resolveip."
    echo "This probably means that your libc libraries are not 100 % compatible"
    echo "with this binary MariaDB version. The MariaDB daemon, mysqld, should work"
    echo "normally with the exception that host name resolving will not work."
    echo "This means that you should use IP addresses instead of hostnames"
    echo "when specifying MariaDB privileges !"
  fi
fi

if test "$ip_only" -eq 1
then
  hostname=`echo "$resolved" | awk '/ /{print $6}'`
fi

# Create database directories
for dir in "$ldata" "$ldata/mysql" "$ldata/test"
do
  if test ! -d "$dir"
  then
    if ! `mkdir -p "$dir"`
    then
      echo "Fatal error Can't create database directory '$dir'"
      link_to_help
      exit 1
    fi
    chmod 700 "$dir"
  fi
  if test -n "$user"
  then
    chown $user "$dir"
    if test $? -ne 0
    then
      echo "Cannot change ownership of the database directories to the '$user'"
      echo "user.  Check that you have the necessary permissions and try again."
      exit 1
    fi
  fi
done

if test -n "$user"
then
  args="$args --user=$user"
fi

# When doing a "cross bootstrap" install, no reference to the current
# host should be added to the system tables.  So we filter out any
# lines which contain the current host name.
if test $cross_bootstrap -eq 1
then
  filter_cmd_line="sed -e '/@current_hostname/d'"
else
  filter_cmd_line="cat"
fi

# Configure mysqld command line
mysqld_bootstrap="${MYSQLD_BOOTSTRAP-$mysqld}"
mysqld_install_cmd_line()
{
  "$mysqld_bootstrap" $defaults "$mysqld_opt" --bootstrap \
  "--basedir=$basedir" "--datadir=$ldata" --log-warnings=0 --loose-skip-innodb \
  --loose-skip-ndbcluster $args --max_allowed_packet=8M \
  --default-storage-engine=myisam \
  --net_buffer_length=16K
}


# Create the system and help tables by passing them to "mysqld --bootstrap"
s_echo "Installing MariaDB/MySQL system tables in '$ldata' ..."
if { echo "use mysql;"; cat "$create_system_tables" "$create_system_tables2" "$fill_system_tables"; } | eval "$filter_cmd_line" | mysqld_install_cmd_line > /dev/null
then
  s_echo "OK"
else
  echo
  echo "Installation of system tables failed!  Examine the logs in"
  echo "$ldata for more information."
  echo
  echo "The problem could be conflicting information in an external"
  echo "my.cnf files. You can ignore these by doing:"
  echo
  echo "    shell> $scriptdir/scripts/mysql_install_db --defaults-file=~/.my.cnf"
  echo
  echo "You can also try to start the mysqld daemon with:"
  echo
  echo "    shell> $mysqld --skip-grant --general-log &"
  echo
  echo "and use the command line tool $bindir/mysql"
  echo "to connect to the mysql database and look at the grant tables:"
  echo
  echo "    shell> $bindir/mysql -u root mysql"
  echo "    mysql> show tables;"
  echo
  echo "Try 'mysqld --help' if you have problems with paths.  Using"
  echo "--general-log gives you a log in $ldata that may be helpful."
  link_to_help
  echo "MariaDB is hosted on launchpad; You can find the latest source and"
  echo "email lists at http://launchpad.net/maria"
  echo
  echo "Please check all of the above before submitting a bug report"
  echo "at http://mariadb.org/jira"
  echo
  exit 1
fi

s_echo "Filling help tables..."
if { echo "use mysql;"; cat "$fill_help_tables"; } | mysqld_install_cmd_line > /dev/null
then
  s_echo "OK"
else
  echo
  echo "WARNING: HELP FILES ARE NOT COMPLETELY INSTALLED!"
  echo "The \"HELP\" command might not work properly."
fi

# Don't output verbose information if running inside bootstrap or using
# --srcdir for testing.  In such cases, there's no end user looking at
# the screen.
if test "$cross_bootstrap" -eq 0 && test -z "$srcdir"
then
  s_echo
  s_echo "To start mysqld at boot time you have to copy"
  s_echo "support-files/mysql.server to the right place for your system"

  echo
  echo "PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !"
  echo "To do so, start the server, then issue the following commands:"
  echo
  echo "'$bindir/mysqladmin' -u root password 'new-password'"
  echo "'$bindir/mysqladmin' -u root -h $hostname password 'new-password'"
  echo
  echo "Alternatively you can run:"
  echo "'$bindir/mysql_secure_installation'"
  echo
  echo "which will also give you the option of removing the test"
  echo "databases and anonymous user created by default.  This is"
  echo "strongly recommended for production servers."
  echo
  echo "See the MariaDB Knowledgebase at http://mariadb.com/kb or the"
  echo "MySQL manual for more instructions."

  if test "$in_rpm" -eq 0
  then
    echo
    echo "You can start the MariaDB daemon with:"
    echo "cd '$basedir' ; $bindir/mysqld_safe --datadir='$ldata'"
    echo
    echo "You can test the MariaDB daemon with mysql-test-run.pl"
    echo "cd '$basedir/mysql-test' ; perl mysql-test-run.pl"
  fi

  echo
  echo "Please report any problems at http://mariadb.org/jira"
  echo
  echo "The latest information about MariaDB is available at http://mariadb.org/."
  echo "You can find additional information about the MySQL part at:"
  echo "http://dev.mysql.com"
  echo "Support MariaDB development by buying support/new features from MariaDB"
  echo "Corporation Ab. You can contact us about this at sales@mariadb.com."
  echo "Alternatively consider joining our community based development effort:"
  echo "http://mariadb.com/kb/en/contributing-to-the-mariadb-project/"
  echo
fi

exit 0

 

권한 설정

[root@CentOS7 ~]# chmod +x /usr/libexec/mariadb-wait-ready
[root@CentOS7 ~]# chmod +x /usr/libexec/mariadb-prepare-db-dir
[root@CentOS7 ~]# chmod +x /usr/libexec/mysql_install_db

 

my.cnf 파일 설정

[root@CentOS7 ~]# vi /etc/my.cnf

[mysqld]
#datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
datadir=/usr/local/mysql/data
lc_messages_dir = /usr/local/mysql/share


[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid
pid-file=/var/lib/mysql/mariadb.pid

 

mysql log디렉토리 생성 및 socket 디렉토리 생성

[root@CentOS7 ~]# mkdir -p /var/lib/mysql
[root@CentOS7 ~]# chown mysql:mysql /var/lib/mysql
[root@CentOS7 ~]# mkdir /var/log/mariadb
[root@CentOS7 ~]# chown mysql:mysql /var/log/mariadb
[root@CentOS7 ~]# export MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock

 

Systemd daemon-reload 및 실행

[root@CentOS7 ~]# systemctl daemon-reload
[root@CentOS7 ~]# systemctl start mariadb
[root@CentOS7 ~]# systemctl enable mariadb

 

mysql_secure_installation

[root@CentOS7 ~]# vi .bash_profile

PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

export PATH
export MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock



[root@CentOS7 ~]# source .bash_profile

[root@CentOS7 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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
 ... 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
 ... Success!

By default, MariaDB 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
 - 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
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@CentOS7 ~]#

Mariadb Status
[root@CentOS7 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.8-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> status;
--------------
mysql  Ver 15.1 Distrib 10.3.8-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:          17
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server:                 MariaDB
Server version:         10.3.8-MariaDB Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 2 min 0 sec

Threads: 7  Questions: 20  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 12  Queries per second avg: 0.166
--------------

MariaDB [(none)]> quit;
Bye
[root@CentOS7 ~]#

 

mariadb 실행 확인

[root@CentOS7 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-12-01 03:43:37 KST; 8s ago
  Process: 2028 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 2002 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 2027 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─2027 /bin/sh /usr/local/mysql/bin/mysqld_safe --basedir=/usr
           └─2125 /usr/local/mysql/bin/mysqld --basedir=/usr --datadir=/usr/local/mysql/data --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/lib/mysql/mariadb.pid --socket=/var/lib/mysql/mysql.sock

Dec 01 03:43:36 CentOS7 systemd[1]: Starting MariaDB database server...
Dec 01 03:43:36 CentOS7 mysqld_safe[2027]: 181201 03:43:36 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Dec 01 03:43:36 CentOS7 mysqld_safe[2027]: 181201 03:43:36 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
Dec 01 03:43:37 CentOS7 systemd[1]: Started MariaDB database server.
[root@CentOS7 ~]#

 

php 7.2 사용시 필요한 설정

[root@CentOS7 ~]# mv /usr/local/mysql/include /usr/local/mysql/include.def
[root@CentOS7 ~]# mkdir -p /usr/local/mysql/include/mysql
[root@CentOS7 ~]# chown -R mysql:mysql /usr/local/mysql/include
[root@CentOS7 ~]# cd /usr/local/src/mariadb-10.3.8/include
[root@CentOS7 include]# cp -rf ./* /usr/local/mysql/include/mysql

 

php7.2 설치

 

php-7.2.12.tar 파일 다운로드 

[root@CentOS7 ~]# cd /usr/local/src/
[root@CentOS7 src]# wget --trust-server-names http://jp2.php.net/get/php-7.2.12.tar.xz/from/this/mirror
[root@CentOS7 src]# tar xvf php-7.2.12.tar.xz
[root@CentOS7 src]# cd php-7.2.12/

 

php-7.2 설치 

[root@CentOS7 php-7.2.12]# ./configure --prefix=/usr/local/php \
--with-config-file-path=/etc \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-scan-dir=/etc/php/php.d --with-zlib-dir --enable-mbstring --with-curl \
--with-zlib --disable-rpath --enable-inline-optimization --enable-sockets \
--with-mysqli --with-openssl --with-fpm-user=nobody --with-fpm-group=nobody \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-pdo-mysql --enable-zip 

[root@CentOS7 php-7.2.12]# make && make install

 

httpd.conf 파일

[root@CentOS7 ~]# vi /usr/local/apache2/conf/httpd.conf

    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps

    DirectoryIndex index.php index.html


[root@CentOS7 ~]# systemctl restart httpd

 

phpinfo

[root@CentOS7 ~]# vi /usr/local/apache2/htdocs/test.php
<?php phpinfo(); ?>