Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # version 1.2
  4. ### changelog: first ask whether it's a laravel project or not.
  5.  
  6. # to be able to work this function globally, copy or create link in /usr/local/bin with execute permission (chmod +x)
  7. ## Process
  8. # 1. cp .env.example .env
  9. # 2. composer install
  10. # 3. php artisan key:generate
  11. # 4. ask for db credentials and save to .env
  12. # [Optional]
  13. # 5. make server block
  14.  
  15.  
  16. makeServerBlock() {
  17. try_files='try_files $uri $uri/ /index.php?q=$uri&$args;'
  18. block="/etc/nginx/sites-available/$domain"
  19.  
  20. #--------------------------------------------------------------------
  21.  
  22. # add to /etc/hosts file
  23. sudo sh -c 'echo "127.0.0.1 '$domain'" >> /etc/hosts'
  24.  
  25.  
  26. # Create the Nginx server block file:
  27. sudo tee $block > /dev/null <<EOF
  28. server {
  29. listen 80;
  30. listen [::]:80;
  31.  
  32. root $path;
  33. index index.php index.html index.htm;
  34.  
  35. server_name $domain;
  36.  
  37. location / {
  38. #autoindex on;
  39. $try_files
  40. }
  41.  
  42. location ~ \.php$ {
  43. include snippets/fastcgi-php.conf;
  44. fastcgi_pass unix:/run/php/php$php-fpm.sock;
  45. }
  46.  
  47. location ~ /\.ht {
  48. deny all;
  49. }
  50. }
  51.  
  52.  
  53. EOF
  54.  
  55. # Link to make it available
  56. sudo ln -s $block /etc/nginx/sites-enabled/
  57.  
  58. # Test configuration and reload if successful
  59. sudo nginx -t && sudo service nginx reload
  60.  
  61. # Give write Permission to /bootstrap/cache & /storage
  62. if [ -d $(pwd)/storage ] ; then
  63. sudo chgrp -R www-data $(pwd)/storage $(pwd)/bootstrap/cache
  64. sudo chmod -R ug+rwx $(pwd)/storage $(pwd)/bootstrap/cache
  65. fi
  66.  
  67. }
  68.  
  69. # get accessories ready foor server block
  70. prepareForServerBlock() {
  71. echo Enter your local domain name:
  72. read domain
  73.  
  74. echo Select PHP version for the project? [7.2]:
  75. read php
  76. if [ -z "$php" ]
  77. then
  78. php='7.2'
  79. else
  80. php=$php
  81. fi
  82.  
  83. makeServerBlock $domain $path $php
  84. }
  85.  
  86. processForLaravelProject() {
  87. # 1. cp .env.example .env
  88. cp .env.example .env
  89. echo '.env created';
  90. #
  91. ## 2. composer install
  92. composer install
  93. #
  94. ## 3. php artisan key:generate
  95. php artisan key:generate
  96.  
  97. # 4. ask for db credentials and save to .env
  98. echo Enter your database name, user and password [with space]:
  99. read db user pass
  100.  
  101. # replace DB_DATABASE, DB_USERNAME & DB_PASSWORD in .env
  102. sed -i 's/DB_DATABASE=homestead/DB_DATABASE='$db'/g' .env
  103. sed -i 's/DB_USERNAME=homestead/DB_USERNAME='$user'/g' .env
  104. sed -i 's/DB_PASSWORD=secret/DB_PASSWORD='$pass'/g' .env
  105.  
  106. echo Your database name is $db, user is $user and password is $pass
  107. }
  108.  
  109. echo Is this a laravel project? [y/n]:
  110. read isLaravel
  111.  
  112. case $isLaravel in
  113. [Yy]* )
  114. path=$(pwd)/public
  115. processForLaravelProject
  116. prepareForServerBlock $path
  117. ;;
  118. [Nn]* )
  119. path=$(pwd)
  120. prepareForServerBlock $path
  121. ;;
  122. * )
  123. path=$(pwd)/public
  124. processForLaravelProject
  125. prepareForServerBlock $path
  126. ;;
  127. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement