1. 初始化项目 - nosun/laravel_blog GitHub Wiki
lnmp 环境
项目使用lnmp环境进行开发,官方推荐使用集成好的homestead,都可以,因为这部分内容是开发的基础工作,这里简略带过。
安装composer
下载composer
curl -sS https://getcomposer.org/installer | php
将composer.phar 移动到 /usr/local/bin/下,供全局调用。
mv composer.phar /usr/local/bin/composer
全局安装 laravel
composer global require "laravel/installer"
将laravel 设置为环境变量
vi ~/.profile
在path处增加:
~/.composer/vendor/bin:$PATH
结果大概是这样的:
PATH=/usr/local/ssdb:~/.composer/vendor/bin:$PATH
export PATH
使之生效:
source ~/.profile
安装laravel
前往web目录,进行安装
cd /www
laravel new laravel.blog
设置项目
权限设置
chown -R nosun.www-data laravel.blog
chmod -R 777 laravel.blog/storage
chmod -R 777 laravel.blog/bootstrap/cache
生成app key
laravel 5.5 已经自动生成了key, 无需下面的步骤
If the application key is not set, your user sessions and other encrypted data will not be secure!
php artisan key:generate
修改配置文件
配置文件位于 /config/app.php,最佳的方式是配置.env
配置nginx
配置nginx
server {
listen 80;
server_name laravel.blog;
index index.html index.htm index.php;
root /data/www/laravel.blog/public;
rewrite_log on;
error_log /data/logs/nginx/lwrok_nginx_error.log info;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php($|/) {
fastcgi_pass unix:/run/php/php5.6-fpm.sock;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
修改hosts表
vi /etc/hosts
add 127.0.0.1 laravel.blog
启动服务
service nginx reload
访问站点
访问 http://laravel.blog 应该能看到laravel默认的首页了。
建立git
git init
git remote add