• R/O
  • SSH
  • HTTPS

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamewindowspythonphpguic翻訳omegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

Windows10のWSL ubuntuにWORDPRESSが動くLAMP環境をセットアップします


File Info

Rev. 15
Size 3,384 bytes
Time 2019-05-15 19:09:18
Author earlgreyx
Log Message

php-mcryptの記述が残っていたので削除

Content

#!/bin/sh
#-------------------------------------------------------------------------------
#
#  Install LAMP environment into Windows Subsystem for Linux(Ubuntu)
#
#-------------------------------------------------------------------------------
mysqluser=wpuser
mysqlpass=0000
mysqldb=wordpress
randomstr=kdfj23432jj4j5j43544kjfkjkljfsai
phppostmax=110M
phpuploadmax=100M
phpmemory=-1
phptimezone=Asia\\/Tokyo
packages='language-pack-ja apache2 apache2-doc mysql-server mysql-client php php-mbstring php-mysql php-sqlite3 php-gd libapache2-mod-php' 

if [ root != "$USER" ] ; then
	echo '[ERROR] Please run this script with root.'
	exit 1
fi

cuser=$SUDO_USER
if [ -z "$cuser" ] ; then  
  echo 'What is your username? (not root) : '
  read cuser
  if [ ! -z "${cuser}" ] ; then
     isvalid=`grep ^${cuser} /etc/passwd`
     if [ -z "${isvalid}" -o "${cuser}" = "root" ] ; then
        echo '[ERROR] Please input valid username.'
        exit 1
      fi
  else
      echo '[ERROR] Please input username.'
      exit 1
  fi
fi

echo 'Input windows directory to access by apache (ex. /mnt/c/working ): '
read wdir
if [ -z "${wdir}" -o ! -d $wdir ] ; then
  echo '[ERROR] Please input exisiting directory.'
  exit 1
fi
echo 'What is name associated this directory? [/working] :'
read vdir
if [ -z "${vdir}" ] ; then 
  vdir=/working
fi

sed -i.orig -e 's%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g' /etc/apt/sources.list

apt update
apt -y upgrade

apt -y install $packages


echo setting apache2 ...

cat << '__EOS__' >> /etc/apache2/apache2.conf

AcceptFilter http none
AcceptFilter https none

__EOS__

chown -R ${cuser}:${cuser} /var/www/html

cat << __EOS__ > /etc/apache2/conf-available/windows.conf
<Directory "${wdir}">
  AllowOverride All
  Options All
  Require all granted
  AddHandler cgi-script .cgi
</Directory>
Alias ${vdir} "${wdir}"


__EOS__

a2enconf windows
a2enmods php7.2

echo setting php ...

cat << __EOS__ | /bin/sh
sed -i.orig -r -e 's/^(date.timezone) *= *".*"/\1 = "${phptimezone}"/g' -e 's/^(upload_max_filesize) *= *(.*)/\1 = ${phpuploadmax}/g' -e 's/^(post_max_size) *= *(.*)/\1 = ${phppostmax}/g' -e 's/^(memory_limit) *= *(.*)/\1 = ${phpmemory}/g' /etc/php/7.2/apache2/php.ini
__EOS__


echo setting mysql ...

mkdir /home/mysql
chown mysql:mysql /home/mysql
usermod -d /home/mysql mysql

cat << '__EOS__' >> /etc/mysql/my.cnf

[client]
default-character-set = utf8

[mysql]
default-character-set = utf8

[mysqld]
character-set-server = utf8
__EOS__

service mysql start

echo 'Start create user(wpuser) and database(wordpress) on mysql.'
echo 'Please input mysql root password...'
cat << __EOS__ | mysql -u root -p
CREATE USER ${mysqluser} IDENTIFIED BY '${mysqlpass}';
CREATE DATABASE ${mysqldb} DEFAULT CHARACTER SET utf8;
GRANT all privileges ON ${mysqldb}.* TO ${mysqluser};
__EOS__
service mysql stop

cat << __EOS__ | sudo -u ${cuser} /bin/sh
cd /home/${cuser}
ln -s /var/www/html wwwroot
cd wwwroot
wget -O - https://files.phpmyadmin.net/phpMyAdmin/4.7.5/phpMyAdmin-4.7.5-all-languages.tar.gz | tar xvzf -
mv phpMyAdmin-4.7.5-all-languages phpMyAdmin
cat ./phpMyAdmin/config.sample.inc.php | sed -r 's/^(\$cfg\['\''blowfish_secret'\''\]) *= *'\''.*'\''/\1 = '\''${randomstr}'\''/g' > ./phpMyAdmin/config.inc.php
__EOS__

# set locale
update-locale LANG=ja_JP.UTF-8

echo 'Setup apache,mysql is over.'

exit 0