composer

  1. composer dump-autoload -o

数据库创建迁移

  1. # 创建表
  2. php artisan make:migration create_users_table --create=users
  3. # 修改表
  4. php artisan make:migration add_votes_to_users_table --table=users
  5. # 执行数据迁移
  6. php artisan migrate

代码注解命令

Laravel 代码提示工具 Laravel IDE Helper介绍

  1. php artisan ide-helper:generate - Facades 生成注释
  2. php artisan ide-helper:models -R - 为数据模型生成注释
  3. php artisan ide-helper:meta - 生成 PhpStorm Meta file

目录权限配置

  1. sudo chmod -R 777 storage/
  2. sudo chmod -R 777 public/
  3. sudo chmod -R 777 /alidata/log/

Nginx 配置

  1. log_format dot '$remote_addr - $remote_user [$time_local] "$request" '
  2. '$status $body_bytes_sent "$http_referer" '
  3. '"$http_user_agent" "$http_x_forwarded_for" "$http_xd_token" '
  4. '"$request_body" $request_time $upstream_response_time';
  5. server
  6. {
  7. listen 80;
  8. #listen [::]:80;
  9. server_name dwt.test.xyz ;
  10. index index.html index.htm index.php default.html default.htm default.php;
  11. root /alidata/www/test/public;
  12. # 位置上报打点
  13. location ~ ^/api/reportLocation
  14. {
  15. default_type application/json;
  16. access_log /alidata/log/nginx/test_dot/test_reportLocation.log dot;
  17. return 200 '{"code":200,"msg":"success"}';
  18. }
  19. location / {
  20. try_files $uri $uri/ /index.php?$query_string;
  21. }
  22. #error_page 404 /404.html;
  23. # Deny access to PHP files in specific directory
  24. #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
  25. location ~ [^/]\.php(/|$)
  26. {
  27. try_files $uri =404;
  28. fastcgi_pass unix:/tmp/php-cgi.sock;
  29. fastcgi_index index.php;
  30. include fastcgi.conf;
  31. fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/alidata/www/test/:/tmp/:/proc/";
  32. }
  33. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  34. {
  35. expires 30d;
  36. }
  37. location ~ .*\.(js|css)?$
  38. {
  39. expires 12h;
  40. }
  41. location ~ /.well-known {
  42. allow all;
  43. }
  44. location ~ .*\.(md|sql|log|zip)?$
  45. {
  46. deny all;
  47. }
  48. location ~ /\.
  49. {
  50. deny all;
  51. }
  52. access_log /alidata/log/nginx/dwt.test.xyz.log main;
  53. }

任务调度

  1. * * * * * cd /alidata/www/xdapi.test.cn && php artisan schedule:run >> /alidata/log/schedule/test_schedule.log 2>&1

supervisorctl 相关配置

  1. php artisan queue:work --timeout=30 --sleep=3
  2. # redis队列启动
  3. [program:test_queue]
  4. command = /usr/local/php/bin/php /alidata/www/xdapi.test.cn/artisan queue:work --timeout=30 --sleep=3
  5. process_name = %(program_name)s_%(process_num)s
  6. numprocs = 3
  7. autostart = true
  8. autorestart = true
  9. stdout_logfile = /alidata/log/supervisor/test_queue_out.log
  10. stdout_logfile_maxbytes = 10MB
  11. stderr_logfile = /alidata/log/supervisor/test_queue_err.log
  12. stderr_logfile_maxbytes = 10MB
  13. redirect_stderr=true
  14. # nginx日志处理入队列
  15. [program:test_positionReportLogTail]
  16. command = /usr/local/php/bin/php /alidata/www/xdapi.test.cn/artisan Supervisor:PositionReportLogTail
  17. process_name = %(program_name)s_%(process_num)s
  18. numprocs = 1
  19. autostart = true
  20. autorestart = true
  21. stdout_logfile = /alidata/log/supervisor/test_positionReportLogTail_out.log
  22. stdout_logfile_maxbytes = 10MB
  23. stderr_logfile = /alidata/log/supervisor/test_positionReportLogTail_err.log
  24. stderr_logfile_maxbytes = 10MB
  25. redirect_stderr=true
  26. # 重新启动配置中的所有程序
  27. sudo supervisorctl reload
  28. # 杀掉多余的 tail 进程
  29. sudo killall -q tail
  30. Ubuntu上安装Supervisor,使用如下命令:
  31. sudo apt-get install supervisor
  32. sudo supervisord -c /etc/supervisor/supervisord.conf
  33. sudo supervisorctl -c /etc/supervisor/supervisord.conf
  1. # 重新启动配置中的所有程序
  2. sudo supervisorctl reload
  3. sudo supervisorctl reread
  4. sudo supervisorctl update
  5. sudo supervisorctl start queue_dispose:*
  6. # 终止配置中的所有进程
  7. sudo supervisorctl stop all
  8. # 启动配置中的所有进程
  9. sudo supervisorctl start all
  10. sudo supervisorctl -c /etc/supervisor/supervisord.conf status
  11. sudo supervisorctl -c /etc/supervisor/supervisord.conf stop webWeiXinLoginList:webWeiXinLoginList_0
  1. <a name="lT0kg"></a>
  2. ## 性能优化
  3. 1、开启opcache 性能提高10倍
  4. > 下面参数随着系统配置升级而升级
  5. ```bash
  6. # 开启opcache
  7. cd /home/public/lnmp
  8. sudo ./addons.sh install opcache
  9. # 配置opcache
  10. /usr/local/php/etc/php.ini
  11. # 按照服务器性能配置如下参数
  12. opcache.enable=1 # 启用 OPcache
  13. opcache.memory_consumption=512 # OPcache 的内存空间(M)
  14. opcache.interned_strings_buffer=64 # 实际字符串的空间(单位:MB)
  15. opcache.max_accelerated_files=32531 # 可以缓存多少个脚本,将这个值尽可能设置为与项目包含的脚本数接近或更大
  16. opcache.validate_timestamps=0 # 0表示不自动释放缓存,性能最佳
  17. opcache.save_comments=0 # 在脚本中保留注释,若存在库需要注释,设为1
  18. opcache.fast_shutdown=0 # 快速关闭