Guest User

Untitled

a guest
Dec 6th, 2017
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.93 KB | None | 0 0
  1. php -d memory_limit=-1 magento setup:install
  2. --admin-firstname="magento"
  3. --admin-lastname="admin"
  4. --admin-email="admin@email.com"
  5. --admin-user='admin'
  6. --admin-password="Admin123"
  7. --base-url="https://magento-2.dev"
  8. --use-rewrites=1
  9. --db-host="localhost"
  10. --db-user="magento_2"
  11. --db-name="magento_2"
  12. --db-password="magento_2"
  13. --use-secure=1
  14. --use-sample-data
  15.  
  16. php -d memory_limit=-1 setup:static-content:deploy -f
  17.  
  18. <?php
  19. $app->command('db [name]', function ($name) {
  20. if (!$name) {
  21. warning('Please specify a database name');
  22. return;
  23. }
  24.  
  25. $create_db_command = sprintf("mysql -uroot -e "create database %s"", $name);
  26. $create_user_command = sprintf("mysql -uroot -e "create user '%s'@'localhost' identified by '%s'"", $name, $name);
  27. $grant_privileges_command = sprintf("mysql -uroot -e "grant all privileges on %s.* to '%s'@'localhost'"", $name, $name);
  28.  
  29. $commands = compact('create_db_command', 'create_user_command', 'grant_privileges_command');
  30.  
  31. foreach ($commands as $command) {
  32. if ($error = CommandLine::run($command)) {
  33. warning($command);
  34. warning($error);
  35. return;
  36. }
  37. }
  38. info('The database '.$name.' has been created');
  39. })->descriptions('Create a new database');
  40.  
  41. <?php
  42. class Magento2ValetDriver extends ValetDriver
  43. {
  44. private $mageMode;
  45.  
  46. public function serves($sitePath, $siteName, $uri)
  47. {
  48. return file_exists($sitePath . '/bin/magento') && file_exists($sitePath . '/pub/index.php');
  49. }
  50.  
  51. public function isStaticFile($sitePath, $siteName, $uri)
  52. {
  53. $this->checkMageMode($sitePath);
  54. $route = parse_url(substr($uri, 1))['path'];
  55. $pub = '';
  56. if ('developer' === $this->mageMode) {
  57. $pub = 'pub/';
  58. }
  59. if (!$this->isPubDirectory($sitePath, $route, $pub)) {
  60. return false;
  61. }
  62. $magentoPackagePubDir = $sitePath;
  63. if ('developer' !== $this->mageMode) {
  64. $magentoPackagePubDir .= '/pub';
  65. }
  66. $file = $magentoPackagePubDir . '/' . $route;
  67. if (file_exists($file)) {
  68. return $magentoPackagePubDir . $uri;
  69. }
  70. if (strpos($route, $pub . 'static/') === 0) {
  71. $route = preg_replace('#' . $pub . 'static/#', '', $route, 1);
  72. $_GET['resource'] = $route;
  73. include $magentoPackagePubDir . '/' . $pub . 'static.php';
  74. exit;
  75. }
  76. if (strpos($route, $pub . 'media/') === 0) {
  77. include $magentoPackagePubDir . '/' . $pub . 'get.php';
  78. exit;
  79. }
  80. return false;
  81. }
  82.  
  83. private function checkMageMode($sitePath)
  84. {
  85. if (null !== $this->mageMode) {
  86. // We have already figure out mode, no need to check it again
  87. return;
  88. }
  89. if (!file_exists($sitePath . '/index.php')) {
  90. $this->mageMode = 'production'; // Can't use developer mode without index.php in project root
  91. return;
  92. }
  93. $mageConfig = [];
  94. if (file_exists($sitePath . '/app/etc/env.php')) {
  95. $mageConfig = require $sitePath . '/app/etc/env.php';
  96. }
  97. if (array_key_exists('MAGE_MODE', $mageConfig)) {
  98. $this->mageMode = $mageConfig['MAGE_MODE'];
  99. }
  100. }
  101.  
  102. private function isPubDirectory($sitePath, $route, $pub = '')
  103. {
  104. $sitePath .= '/pub/';
  105. $dirs = glob($sitePath . '*', GLOB_ONLYDIR);
  106. $dirs = str_replace($sitePath, '', $dirs);
  107. foreach ($dirs as $dir) {
  108. if (strpos($route, $pub . $dir . '/') === 0) {
  109. return true;
  110. }
  111. }
  112. return false;
  113. }
  114.  
  115. public function frontControllerPath($sitePath, $siteName, $uri)
  116. {
  117. $this->checkMageMode($sitePath);
  118. if ('developer' === $this->mageMode) {
  119. return $sitePath . '/index.php';
  120. }
  121. return $sitePath . '/pub/index.php';
  122. }
  123. }
  124.  
  125. upstream fastcgi_backend {
  126. server unix:/Users/user/.valet/valet.sock;
  127. }
  128.  
  129. server {
  130. listen 80;
  131. server_name magento-2.dev www.magento-2.dev *.magento-2.dev;
  132. return 301 https://$host$request_uri;
  133. }
  134.  
  135. server {
  136. # SSL Setup
  137. listen 443 ssl http2;
  138. server_name magento-2.dev www.magento-2.dev *.magento-2.dev;
  139. charset utf-8;
  140.  
  141. # SSL Certifcates
  142. ssl_certificate /Users/user/.valet/Certificates/magento-2.dev.crt;
  143. ssl_certificate_key /Users/user/.valet/Certificates/magento-2.dev.key;
  144.  
  145. # Logs
  146. access_log /Users/user/.valet/Log/nginx-access.log;
  147. error_log /Users/user/.valet/Log/nginx-error.log;
  148.  
  149. # Magento Setup
  150. set $MAGE_ROOT /Users/user/www/magento-2;
  151. root $MAGE_ROOT/pub;
  152. index index.php;
  153. autoindex off;
  154. error_page 404 403 = /errors/404.php;
  155. add_header "X-UA-Compatible" "IE=Edge";
  156.  
  157. location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
  158. internal;
  159. alias /;
  160. try_files $uri $uri/;
  161. }
  162.  
  163. location = /favicon.ico {
  164. access_log on;
  165. log_not_found off;
  166. }
  167.  
  168. location = /robots.txt {
  169. access_log off;
  170. log_not_found off;
  171. }
  172.  
  173. # PHP entry point for setup application
  174. location ~* ^/setup($|/) {
  175. root $MAGE_ROOT;
  176. location ~ ^/setup/index.php {
  177. fastcgi_pass fastcgi_backend;
  178.  
  179. fastcgi_param PHP_FLAG "session.auto_start=off n suhosin.session.cryptua=off";
  180. fastcgi_param PHP_VALUE "memory_limit=768M n max_execution_time=600";
  181. fastcgi_read_timeout 600s;
  182. fastcgi_connect_timeout 600s;
  183.  
  184. fastcgi_index index.php;
  185. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  186. include fastcgi_params;
  187. }
  188.  
  189. location ~ ^/setup/(?!pub/). {
  190. deny all;
  191. }
  192.  
  193. location ~ ^/setup/pub/ {
  194. add_header X-Frame-Options "SAMEORIGIN";
  195. }
  196. }
  197.  
  198. # PHP entry point for update application
  199. location ~* ^/update($|/) {
  200. root $MAGE_ROOT;
  201.  
  202. location ~ ^/update/index.php {
  203. fastcgi_split_path_info ^(/update/index.php)(/.+)$;
  204. fastcgi_pass fastcgi_backend;
  205. fastcgi_index index.php;
  206. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  207. fastcgi_param PATH_INFO $fastcgi_path_info;
  208. include fastcgi_params;
  209. }
  210.  
  211. # Deny everything but index.php
  212. location ~ ^/update/(?!pub/). {
  213. deny all;
  214. }
  215.  
  216. location ~ ^/update/pub/ {
  217. add_header X-Frame-Options "SAMEORIGIN";
  218. }
  219. }
  220.  
  221. location / {
  222. try_files $uri $uri/ /index.php$is_args$args;
  223. }
  224.  
  225. location /pub/ {
  226. location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*.xml) {
  227. deny all;
  228. }
  229. alias $MAGE_ROOT/pub/;
  230. add_header X-Frame-Options "SAMEORIGIN";
  231. }
  232.  
  233. location /static/ {
  234. # Uncomment the following line in production mode
  235. # expires max;
  236.  
  237. # Remove signature of the static files that is used to overcome the browser cache
  238. location ~ ^/static/version {
  239. rewrite ^/static/(versiond*/)?(.*)$ /static/$2 last;
  240. }
  241.  
  242. location ~* .(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
  243. add_header Cache-Control "public";
  244. add_header X-Frame-Options "SAMEORIGIN";
  245. expires +1y;
  246.  
  247. if (!-f $request_filename) {
  248. rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
  249. }
  250. }
  251. location ~* .(zip|gz|gzip|bz2|csv|xml)$ {
  252. add_header Cache-Control "no-store";
  253. add_header X-Frame-Options "SAMEORIGIN";
  254. expires off;
  255.  
  256. if (!-f $request_filename) {
  257. rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
  258. }
  259. }
  260. if (!-f $request_filename) {
  261. rewrite ^/static/?(.*)$ /static.php?resource=$1 last;
  262. }
  263. add_header X-Frame-Options "SAMEORIGIN";
  264. }
  265.  
  266. location /media/ {
  267. try_files $uri $uri/ /get.php$is_args$args;
  268.  
  269. location ~ ^/media/theme_customization/.*.xml {
  270. deny all;
  271. }
  272.  
  273. location ~* .(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
  274. add_header Cache-Control "public";
  275. add_header X-Frame-Options "SAMEORIGIN";
  276. expires +1y;
  277. try_files $uri $uri/ /get.php$is_args$args;
  278. }
  279. location ~* .(zip|gz|gzip|bz2|csv|xml)$ {
  280. add_header Cache-Control "no-store";
  281. add_header X-Frame-Options "SAMEORIGIN";
  282. expires off;
  283. try_files $uri $uri/ /get.php$is_args$args;
  284. }
  285. add_header X-Frame-Options "SAMEORIGIN";
  286. }
  287.  
  288. location /media/customer/ {
  289. deny all;
  290. }
  291.  
  292. location /media/downloadable/ {
  293. deny all;
  294. }
  295.  
  296. location /media/import/ {
  297. deny all;
  298. }
  299.  
  300. # PHP entry point for main application
  301. location ~ (index|get|static|report|404|503).php$ {
  302. try_files $uri =404;
  303. fastcgi_pass fastcgi_backend;
  304. fastcgi_buffers 1024 4k;
  305.  
  306. fastcgi_param PHP_FLAG "session.auto_start=off n suhosin.session.cryptua=off";
  307. fastcgi_param PHP_VALUE "memory_limit=768M n max_execution_time=18000";
  308. fastcgi_read_timeout 600s;
  309. fastcgi_connect_timeout 600s;
  310.  
  311. fastcgi_index index.php;
  312. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  313. include fastcgi_params;
  314. }
  315.  
  316. gzip on;
  317. gzip_disable "msie6";
  318.  
  319. gzip_comp_level 6;
  320. gzip_min_length 1100;
  321. gzip_buffers 16 8k;
  322. gzip_proxied any;
  323. gzip_types
  324. text/plain
  325. text/css
  326. text/js
  327. text/xml
  328. text/javascript
  329. application/javascript
  330. application/x-javascript
  331. application/json
  332. application/xml
  333. application/xml+rss
  334. image/svg+xml;
  335. gzip_vary on;
  336.  
  337. # Banned locations (only reached if the earlier PHP entry point regexes don't match)
  338. location ~* (.php$|.htaccess$|.git) {
  339. deny all;
  340. }
  341. }
Add Comment
Please, Sign In to add comment