laravel项目部署到LAMP LNMP 环境

2019-01-14 10:10:59   PHP

  php   linux   Laravel  

laravel项目部署到LAMP LNMP 环境

工具

xshell git winscp rz/sz phpstrom samba

1、apache 配置

1、设置访问权限
   Allow from all
2、配置默认显示文件
<IfModule dir_module>
    DirectoryIndex index.html  index.php
</IfModule>
3、加载php模块和解析php文件
LoadModule php7_module        modules/libphp7.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
4、为了隐藏index.php  开启重写模块
AllowOverride   all
5、加载vhost配置文件
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
6、配置虚拟主机
​```
/usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    #ServerAdmin webmaster@dummy-host2.example.com
    #项目入口文件位置
    DocumentRoot "/www/lv/public"
    #项目域名
    ServerName l.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

2、hosts配置

1linux  /etc/hosts
127.0.0.1   l.com
2win   C:\Windows\System32\drivers\etc\hosts
服务器ip   l.com

3、laravel配置

1、配置文件
** 1 Whoops, looks like something went wrong.**
如果页面只有这一行错误,这是因为配置文件没有生成.
laravel的配置文件叫'.env';
cp .env.example .env
2、No supported encrypter found
RuntimeException in EncryptionServiceProvider.php line 29:
No supported encrypter found. The cipher and / or key length are invalid.
原因:laravel需要定义一个key,用于作密钥用,但没生成这个key.
解决:php artsian key:generate 生成key

3、服务器500
修改目录权限
chmod o+rwx storage -R
chmod o+rwx bootstrap/cache -R
chmod o+rwx public -R

4nginx配置

#laravel
......
server {
        listen       80;
        server_name  l.com;
        location / {
            root   /www/lv/public;
            index  index.html index.htm index.php;
        }
        location ~ \.php$ {
            root           /www/lv/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params; 
        }   
    }   
......

虚拟主机配置文件只有首页可以访问解决

location / {
       try_files $uri $uri/ /index.php$is_args$query_string;
 }