Advertisement
Majorchamp

Untitled

Mar 5th, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.77 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. echo "#######################################"
  4. echo "#######################################"
  5. echo "#######################################"
  6. echo "#######################################"
  7. echo "#######################################"
  8. echo "#######################################"
  9. echo " "
  10. echo "This Debian 8 server running PHP 7.0 is using Nginx as a reverse proxy on port 8080"
  11. echo " "
  12. echo "#######################################"
  13. echo "#######################################"
  14. echo "#######################################"
  15. echo "#######################################"
  16. echo "#######################################"
  17. echo "#######################################"
  18.  
  19.  
  20. # Use single quotes instead of double quotes to make it work with special-character passwords
  21. PASSWORD='root'
  22. PROJECTFOLDER='project'
  23. ADDTIONALPATH=''
  24. WEBSERVERIP='192.168.22.33' #enter your chosen IP here
  25.  
  26.  
  27. # update / upgrade
  28. apt-get update
  29. apt-get -y upgrade
  30.  
  31.  
  32. echo "#######################################"
  33. echo " "
  34. echo "Install Apache2 and helper utils"
  35. echo " "
  36. echo "#######################################"
  37.  
  38. # install apache 2.5 and php 5.5
  39. apt-get install -y apache2 python-software-properties vim htop curl git npm nodejs grunt
  40.  
  41. echo "#######################################"
  42. echo " "
  43. echo "Install Nginx"
  44. echo " "
  45. echo "#######################################"
  46. # install and setup Nginx + reverse proxy
  47. apt-get install -y nginx
  48.  
  49. echo "#######################################"
  50. echo " "
  51. echo "Added DotDeb.org packages for PHP7.0"
  52. echo " "
  53. echo "#######################################"
  54. # Needed to install PHP 7 into Debian
  55. cat <<EOT >> /etc/apt/sources.list
  56. deb http://packages.dotdeb.org jessie all
  57. deb-src http://packages.dotdeb.org jessie all
  58. EOT
  59.  
  60. wget https://www.dotdeb.org/dotdeb.gpg
  61. apt-key add dotdeb.gpg
  62.  
  63. apt-get update
  64.  
  65. echo "#######################################"
  66. echo " "
  67. echo "Install PHP7.0 and supporting packages"
  68. echo " "
  69. echo "#######################################"
  70. #apt-get install -y php7.0 php7.0-common php7.0-cli php7.0-mbstring php7.0-xml php7.0-curl php7.0-json php7.0-phpdbg php7.0-readline php7.0-mcrypt php7.0-gd php7.0-mbstring
  71. apt-get install -y php7.0-common php7.0-dev php7.0-json php7.0-opcache php7.0-cli libapache2-mod-php7.0 php7.0 php7.0-mysql php7.0-fpm php7.0-curl php7.0-gd php7.0-mcrypt php7.0-mbstring php7.0-bcmath php7.0-zip
  72.  
  73. echo "#######################################"
  74. echo " "
  75. echo "Install Mysql Server and PHPMyAdmin. user = root / Password = $PASSWORD"
  76. echo " "
  77. echo "#######################################"
  78. # install mysql and give password to installer
  79. debconf-set-selections <<< "mysql-server mysql-server/root_password password $PASSWORD"
  80. debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $PASSWORD"
  81. apt-get -y install mysql-server
  82. apt-get install php7.0-mysql
  83.  
  84. # install phpmyadmin and give password(s) to installer
  85. # for simplicity I'm using the same password for mysql and phpmyadmin
  86. debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
  87. debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $PASSWORD"
  88. debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $PASSWORD"
  89. debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $PASSWORD"
  90. debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"
  91. apt-get -y install phpmyadmin
  92.  
  93. echo "#######################################"
  94. echo " "
  95. echo "Setup Apache Virtual Host for /var/www/html/${PROJECTFOLDER}${ADDITIONALPATH}"
  96. echo " "
  97. echo "#######################################"
  98. # setup hosts file
  99. VHOST=$(cat <<EOF
  100. <VirtualHost *:8080>
  101.     ServerName ${PROJECTFOLDER}.dev
  102.     DocumentRoot "/var/www/html/${PROJECTFOLDER}${ADDITIONALPATH}"
  103.     <Directory "/var/www/html/${PROJECTFOLDER}${ADDITIONALPATH}">
  104.         AllowOverride All
  105.         Require all granted
  106.     </Directory>
  107. </VirtualHost>
  108. EOF
  109. )
  110. echo "${VHOST}" > /etc/apache2/sites-available/${PROJECTFOLDER}.conf
  111.  
  112. a2ensite ${PROJECTFOLDER}.conf
  113.  
  114.  
  115. echo "#######################################"
  116. echo " "
  117. echo "Setup Nginx Server Block for Reverse Proxy"
  118. echo " "
  119. echo "#######################################"
  120.  
  121. # setup Nginx Apache conf proxy
  122. nginxsetupDefault=$(cat <<EOF
  123. server {
  124.     listen 80;
  125.     server_name ${PROJECTFOLDER}.dev localhost;
  126.  
  127.     location / {
  128.         proxy_pass http://${WEBSERVERIP}:8080;
  129.         proxy_set_header Host \$host;
  130.         proxy_set_header X-Real-IP \$remote_addr;
  131.         proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  132.         proxy_set_header X-Forwarded-Proto \$scheme;
  133.     }
  134. }
  135.  
  136. EOF
  137. )
  138.  
  139. echo "${nginxsetupDefault}" > /etc/nginx/sites-available/apache
  140. ln -s /etc/nginx/sites-available/apache /etc/nginx/sites-enabled/apache
  141.  
  142.  
  143. echo "#######################################"
  144. echo " "
  145. echo "Modifications to FASTCGI.CONF"
  146. echo " "
  147. echo "#######################################"
  148. # Add the following content to the FastCGI.conf
  149. fastcgivar="$(cat <<EOF
  150. <IfModule mod_fastcgi.c>
  151.    AddHandler fastcgi-script .fcgi
  152.    #FastCgiWrapper /usr/lib/apache2/suexec
  153.    FastCgiIpcDir /var/lib/apache2/fastcgi
  154.    AddType application/x-httpd-fastphp .php
  155.    Action application/x-httpd-fastphp /php-fcgi
  156.    Alias /php-fcgi /usr/lib/cgi-bin/php-fcgi
  157.    FastCgiExternalServer /usr/lib/cgi-bin/php-fcgi -socket /run/php/php7.0-fpm.sock -pass-header Authorization
  158.    <Directory /usr/lib/cgi-bin>
  159.        Require all granted
  160.    </Directory>
  161. </IfModule>
  162. EOF
  163. )"
  164.  
  165. echo "${fastcgivar}" > /etc/apache2/mods-enabled/fastcgi.conf
  166.  
  167. echo "#######################################"
  168. echo " "
  169. echo "Change ports.conf to Listen to 8080"
  170. echo " "
  171. echo "#######################################"
  172. # modify Listen from 80 to 8080 for reverse proxy
  173. modifyports=$(cat <<EOF
  174. # If you just change the port or add more ports here, you will likely also
  175. # have to change the VirtualHost statement in
  176. # /etc/apache2/sites-enabled/000-default.conf
  177.  
  178. Listen 8080
  179.  
  180. <IfModule ssl_module>
  181.         Listen 443
  182. </IfModule>
  183.  
  184. <IfModule mod_gnutls.c>
  185.         Listen 443
  186. </IfModule>
  187.  
  188. # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  189.  
  190. EOF
  191. )
  192.  
  193. echo "${modifyports}" > /etc/apache2/ports.conf
  194.  
  195. # enable mod_rewrite
  196. a2enmod rewrite
  197.  
  198.  
  199. echo "#######################################"
  200. echo " "
  201. echo "Restart Apache and Nginx"
  202. echo " "
  203. echo "#######################################"
  204. # restart apache
  205. service apache2 restart
  206. # restart apache
  207. service nginx restart
  208.  
  209.  
  210.  
  211. echo "#######################################"
  212. echo " "
  213. echo "Install Composer"
  214. echo " "
  215. echo "#######################################"
  216.  
  217. # install Composer
  218. curl -s https://getcomposer.org/installer | php
  219. mv composer.phar /usr/local/bin/composer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement