目前爲止laravel是5.1版本,須要對php有要求,要php5.59以上php
The Laravel framework has a few system requirements. Of course, all of these requirements are satisfied by the Laravel Homestead virtual machine: * PHP >= 5.5.9 * OpenSSL PHP Extension * PDO PHP Extension * Mbstring PHP Extension * Tokenizer PHP Extension
ubuntu 14.2 64位(開發使用,主要由於php的包版本夠高,知足laravel的要求)html
apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-curl php5-gd php5-json php5-mysqlnd openssl apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql curl 基本上這裏安裝完成,larvel的所需東西都齊全了。
因爲laravel是試用composer來作包依賴管理的,包括laravel的安裝,因此還須要安裝composer https://getcomposer.org/mysql
對於composer其實不須要了解太多,只須要知道如何使用,如何安裝便可
在沒有被牆的狀況下執行這2個命令linux
curl -sS https://getcomposer.org/installer | php #下載composer安裝文件並使用php執行,以便生成一個composer.phar包 mv composer.phar /usr/local/bin/composer # 將生成的composer包放到一個存放命令包的目錄,以便系統的$PATH可以搜索到這個命令,這樣就能夠在命令行直接使用composer命令了。
須要注意composer的執行權限nginx
chmod +x /usr/local/bin/composer
確保有composer這個工具以後,咱們就能夠安裝laravel了laravel
composer global require "laravel/installer=~1.1"
執行這個命令成功後
會在本地目錄生成一個 ~/.composer/vendor/bin 這樣的目錄,laravel命令就是放在了這個目錄裏面,爲了方便咱們使用laravel命令,因此咱們須要將他放到系統的$PATH裏面,由於我是在root執行上述那個命令的,因此個人包生成在了root的目錄sql
export PATH=$PATH:/root/.composer/vendor/bin/
能夠將這個命令寫進去用戶的環境變量配置文件裏面
Ubuntu Linux系統環境變量配置文件:shell
不建議:/etc/profile : 在登陸時,操做系統定製用戶環境時使用的第一個文件 ,此文件爲系統的每一個用戶設置環境信息,當用戶第一次登陸時,該文件被執行。 不建議: /etc /environment : 在登陸時操做系統使用的第二個文件, 系統在讀取你本身的profile前,設置環境文件的環境變量。 建議:~/.profile : 在登陸時用到的第三個文件 是.profile文件,每一個用戶均可使用該文件輸入專用於本身使用的shell信息,當用戶登陸時,該文件僅僅執行一次!默認狀況下,他設置一些環境變量,執行用戶的.bashrc文件。 不建議: /etc/bashrc : 爲每個運行bash shell的用戶執行此文件.當bash shell被打開時,該文件被讀取. 建議~/.bashrc : 該文件包含專用於你的bash shell的bash信息,當登陸時以及每次打開新的shell時,該該文件被讀取。
例如:數據庫
cat ~/.profile
# ~/.profile: executed by Bourne-compatible login shells. if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fi fi mesg n export PATH=$PATH:/root/.composer/vendor/bin/
安裝好laravel後apache
laravel new blog
執行new命令,能夠建立一個app,app其實就是一個網站應用的目錄
這個項目的目錄架構以下:
tree -d -L 1 /root/blog/ /root/blog/ ├── app ├── bootstrap # 須要有apache的寫入權限 ├── config ├── database ├── public #apache的document目錄須要指向它 ├── resources ├── storage # 須要有apache的寫入權限 ├── tests └── vendor
一個全新建立的 Laravel 項目的根目錄中包含如下子目錄:
app 目錄:如你所料,包含應用程序的核心代碼。咱們以後將會很快深刻地探討這個目錄的細節。
bootstrap 目錄:包含的幾個文件用於啓動框架和配置自動加載功能,還有一個 cache 目錄,用於存放框架自動生成的文件,可以加速框架啓動。 config 目錄:顧名思義,包含全部應用程序的配置文件。 database 目錄:包含了數據庫遷移與數據填充文件。若是你不介意的話,也能夠將 SQLite 數據庫文件存放在這個目錄中。 The public directory contains the front controller and your assets (images, JavaScript, CSS, etc.). public 目錄包含前面的控制器和你的資源文件 (圖片、JavaScript、CSS,等等)。 resources 目錄:包含你的視圖、原始的資源文件 (LESS、SASS、CoffeeScript) 和本地化語言文件。 storage 目錄:包含編譯後的 Blade 模板、基於文件的 session、文件緩存和其餘由框架生成的文件。 此目錄下面包含三個子目錄:app、framework 和 logs。app 目錄用戶存放應用程序所用到的任何任何文件;framework 目錄用於存放由框架生成的文件和緩存文件;最後,logs 目錄用於存放應用程序的日誌文件。 tests 目錄用於存放你的自動化測試文件。Laravel 默認自帶了一個 PHPUnit 的實例。 vendor 目錄用於存放 Composer 的依賴包。
laravel會使用mod_rewrite和.htaccess
The framework ships with a public/.htaccess file that is used to allow URLs without index.php. If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.
因此須要須要配置一下,如下包含全部apache用到的配置
ubuntu的apache安裝目錄是
/etc/apache2/
配置文件/etc/apache2/ports.conf,主要是爲了配置監聽端口,默認是80,若是你不配置也能夠,可是80由於太多應用使用了,因此我仍是配置一下,不配置也能夠的。apache2的端口配置改成了在ports.conf裏,我配置的8011
Listen 8011
配置虛擬主機
ls /etc/apache2/sites-enabled/ 000-default.conf
默認有一個demo模板配置文件000-default.conf ,將其複製一份,看成咱們本身使用的虛擬機主機配置文件
cp 000-default.conf testsite.conf
主要配置端口是8011(剛纔配置的監聽端口)和DocumentRoot目錄位置,跟前面所說的一致,是public目錄
cat /etc/apache2/sites-enabled/testsite.conf <VirtualHost *:8011> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com DocumentRoot /var/www/html/laravel-v5.1.4/public #這裏laravel new blog的話會在本地建立目錄,須要將整個blog目錄移到apache的documentroot目錄裏,這樣apache才能識別。 # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>
在/etc/apache2/apache2.conf裏找到
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
將AllowOverride None改成AllowOverride All
由於ubuntu的apache是使用www-data用戶來運行的。
簡單的方法就是將整個larave目錄設置爲www-data用戶所屬
chown -R www-data /var/www/html/laravel-v5.1.4/
這樣就不存在權限不正常的狀況了,不過按照嚴格標準的話,只須要上面提到的3個目錄有寫入權限便可。
service apache2 start
訪問http://XXXX:8011便可看到有larave的字樣出現,表明安裝配置成功。
1.檢查apache2的日誌
/var/logs/apache2/ 的access.log和error.log
2.關閉selinux和iptables
3.這裏我只是列出了安裝的必須項,其餘的都是非必須項目,能夠自行參考官網文檔,剩餘的那些就基本上能夠看得懂了,即便我這樣的人。
參考:
官網
http://laravel.com/
http://laravel.com/docs/5.1
composer官網
https://getcomposer.org/doc/00-intro.md
原文引用:
http://www.godblessyuan.com/2015/07/20/laravel5-1_install_tutorial/