在搭建和运行laravel项目之前你必须要有lnmp的环境,其中我这里使用的linux是redhat的,在我的博客中有介绍如何搭建lnmp,大家可以去看一下。
首先在有了lnmp环境的条件下,大家先打开自己的nginx服务器,首先需要在linux中安装composer
- curl -sS https://getcomposer.org/installer | php
- mv composer.phar /usr/local/bin/composer
- 安装成功之后运行composer -v可以显示你的composer的版本,当你输入composer的时候会显示如下的composer字样
-
-
-
-
- 其中这里的composer使用的是默认安装,就表示你安装composer成功。
-
- 安装完composer之后,就需要配置nginx来让你的lnmp服务器上可以运行laravel项目。
-
-
-
- 首先打开你的nginx所在的目录,如果大家是和照这我的lnmp环境安装的,那就在/usr/local/nginx/这个目录,大家输入ls就可以看见你的目录中有一个conf的文件夹,打开conf,然后使用vi打开nginx.conf这个文件。然后对着干文件进行编辑,把他的server部分改成下面这样。
-
-
-
-
其中root是你的laravel项目所在的地方,但你这里放置的地方必须要你的nginx可以识别的地方。其中server { listen 80; server_name localhost; location / { root /usr/share/nginx/html/laravel/public; try_files $uri $uri/ /index.php?$query_string; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html/laravel/public; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html/laravel/public; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /usr/share/nginx/html/laravel/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
try_files $uri $uri/ /index.php?$query_string;这一句必须添加在你的nginx的server中添加然后保存你所修改的就可以了。
-
其中安装laravel项目必须要安装一些依赖,这里使用yum进行安装,
-
yum install php-mysql php-mcrypt php-mbstring php-tokenizer php-openssl
-
然后进入你的laravel项目中改变storage和vendor的权限为读和写。
-
chmod -R 766 storage
-
chmod -R 766 vendor
-
然后就可以了,现在就可以安装laravel项目了,你可以上传你之前写好了的laravel项目,然后在浏览器中输入127.0.0.1就可以访问你的项目了。
-
其中如果运行时出了一下的错误,
`Warning: require(/http/www.mywakavLee.cn/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /http/www.mywakavLee.cn/bootstrap/autoload.php on line 17
Fatal error: require(): Failed opening required ‘/http/www.mywakavLee.cn/bootstrap/../vendor/autoload.php’ (include_path=’.:’) in /http/www.mywakavLee.cn/bootstrap/autoload.php on line 17`
-
那就是你的网站根目录下缺少vendor这个存放laraver依赖包的目录
-
使用
composer install
进行安装(没有安装过的情况下,以前安装过的话使用:composer update
) -
如果你之前没有没有安装过,直接使用了
composer update
命令,就会报错。 -
然而这里的这两个方法都需要你的php版本大于5.4不然会失败的。如果安装成功,那就可以运行你的laravel项目了。
-
-
-
-
-
-