1. 使用 Laravel 安装器安装
1.1 命令
## 先切根目录## 1. composer 使用阿里云镜像composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/## 2. Composer 安装 Laravel 安装器composer global require laravel/installer## 3. 一定不要忘了添加环境变量,要不找不到。我添加的是用户级别的配置vim /Users/xs/.bash_profile## 添加配置export PATH = "/Users/xs/.composer/vendor/bin:$PATH"## 配置生效source ~/.bash_profile## 4. 任意目录下载laravel new blog
1.2 截图
环境变量记得加呀
下载截图
2. 使用 Composer 直接安装
3. 部署
3.1 nginx部署
3.1.1 先配置一下nginx的环境变量 .bash 文件下添加并保存退出
# nginx 环境变量设置export PATH="/usr/local/nginx/sbin:$PATH"
3.1.2 查看nginx是否配置ok
xs@xsdeMacBook-Pro ~ % nginx -vTengine version: Tengine/2.3.3nginx version: nginx/1.18.0
3.1.3 修改一下nginx的配置文件
worker_processes auto;error_log logs/error.log;worker_rlimit_nofile 65535;events {worker_connections 65535;}# http streamhttp {include mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" $http_x_forwarded_for $upstream_response_time $upstream_addr $upstream_status ';tcp_nopush on;tcp_nodelay on;gzip on;gzip_http_version 1.0;gzip_comp_level 3;gzip_proxied any;gzip_types text/plain text/css application/x-javascript text/xml application/x-shockwave-flash;gzip_min_length 1024;gzip_buffers 16 16k;gzip_disable "MSIE [1-6]\.";keepalive_timeout 60;server_names_hash_bucket_size 128;client_header_buffer_size 128k;large_client_header_buffers 8 128k;client_max_body_size 64m;fastcgi_connect_timeout 400;fastcgi_send_timeout 400;fastcgi_read_timeout 400;fastcgi_buffer_size 128k;fastcgi_buffers 8 128k;fastcgi_busy_buffers_size 256k;fastcgi_temp_file_write_size 256k;fastcgi_intercept_errors on;proxy_intercept_errors on;proxy_ignore_client_abort on;send_timeout 120;# 单项目配置include vhosts/*.conf;}
3.1.4 配置下 localhost
注意将 root 配置在 server 模块中,让每一个localtion去继承,不要配置在 localtion / 中
这里不要写死,所以这么配置比较好:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
server {listen 80;server_name localhost;#charset utf-8;access_log logs/host.access.log main;root /Users/xs/workPlace/php;location / {index index.php index.html index.htm;}location ~* \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}#error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
/Users/xs/workPlace/php 下的index.php 输入
<!DOCTYPE html><html lang="en"><head><title>localhost</title><style>body {margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;text-align: center;}</style></head><body><h1>project: localhost, port: 80</h1><hr></body></html><?phpecho phpinfo();
启动nginx 和启动 php-fpm
# 启动nginxsudo nginx# 启动php-fpmsudo php-fpm
浏览器输入 localhost 查看,OK
3.1.5 配置下 laravel8的项目
vhost 下新建 blog.conf,写入
server {listen 80;server_name xs.blog.com;root /Users/xs/workPlace/php/blog/public;access_log logs/host.access.log main;charset utf-8;# add_header X-Frame-Options "SAMEORIGIN";# add_header X-XSS-Protection "1; mode=block";# add_header X-Content-Type-Options "nosniff";location / {index index.php index.html index.htm;try_files $uri $uri/ /index.php?$query_string;}location ~* \.php$ {# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_split_path_info ^(.+\.php)(/.+)$;# fastcgi_param PATH_INFO $fastcgi_path_info;# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;# include fastcgi_params;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;include fastcgi_params;}# error_page 404 /404.html;# error_page 500 502 503 504 /50x.html;# location = /50x.html {# root html;# }}server {listen 80;server_name xs.blog.com;root /Users/xs/workPlace/php/blog/public;access_log logs/host.access.log main;charset utf-8;index index.phpadd_header X-Frame-Options "SAMEORIGIN";add_header X-XSS-Protection "1; mode=block";add_header X-Content-Type-Options "nosniff";location / {try_files $uri $uri/ /index.php?$query_string;}location ~* \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}#error_page 404 /404.html;error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}
重启下nginx
# 重启 nginxsudo nginx -s reload# /etc/hosts 添加解析域名127.0.0.1 xs.blog.com
浏览器查看下,如果报错 stroge 清下缓存。
