我在Laravel中有一个任务是在存储文件夹中创建一个nginx.conf文件,并使用nginx命令测试该文件。我在存储文件夹中创建了一个配置文件'nginx.conf',我尝试在nginx命令,shell_exec()或exec()的帮助下进行测试,但是我收到错误'Permission denied'。
这是我测试nginx.conf文件https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/#
后面的命令行NginxController.php
public function nginxConfig(){
$path = storage_path('app/nginx/nginx.conf'); //"/home/vagrant/Code/Laravel/storage/app/nginx.conf"
/*$change_mode = exec('chmod -R 755 /home/vagrant/Code/Laravel/storage/app/nginx 2>&1');*/
$config = exec('/home/vagrant/Code/Laravel/storage/app/nginx -t 2>&1');
dd($config);
/*$restart_config = shell_exec('/etc/init.d/nginx restart');
$reload = shell_exec('nginx -s reload');*/
}
消息
"sh: 1: /home/vagrant/Code/Laravel/storage/app/nginx: Permission denied"
nginx.conf
server {
listen 443 ssl http2
root /var/www/google.de/beta.google.de
index index.html index.htm index.php
server_name beta.google.de
include var/www/includes/contao
include var/www/includes/shopware
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
}
答案 0 :(得分:0)
很遗憾,如果没有sudo
,你就无法做到这一点,所以你可以尝试安装OpenSSH Server和Laravel's Envoy将你的私有ssh密钥添加到root的授权密钥,然后尝试在<具有root访问权限的strong> Envoy 。 Envoy.blade.php
将如下所示:
@servers(['nginx' => isset($server) ? $server : 'root@localhost'])
@task('testconf', ['on' => 'nginx'])
{-- here you do what you whant to check --}
@endtask
然后在PHP中,你只需添加shell
执行envoy命令,如:
envoy run testconf