Ubuntu-16.04 使用LAMP一鍵安裝包搭建laravel項目

1、事前準備(安裝 wget、screen、unzip,創建 screen 會話)
    apt-get -y install wget screen git 
2、git clone 并賦予腳本執行權限
    git clone https://github.com/teddysun/lamp.git
    cd lamp
    chmod +x *.sh
3、開始安裝
    screen -S lamp
    ./lamp.sh

安裝完成時,訪問localhost出現以下頁面,lamp環境就搭建好了:


image.png
4、如何卸載
    ./uninstall.sh
5、程序目錄
    MySQL 安裝目錄: /usr/local/mysql
    MySQL 數據庫目錄:/usr/local/mysql/data(默認,安裝時可更改路徑)
    PHP 安裝目錄: /usr/local/php
    Apache 安裝目錄: /usr/local/apache
6、命令一覽
    MySQL 命令
    /etc/init.d/mysqld (start|stop|restart|status)
    Apache 命令
    /etc/init.d/httpd (start|stop|restart|status)
7、網站根目錄
    默認的網站根目錄: /data/www/default
以上是lamp環境搭建的介紹,接下來就開始搭建laravel項目:
  • lamp add 創建虛擬主機
root@zhangshu-virtual-machine:/# lamp add       /*輸入創建虛擬主機的命令*/
Please enter server names(like this:www.lamp.sh lamp.sh): zhangshu.sz     /*輸入要解析的域名*/
Please enter website root directory(default:/data/www/zhangshu.sz):       /*默認根目錄,直接按回車*/
Do you want to create database?[y/n]:n
Don't create database.
Congratulations. vhost [zhangshu.sz] had created.
Website root directory is: /data/www/zhangshu.sz/
Reloading the apache config file...
Syntax OK
Reload success.
root@zhangshu-virtual-machine:/# 
  • 從coding.net拉代碼到本地
root@zhangshu-virtual-machine:/# cd /data/www/zhangshu.sz/           /*切換到根目錄*/
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# git clone https://git.coding.net/s××××c/n××××c.git .             /*從coding.net克隆項目到本地*/
Cloning into '.'...
Username for 'https://git.coding.net': s××××c           /*輸入coding用戶名*/
Password for 'https://sfabric@git.coding.net':          /*輸入密碼按回車*/
remote: Counting objects: 20520, done.
remote: Compressing objects: 100% (13948/13948), done.
remote: Total 20520 (delta 10829), reused 14356 (delta 6042)
Receiving objects: 100% (20520/20520), 32.40 MiB | 2.00 MiB/s, done.
Resolving deltas: 100% (10829/10829), done.
Checking connectivity... done.
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# 
  • 創建數據庫和導入數據

可以通過在瀏覽器地址欄輸入localhost/phpmyadmin訪問的方式添加數據庫和導入數據,也可以通過命令的方式導入數據:

root@zhangshu-virtual-machine:/# mysql -u root -p    /*root用戶登錄mysql數據庫*/
Enter password:                                      /*輸入密碼后按回車鍵*/
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.7.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 

mysql> create database demo_test;      /*創建一個數據庫demo_test*/
Query OK, 1 row affected (0.00 sec)
mysql> show databases;                 /*顯示所有數據庫*/
+--------------------+
| Database           |
+--------------------+
| information_schema |
| demo_sfabric       |
| demo_test          |
| mysql              |
| performance_schema |
| phpmyadmin         |
| sys                |
+--------------------+
7 rows in set (0.00 sec)
mysql> 

mysql> use demo_test;               /*選擇數據庫*/
Database changed
mysql> set foreign_key_checks=0;    /*設置取消外鍵約束*/
Query OK, 0 rows affected (0.00 sec)
mysql> source ./abc.sql             /*假如abc.sql是我們當前要導入的數據庫文件*/

通過上述的一些步驟,我已經創建好了數據庫。

  • 修改環境配置文件.env,重新配置緩存
.env 文件:
DB_HOST=localhost            /*填寫數據庫主機*/
DB_DATABASE=demo_sfabric     /*填寫數據庫名稱*/
DB_USERNAME=root             /*數據庫用戶名*/
DB_PASSWORD=root             /*數據庫密碼*/
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# cp .env.example .env
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# vi .env

root@zhangshu-virtual-machine:/data/www/zhangshu.sz# php artisan config:clear   /*清除緩存配置文件*/
Configuration cache cleared!
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# php artisan key:generate   /*重新設置key值*/
Application key [base64:7dMhev8iv1cwgkR5iKjQ3g==] set successfully.
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# php artisan config:cache   /*重新緩存配置文件*/
Configuration cache cleared!
Configuration cached successfully!
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# php artisan passport:install  /*安裝passport登錄驗證*/
Encryption keys generated successfully.
Personal access client created successfully.
Client ID: 13
Client Secret: yrhQOXYmd54OLzgPQGEFpZmxZ2WzrDHRlp7NfCe0
Password grant client created successfully.
Client ID: 14
Client Secret: xrhD1OAqDsY14iO0jFg91SrKcvWYcfbDOSKQrOyk
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# 
  • 修改storage目錄的權限,要不然會出現500錯誤,訪問出現空白

這一步非常重要:

root@zhangshu-virtual-machine:/data/www/zhangshu.sz# chmod -R 777 storage/
  • 進入/usr/local/apache/conf/vhost目錄,修改conf 文件
root@zhangshu-virtual-machine:/usr/local/apache/conf/vhost# ls
none.conf  zhangshu.sz.conf
root@zhangshu-virtual-machine:/usr/local/apache/conf/vhost# vi zhangshu.sz.conf   /*編輯conf文件*/
root@zhangshu-virtual-machine:/usr/local/apache/conf/vhost# /etc/init.d/httpd restart   /*編輯完成時,重啟httpd服務*/
root@zhangshu-virtual-machine:/usr/local/apache/conf/vhost# 
/*zhangshu.sz.conf文件*/
 <VirtualHost *:80>
    ServerName zhangshu.sz
    ServerAlias zhangshu.sz
    DocumentRoot /data/www/zhangshu.sz/public     /*在根目錄這里加一個public目錄,其他先不變*/  
    DirectoryIndex index.php index.html index.htm
    <Directory /data/www/zhangshu.sz>
    Options +Includes -Indexes
    AllowOverride All
    Order Deny,Allow
    Require all granted
    php_admin_value open_basedir /data/www/zhangshu.sz:/tmp:/proc
    </Directory>
    ErrorLog  /data/wwwlog/zhangshu.sz/error.log
    TransferLog  /data/wwwlog/zhangshu.sz/access.log
    </VirtualHost>
  • 修改hosts文件
root@zhangshu-virtual-machine:/etc# vi hosts   /*進入/etc 目錄編輯hosts文件*/
root@zhangshu-virtual-machine:/etc# init.d/networking restart   /*重啟網絡*/
[ ok ] Restarting networking (via systemctl): networking.service.
root@zhangshu-virtual-machine:/etc# 
/*hosts文件:*/
127.0.0.1       localhost
127.0.1.1       zhangshu-virtual-machine
127.0.0.1       zhangshu.sz                         /*在hosts文件里面新加這條記錄*/
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
  • 用剛添加的域名訪問

如果訪問出現錯誤或者空白,建議把php.ini文件的錯誤提示打開,方便調試:

首先進入到/usr/local/php/etc目錄,編輯php.ini文件,把錯誤顯示打開:
root@zhangshu-virtual-machine:/usr/local/php/etc# ls  
php.ini
root@zhangshu-virtual-machine:/usr/local/php/etc# vi php.ini
display_errors = On    /*把php.ini里面的錯誤提示打開*/
  • 最后,配置前端登錄passport驗證

不是passport登錄的可以忽略這一步
配置到這一步時,從前端登錄的時候會出現500的錯誤,token請求失敗,現在要做的就是去storage目錄,修改兩個key文件的權限。
通過命令ls -al可以查看到oauth-private.key和oauth-public.key的所有者都是root

root@zhangshu-virtual-machine:/data/www/zhangshu.sz/storage# ls -al
total 40
drwxrwxrwx  7 root   root   4096 9月  21 09:38 .
drwxr-xr-x 13 apache apache 4096 9月  21 09:23 ..
drwxrwxrwx  2 root   root   4096 9月  20 19:10 app
drwxrwxrwx  2 root   root   4096 9月  20 19:10 debugbar
drwxrwxrwx  3 root   root   4096 9月  20 19:10 excel
drwxrwxrwx  5 root   root   4096 9月  20 19:10 framework
-rwxrwxrwx  1 root   root     11 9月  20 19:10 .gitignore
drwxrwxrwx  2 root   root   4096 9月  21 10:08 logs
-rwxrwxrwx  1 root   root   3292 9月  21 09:38 oauth-private.key
-rwxrwxrwx  1 root   root    812 9月  21 09:38 oauth-public.key
root@zhangshu-virtual-machine:/data/www/zhangshu.sz/storage# 

我們需要把這兩個文件的所有者改為apache:

root@zhangshu-virtual-machine:/data/www/zhangshu.sz/storage# chown apache:apache oauth-*.key

修改完成時,我們再次登錄,就一切正常了。

參考資料:https://lamp.sh/install.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,882評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,208評論 3 414
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 175,746評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,666評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,477評論 6 407
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 54,960評論 1 321
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,047評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,200評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,726評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,617評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,807評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,327評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,049評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,425評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,674評論 1 281
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,432評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,769評論 2 372

推薦閱讀更多精彩內容