安装Composer PHP包管理工具
官网: ttps://getcomposer.org packagist.org
中文网: http://www.phpcomposer.com
建议使用国内用户使用 中文网镜像, 具体参考: http://pkg.phpcomposer.com/ (喷血推荐)
安装
$ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer
推荐全局配置:
composer config -g repositories.packagist composer http://packagist.phpcomposer.com
安装Laravel
官网: www.aravel.com
中文网: http://www.golaravel.com/ 做得还不错, 提供离线包, 国内用户的福利
参考官网安装教程: http://laravel.com/docs/5.1
composer global require "laravel/installer=~1.1"
添加bin路径到PATH中: ~/.composer/vendor/bin
laravel new blog
配置
配置时区和语言 blog/config/app.php
修改对应的值: 'timezone' => 'Asia/Shanghai' 'locale' => 'zh'
配置数据库链接, 以下方法二选一
方法1: 根目录.env文件中配置 (推荐)
DB_HOST=localhost DB_DATABASE=database DB_USERNAME=name DB_PASSWORD=pw
方法2:config/database.php中配置
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],
配置目录权限:
将一下目录的权限修改为服务器可写权限
假设是apache服务器的用户名为 www-data, 组名为 www-data
sudo chown www-data:www-data -R storage bootstrap/cache
创建虚拟主机
ubuntu apache环境
添加虚拟主机配置文件
sudo vim /etc/apache2/sites-available/test.conf
内容如下, 相关参数自行修改
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName www.test.com #ServerName www.123.com ServerAlias test.com DocumentRoot app/public <Directory app/public> Options Indexes FollowSymLinks Require all granted AllowOverride All </Directory> ErrorLog /var/log/apache2/test_error.log CustomLog /var/log/apache2/test_access.log combined </VirtualHost>
保存后,启用该虚拟主机配置, 重启apache生效
sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/ sudo service apache2 restart
============== 重点配置: Route 不能正常工作 =================
需检查apache是否启用rewrite模块, 这是因为laravel框架都是有index.php作为路由入口, 需要让public/.haccess文件生效
ubuntu 14.04环境apache启用rewrite模块, 以下两个步骤
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/
检查虚拟主机的配置, 加入 AllowOverride All
<Directory app/public> Options Indexes FollowSymLinks Require all granted AllowOverride All </Directory>
重启apache
sudo service apache2 restart
===================================================================
Laravel 5.0 安装错误
composer create-project laravel/laravel laravel5 5.0.22
若遇到如下错误:
Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for laravel/framework v5.0.16 -> satisfiable by laravel/framework[v5.0.16]. - laravel/framework v5.0.16 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
解决方案:
vim /etc/php5/cli/php.ini
文件末尾追加一句
extension=mcrypt.so
删除原来的文件夹, 重新安装即可
======================== 403 Forbid ==================
在apache中设置过vhosts之后,如果路径指向的是/home/ubuntu/website的话,需要给 ubuntu 文件夹增加可执行权限,不然在apache的error log中会出现 because search permissions are missing on a component of the path。 将laravel的storage文件夹设置权限为777。