• R/O
  • SSH
  • HTTPS

Tags
No Tags

Frequently used words (click to add to your profile)

javaandroidc++cocoaobjective-cc#誰得gamephpbathyscaphelinuxqtrubycomegat翻訳pythontwitterwindowsbtronvb.nettestframeworkgui計画中(planning stage)directxpreviewerpukiwikidommruby

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


File Info

Rev. 7
Size 3,288 bytes
Time 2017-11-14 23:01:55
Author earlgreyx
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/sites-available/windows.conf
  57. <Directory "${wdir}">
  58. AllowOverride All
  59. Options All
  60. Require all granted
  61. </Directory>
  62. Alias ${vdir} "${wdir}"
  63. __EOS__
  64. a2ensite windows
  65. echo setting php ...
  66. cat << __EOS__ | /bin/sh
  67. 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
  68. __EOS__
  69. echo setting mysql ...
  70. mkdir /home/mysql
  71. chown mysql:mysql /home/mysql
  72. usermod -d /home/mysql mysql
  73. cat << '__EOS__' >> /etc/mysql/my.cnf
  74. [client]
  75. default-character-set = utf8
  76. [mysql]
  77. default-character-set = utf8
  78. [mysqld]
  79. character-set-server = utf8
  80. __EOS__
  81. service mysql start
  82. echo 'Start create user(wpuser) and database(wordpress) on mysql.'
  83. echo 'Please input mysql root password...'
  84. cat << __EOS__ | mysql -u root -p
  85. CREATE USER ${mysqluser} IDENTIFIED BY '${mysqlpass}';
  86. CREATE DATABASE ${mysqldb} DEFAULT CHARACTER SET utf8;
  87. GRANT all privileges ON ${mysqldb}.* TO ${mysqluser};
  88. __EOS__
  89. service mysql stop
  90. cat << __EOS__ | sudo -u ${cuser} /bin/sh
  91. cd /home/${cuser}
  92. ln -s /var/www/html wwwroot
  93. cd wwwroot
  94. wget -O - https://files.phpmyadmin.net/phpMyAdmin/4.7.5/phpMyAdmin-4.7.5-all-languages.tar.gz | tar xvzf -
  95. mv phpMyAdmin-4.7.5-all-languages phpMyAdmin
  96. cat ./phpMyAdmin/config.sample.inc.php | sed -r 's/^(\$cfg\['\''blowfish_secret'\''\]) *= *'\''.*'\''/\1 = '\''${randomstr}'\''/g' > ./phpMyAdmin/config.inc.php
  97. __EOS__
  98. echo 'Setup apache,mysql is over.'
  99. exit 0