LAMP Source Auto Installer


/ Published in: Bash
Save to your folder(s)

Automatically Download and install a LAMP Setup from Source


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2. #
  3. # Web Server Installer
  4. # Copyright (C) 2012 Keiran "Affix" Smith <[email protected]>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19.  
  20. echo "+-------------------------------------+"
  21. echo "| Web Server Installer |"
  22. echo "| Automatically Configure and Build : |"
  23. echo "| Apache |"
  24. echo "| mySQL |"
  25. echo "| PHP |"
  26. echo "+-------------------------------------+"
  27. echo ""
  28.  
  29. if [ "$(whoami)" != 'root' ]; then
  30. echo "You must be root to run this script"
  31. # exit 1;
  32. fi
  33.  
  34. read -p "Please Enter Install Directory [/opt/web] : " installDir
  35.  
  36. if [ -z $installDir ]
  37. then
  38. installDir="/opt/web"
  39. fi
  40.  
  41. echo "Cleaning old temporary Installation Files (if any)!"
  42. rm -rf /tmp/webServer
  43. echo "Creating Installation Directories"
  44. mkdir $installDir
  45. mkdir /tmp/webServer
  46.  
  47. cd /tmp/webServer
  48.  
  49. mkpass() {
  50. [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
  51. cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
  52. echo
  53. }
  54.  
  55. retrieveApache() {
  56. $(wget http://mirror.rmg.io/apache//httpd/httpd-2.2.21.tar.gz -O /tmp/webServer/httpd.tar.gz --quiet)
  57. echo "Extracting Apache"
  58. $(tar -zxvf /tmp/webServer/httpd.tar.gz > /dev/null)
  59. echo "Apache Downloaded and Extracted!"
  60. cd /tmp/webServer
  61. }
  62.  
  63. buildApache() {
  64. cd /tmp/webServer/httpd-2.2.21
  65. ./configure --prefix=$installDir/apache --enable-shared=max --enable-module=rewrite --enable-module=so
  66. make && make install
  67. ln -s $installDir/apache/bin/apachectl /etc/rc.d/init.d/apache
  68. }
  69.  
  70. retrievemySQL() {
  71. cd /tmp/webServer
  72. wget http://www.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-5.5/mysql-5.5.20-linux2.6-$(uname -m).tar.gz -O /tmp/webServer/mySQL.tar.gz --quiet
  73. echo "Extracting mySQL"
  74. tar -zxvf /tmp/webServer/mySQL.tar.gz
  75. echo "mySQL Downloaded and Extracted!"
  76. }
  77.  
  78. buildmySQL() {
  79. cd /tmp/webServer/mysql-5.5.20
  80. echo "Creating MySQL User and Group"
  81. groupadd mysql
  82. useradd -g mysql -c "MySQL Server" mysql
  83. echo "Starting the MySQL Build"
  84. ./configure --prefix=$installDir/mysql --localstatedir=$installDir/mysql/data --disable-maintainer-mode --with-musqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --without-comment --withour-debug --without-bench
  85. make && make install
  86.  
  87. }
  88.  
  89. configmySQL() {
  90. cd /tmp/webServer/mysql-5.5.20
  91. scripts/mysql_install_db
  92. chown -R root:mysql $installDir/mysql
  93. chown -R mysql:mysql $installDir/mysql/data
  94. cp support-files/my-medium.cnf /etc/my.cnf
  95. chown root:root /etc/my.cnf
  96. chmod 644 /etc/my.cnf
  97. echo "$installDir/mysql/lib/mysql" >> /etc/ld.so.conf
  98. ldconfig
  99. cd $installDir/mysql/bin
  100. for file in *; do ln -s $installDir/mysql/bin/$file /usr/bin/$file; done
  101. cd /tmp/webServer/mysql-5.5.20
  102. cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
  103. chmod +x /etc/rc.d/init.d/mysql
  104. /etc/rc.d/init.d/mysql start
  105. mysql -u root password $sqlrootPass
  106. /etc/rc.d/init.d/mysql stop
  107. clear
  108.  
  109. }
  110.  
  111. retrievePHP() {
  112. cd /tmp/webServer
  113. wget http://uk.php.net/distributions/php-5.3.9.tar.gz -O /tmp/webServer/php.tar.gz --quiet
  114. echo "Extracting PHP"
  115. tar -zxvf /tmp/webServer/php.tar.gz > /dev/null
  116. echo "PHP Downloaded and Extracted!"
  117. cd /tmp/webServer
  118. }
  119.  
  120. buildPHP() {
  121. cd /tmp/webServer/php-5.3.9
  122. ./configure --with-apxs=$installDir/apache/bin/apxs --disable-debug --enable-ftp --enable-inline-optimization --enable-magic-quotes --enable-mbstring --enable-mm=shared --enable-safe-mode --enable-track-vars --enable-trans-sid --enable-wddx=shared --enable-xml --with-dom --with-gd --with-gettext --with-mysql=$installDir/mysql --with-regex=system --with-xml --with-zlib-dir=/usr/lib
  123. make && make install
  124. cp php.ini-dist /usr/local/lib/php.ini
  125. ln -s /usr/local/lib/php.ini /etc/php.ini
  126. }
  127.  
  128. read -p "Install Apache [Y/n] : " apacheInst
  129. read -p "Install mySQL [Y/n] : " mySQLInst
  130. read -p "Install PHP [Y/n] : " PHPInst
  131. if [ "$mySQLInst" != "n" ]
  132. then
  133. read -p "Please enter your new mySQL root password (if blank one will be generated) : " sqlrootPass
  134. if [ -z $sqlrootPass ]
  135. then
  136. sqlrootPass=$(mkpass 20 0)
  137. fi
  138. fi
  139.  
  140. if [ "$apacheInst" != "n" ]
  141. then
  142. echo "Retrieving Apache..."
  143. retrieveApache
  144. echo "Building Apache..."
  145. buildApache
  146. clear
  147. fi
  148.  
  149. if [ "$mySQLInst" != "n" ]
  150. then
  151. echo "Retrieving mySQL..."
  152. retrievemySQL
  153. echo "Building mySQL..."
  154. buildmySQL
  155. echo "mySQL Build Completed now launching configuration."
  156. configmySQL
  157. clear
  158. fi
  159.  
  160. if [ "$PHPInst" != "n" ]
  161. then
  162. echo "Retrieving PHP..."
  163. retrievePHP
  164. echo "Building PHP..."
  165. buildPHP
  166. clear
  167. fi
  168.  
  169. rm -rf /tmp/webServer
  170. clear
  171. echo "Instalation Complete!!"
  172. echo "Installation Directory : $installDir"
  173. echo "mySQL Root Password : $sqlrootPass"
  174. echo ""
  175. read -p "Start Services ? [Y/n]" $startServices
  176. if [ "$startServices" != "n" ]
  177. then
  178. echo "Starting Apache"
  179. /etc/rc.d/init.d/apache start
  180. echo "Starting mySQL"
  181. /etc/rc.d/init.d/mysql start
  182.  
  183. fi
  184. echo "Thanks for trying my script visit http://affix.me :D"

URL: http://affix.me

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.