1. 使用 Laravel 安装器安装

1.1 命令

  1. ## 先切根目录
  2. ## 1. composer 使用阿里云镜像
  3. composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
  4. ## 2. Composer 安装 Laravel 安装器
  5. composer global require laravel/installer
  6. ## 3. 一定不要忘了添加环境变量,要不找不到。我添加的是用户级别的配置
  7. vim /Users/xs/.bash_profile
  8. ## 添加配置
  9. export PATH = "/Users/xs/.composer/vendor/bin:$PATH"
  10. ## 配置生效
  11. source ~/.bash_profile
  12. ## 4. 任意目录下载
  13. laravel new blog

1.2 截图

环境变量记得加呀
截屏2021-09-26 下午10.27.36.png

下载截图
截屏2021-09-26 下午10.33.57.png


2. 使用 Composer 直接安装


3. 部署

3.1 nginx部署

3.1.1 先配置一下nginx的环境变量 .bash 文件下添加并保存退出

  1. # nginx 环境变量设置
  2. export PATH="/usr/local/nginx/sbin:$PATH"

3.1.2 查看nginx是否配置ok

  1. xs@xsdeMacBook-Pro ~ % nginx -v
  2. Tengine version: Tengine/2.3.3
  3. nginx version: nginx/1.18.0

3.1.3 修改一下nginx的配置文件

  1. worker_processes auto;
  2. error_log logs/error.log;
  3. worker_rlimit_nofile 65535;
  4. events {
  5. worker_connections 65535;
  6. }
  7. # http stream
  8. http {
  9. include mime.types;
  10. default_type application/octet-stream;
  11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  12. '$status $body_bytes_sent "$http_referer" '
  13. '"$http_user_agent" $http_x_forwarded_for $upstream_response_time $upstream_addr $upstream_status ';
  14. tcp_nopush on;
  15. tcp_nodelay on;
  16. gzip on;
  17. gzip_http_version 1.0;
  18. gzip_comp_level 3;
  19. gzip_proxied any;
  20. gzip_types text/plain text/css application/x-javascript text/xml application/x-shockwave-flash;
  21. gzip_min_length 1024;
  22. gzip_buffers 16 16k;
  23. gzip_disable "MSIE [1-6]\.";
  24. keepalive_timeout 60;
  25. server_names_hash_bucket_size 128;
  26. client_header_buffer_size 128k;
  27. large_client_header_buffers 8 128k;
  28. client_max_body_size 64m;
  29. fastcgi_connect_timeout 400;
  30. fastcgi_send_timeout 400;
  31. fastcgi_read_timeout 400;
  32. fastcgi_buffer_size 128k;
  33. fastcgi_buffers 8 128k;
  34. fastcgi_busy_buffers_size 256k;
  35. fastcgi_temp_file_write_size 256k;
  36. fastcgi_intercept_errors on;
  37. proxy_intercept_errors on;
  38. proxy_ignore_client_abort on;
  39. send_timeout 120;
  40. # 单项目配置
  41. include vhosts/*.conf;
  42. }

3.1.4 配置下 localhost

注意将 root 配置在 server 模块中,让每一个localtion去继承,不要配置在 localtion / 中
这里不要写死,所以这么配置比较好:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  1. server {
  2. listen 80;
  3. server_name localhost;
  4. #charset utf-8;
  5. access_log logs/host.access.log main;
  6. root /Users/xs/workPlace/php;
  7. location / {
  8. index index.php index.html index.htm;
  9. }
  10. location ~* \.php$ {
  11. fastcgi_pass 127.0.0.1:9000;
  12. fastcgi_index index.php;
  13. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  14. fastcgi_param PATH_INFO $fastcgi_path_info;
  15. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  16. include fastcgi_params;
  17. }
  18. #error_page 404 /404.html;
  19. error_page 500 502 503 504 /50x.html;
  20. location = /50x.html {
  21. root html;
  22. }
  23. }

/Users/xs/workPlace/php 下的index.php 输入

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>localhost</title>
  5. <style>
  6. body {
  7. margin: 0 auto;
  8. font-family: Tahoma, Verdana, Arial, sans-serif;
  9. text-align: center;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <h1>project: localhost, port: 80</h1>
  15. <hr>
  16. </body>
  17. </html>
  18. <?php
  19. echo phpinfo();

启动nginx 和启动 php-fpm

  1. # 启动nginx
  2. sudo nginx
  3. # 启动php-fpm
  4. sudo php-fpm

浏览器输入 localhost 查看,OK
截屏2021-10-05 下午2.41.21.png

3.1.5 配置下 laravel8的项目

vhost 下新建 blog.conf,写入

  1. server {
  2. listen 80;
  3. server_name xs.blog.com;
  4. root /Users/xs/workPlace/php/blog/public;
  5. access_log logs/host.access.log main;
  6. charset utf-8;
  7. # add_header X-Frame-Options "SAMEORIGIN";
  8. # add_header X-XSS-Protection "1; mode=block";
  9. # add_header X-Content-Type-Options "nosniff";
  10. location / {
  11. index index.php index.html index.htm;
  12. try_files $uri $uri/ /index.php?$query_string;
  13. }
  14. location ~* \.php$ {
  15. # fastcgi_pass 127.0.0.1:9000;
  16. # fastcgi_index index.php;
  17. # fastcgi_split_path_info ^(.+\.php)(/.+)$;
  18. # fastcgi_param PATH_INFO $fastcgi_path_info;
  19. # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  20. # include fastcgi_params;
  21. fastcgi_pass 127.0.0.1:9000;
  22. fastcgi_index index.php;
  23. fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  24. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  25. fastcgi_param PATH_INFO $fastcgi_path_info;
  26. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  27. include fastcgi_params;
  28. }
  29. # error_page 404 /404.html;
  30. # error_page 500 502 503 504 /50x.html;
  31. # location = /50x.html {
  32. # root html;
  33. # }
  34. }server {
  35. listen 80;
  36. server_name xs.blog.com;
  37. root /Users/xs/workPlace/php/blog/public;
  38. access_log logs/host.access.log main;
  39. charset utf-8;
  40. index index.php
  41. add_header X-Frame-Options "SAMEORIGIN";
  42. add_header X-XSS-Protection "1; mode=block";
  43. add_header X-Content-Type-Options "nosniff";
  44. location / {
  45. try_files $uri $uri/ /index.php?$query_string;
  46. }
  47. location ~* \.php$ {
  48. fastcgi_pass 127.0.0.1:9000;
  49. fastcgi_index index.php;
  50. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  51. fastcgi_param PATH_INFO $fastcgi_path_info;
  52. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  53. include fastcgi_params;
  54. }
  55. #error_page 404 /404.html;
  56. error_page 500 502 503 504 /50x.html;
  57. location = /50x.html {
  58. root html;
  59. }
  60. }

重启下nginx

  1. # 重启 nginx
  2. sudo nginx -s reload
  3. # /etc/hosts 添加解析域名
  4. 127.0.0.1 xs.blog.com

浏览器查看下,如果报错 stroge 清下缓存。
截屏2021-10-05 下午5.19.02.png