安裝Composer PHP包管理工具php
官網: ttps://getcomposer.org packagist.orgjava
中文網: http://www.phpcomposer.commysql
建議使用國內用戶使用 中文網鏡像, 具體參考: http://pkg.phpcomposer.com/ (噴血推薦)laravel
安裝
web
$ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer
推薦全局配置:
sql
composer config -g repositories.packagist composer http://packagist.phpcomposer.comshell
安裝Laravel數據庫
官網: www.aravel.comapache
中文網: http://www.golaravel.com/ 作得還不錯, 提供離線包, 國內用戶的福利bootstrap
參考官網安裝教程: 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 和 bootstrap/cache文件夾設置權限爲777 或全部者www-data。