• R/O
  • SSH
  • HTTPS

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++objective-ccocoa誰得c#gamelinuxbathyscaphephp翻訳qtrubycwindowspythonomegattwitterguiframeworkbtronarduinovb.netdirectxtestゲームエンジンdom計画中(planning stage)previewer

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


File Info

Rev. 12
Size 3,333 bytes
Time 2018-08-22 19:07:58
Author earlgreyx
Log Message

(empty log message)

Content

  1. #!/bin/sh
  2. #-------------------------------------------------------------------------------
  3. #
  4. # Install LAMP environment into Windows Subsystem for Linux(Ubuntu)
  5. #
  6. #-------------------------------------------------------------------------------
  7. mysqluser=wpuser
  8. mysqlpass=0000
  9. mysqldb=wordpress
  10. randomstr=kdfj23432jj4j5j43544kjfkjkljfsai
  11. phppostmax=110M
  12. phpuploadmax=100M
  13. phpmemory=-1
  14. phptimezone=Asia\\/Tokyo
  15. packages='apache2 apache2-doc mysql-server mysql-client php php-mbstring php-mysql php-sqlite3 php-gd php-mcrypt libapache2-mod-php'
  16. if [ root != "$USER" ] ; then
  17. echo '[ERROR] Please run this script with root.'
  18. exit 1
  19. fi
  20. cuser=$SUDO_USER
  21. if [ -z "$cuser" ] ; then
  22. echo 'What is your username? (not root) : '
  23. read cuser
  24. if [ ! -z "${cuser}" ] ; then
  25. isvalid=`grep ^${cuser} /etc/passwd`
  26. if [ -z "${isvalid}" -o "${cuser}" = "root" ] ; then
  27. echo '[ERROR] Please input valid username.'
  28. exit 1
  29. fi
  30. else
  31. echo '[ERROR] Please input username.'
  32. exit 1
  33. fi
  34. fi
  35. echo 'Input windows directory to access by apache (ex. /mnt/c/working ): '
  36. read wdir
  37. if [ -z "${wdir}" -o ! -d $wdir ] ; then
  38. echo '[ERROR] Please input exisiting directory.'
  39. exit 1
  40. fi
  41. echo 'What is name associated this directory? [/working] :'
  42. read vdir
  43. if [ -z "${vdir}" ] ; then
  44. vdir=/working
  45. fi
  46. sed -i.orig -e 's%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g' /etc/apt/sources.list
  47. apt update
  48. apt -y upgrade
  49. apt -y install $packages
  50. echo setting apache2 ...
  51. cat << '__EOS__' >> /etc/apache2/apache2.conf
  52. AcceptFilter http none
  53. AcceptFilter https none
  54. __EOS__
  55. chown -R ${cuser}:${cuser} /var/www/html
  56. cat << __EOS__ > /etc/apache2/conf-available/windows.conf
  57. <Directory "${wdir}">
  58. AllowOverride All
  59. Options All
  60. Require all granted
  61. AddHander cgi-script .cgi
  62. </Directory>
  63. Alias ${vdir} "${wdir}"
  64. __EOS__
  65. a2enconf windows
  66. a2enmods php7.2
  67. echo setting php ...
  68. cat << __EOS__ | /bin/sh
  69. 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.0/apache2/php.ini
  70. __EOS__
  71. echo setting mysql ...
  72. mkdir /home/mysql
  73. chown mysql:mysql /home/mysql
  74. usermod -d /home/mysql mysql
  75. cat << '__EOS__' >> /etc/mysql/my.cnf
  76. [client]
  77. default-character-set = utf8
  78. [mysql]
  79. default-character-set = utf8
  80. [mysqld]
  81. character-set-server = utf8
  82. __EOS__
  83. service mysql start
  84. echo 'Start create user(wpuser) and database(wordpress) on mysql.'
  85. echo 'Please input mysql root password...'
  86. cat << __EOS__ | mysql -u root -p
  87. CREATE USER ${mysqluser} IDENTIFIED BY '${mysqlpass}';
  88. CREATE DATABASE ${mysqldb} DEFAULT CHARACTER SET utf8;
  89. GRANT all privileges ON ${mysqldb}.* TO ${mysqluser};
  90. __EOS__
  91. service mysql stop
  92. cat << __EOS__ | sudo -u ${cuser} /bin/sh
  93. cd /home/${cuser}
  94. ln -s /var/www/html wwwroot
  95. cd wwwroot
  96. wget -O - https://files.phpmyadmin.net/phpMyAdmin/4.7.5/phpMyAdmin-4.7.5-all-languages.tar.gz | tar xvzf -
  97. mv phpMyAdmin-4.7.5-all-languages phpMyAdmin
  98. cat ./phpMyAdmin/config.sample.inc.php | sed -r 's/^(\$cfg\['\''blowfish_secret'\''\]) *= *'\''.*'\''/\1 = '\''${randomstr}'\''/g' > ./phpMyAdmin/config.inc.php
  99. __EOS__
  100. echo 'Setup apache,mysql is over.'
  101. exit 0