composer
composer dump-autoload -o
数据库创建迁移
# 创建表
php artisan make:migration create_users_table --create=users
# 修改表
php artisan make:migration add_votes_to_users_table --table=users
# 执行数据迁移
php artisan migrate
代码注解命令
Laravel 代码提示工具 Laravel IDE Helper介绍
php artisan ide-helper:generate - 为 Facades 生成注释
php artisan ide-helper:models -R - 为数据模型生成注释
php artisan ide-helper:meta - 生成 PhpStorm Meta file
目录权限配置
sudo chmod -R 777 storage/
sudo chmod -R 777 public/
sudo chmod -R 777 /alidata/log/
Nginx 配置
log_format dot '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$http_xd_token" '
'"$request_body" $request_time $upstream_response_time';
server
{
listen 80;
#listen [::]:80;
server_name dwt.test.xyz ;
index index.html index.htm index.php default.html default.htm default.php;
root /alidata/www/test/public;
# 位置上报打点
location ~ ^/api/reportLocation
{
default_type application/json;
access_log /alidata/log/nginx/test_dot/test_reportLocation.log dot;
return 200 '{"code":200,"msg":"success"}';
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/alidata/www/test/:/tmp/:/proc/";
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ .*\.(md|sql|log|zip)?$
{
deny all;
}
location ~ /\.
{
deny all;
}
access_log /alidata/log/nginx/dwt.test.xyz.log main;
}
任务调度
* * * * * cd /alidata/www/xdapi.test.cn && php artisan schedule:run >> /alidata/log/schedule/test_schedule.log 2>&1
supervisorctl 相关配置
php artisan queue:work --timeout=30 --sleep=3
# redis队列启动
[program:test_queue]
command = /usr/local/php/bin/php /alidata/www/xdapi.test.cn/artisan queue:work --timeout=30 --sleep=3
process_name = %(program_name)s_%(process_num)s
numprocs = 3
autostart = true
autorestart = true
stdout_logfile = /alidata/log/supervisor/test_queue_out.log
stdout_logfile_maxbytes = 10MB
stderr_logfile = /alidata/log/supervisor/test_queue_err.log
stderr_logfile_maxbytes = 10MB
redirect_stderr=true
# nginx日志处理入队列
[program:test_positionReportLogTail]
command = /usr/local/php/bin/php /alidata/www/xdapi.test.cn/artisan Supervisor:PositionReportLogTail
process_name = %(program_name)s_%(process_num)s
numprocs = 1
autostart = true
autorestart = true
stdout_logfile = /alidata/log/supervisor/test_positionReportLogTail_out.log
stdout_logfile_maxbytes = 10MB
stderr_logfile = /alidata/log/supervisor/test_positionReportLogTail_err.log
stderr_logfile_maxbytes = 10MB
redirect_stderr=true
# 重新启动配置中的所有程序
sudo supervisorctl reload
# 杀掉多余的 tail 进程
sudo killall -q tail
Ubuntu上安装Supervisor,使用如下命令:
sudo apt-get install supervisor
sudo supervisord -c /etc/supervisor/supervisord.conf
sudo supervisorctl -c /etc/supervisor/supervisord.conf
# 重新启动配置中的所有程序
sudo supervisorctl reload
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start queue_dispose:*
# 终止配置中的所有进程
sudo supervisorctl stop all
# 启动配置中的所有进程
sudo supervisorctl start all
sudo supervisorctl -c /etc/supervisor/supervisord.conf status
sudo supervisorctl -c /etc/supervisor/supervisord.conf stop webWeiXinLoginList:webWeiXinLoginList_0
<a name="lT0kg"></a>
## 性能优化
1、开启opcache 性能提高10倍
> 下面参数随着系统配置升级而升级
```bash
# 开启opcache
cd /home/public/lnmp
sudo ./addons.sh install opcache
# 配置opcache
/usr/local/php/etc/php.ini
# 按照服务器性能配置如下参数
opcache.enable=1 # 启用 OPcache
opcache.memory_consumption=512 # OPcache 的内存空间(M)
opcache.interned_strings_buffer=64 # 实际字符串的空间(单位:MB)
opcache.max_accelerated_files=32531 # 可以缓存多少个脚本,将这个值尽可能设置为与项目包含的脚本数接近或更大
opcache.validate_timestamps=0 # 0表示不自动释放缓存,性能最佳
opcache.save_comments=0 # 在脚本中保留注释,若存在库需要注释,设为1
opcache.fast_shutdown=0 # 快速关闭