1战秋、事前準(zhǔn)備(安裝 wget、screen讨韭、unzip脂信,創(chuàng)建 screen 會(huì)話)
apt-get -y install wget screen git
2、git clone 并賦予腳本執(zhí)行權(quán)限
git clone https://github.com/teddysun/lamp.git
cd lamp
chmod +x *.sh
3透硝、開(kāi)始安裝
screen -S lamp
./lamp.sh
安裝完成時(shí)狰闪,訪問(wèn)localhost出現(xiàn)以下頁(yè)面,lamp環(huán)境就搭建好了:
4濒生、如何卸載
./uninstall.sh
5埋泵、程序目錄
MySQL 安裝目錄: /usr/local/mysql
MySQL 數(shù)據(jù)庫(kù)目錄:/usr/local/mysql/data(默認(rèn),安裝時(shí)可更改路徑)
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丽声、網(wǎng)站根目錄
默認(rèn)的網(wǎng)站根目錄: /data/www/default
以上是lamp環(huán)境搭建的介紹,接下來(lái)就開(kāi)始搭建laravel項(xiàng)目:
-
lamp add 創(chuàng)建虛擬主機(jī)
root@zhangshu-virtual-machine:/# lamp add /*輸入創(chuàng)建虛擬主機(jī)的命令*/
Please enter server names(like this:www.lamp.sh lamp.sh): zhangshu.sz /*輸入要解析的域名*/
Please enter website root directory(default:/data/www/zhangshu.sz): /*默認(rèn)根目錄觉义,直接按回車*/
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克隆項(xiàng)目到本地*/
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#
-
創(chuàng)建數(shù)據(jù)庫(kù)和導(dǎo)入數(shù)據(jù)
可以通過(guò)在瀏覽器地址欄輸入localhost/phpmyadmin訪問(wèn)的方式添加數(shù)據(jù)庫(kù)和導(dǎo)入數(shù)據(jù)恒序,也可以通過(guò)命令的方式導(dǎo)入數(shù)據(jù):
root@zhangshu-virtual-machine:/# mysql -u root -p /*root用戶登錄mysql數(shù)據(jù)庫(kù)*/
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; /*創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)demo_test*/
Query OK, 1 row affected (0.00 sec)
mysql> show databases; /*顯示所有數(shù)據(jù)庫(kù)*/
+--------------------+
| Database |
+--------------------+
| information_schema |
| demo_sfabric |
| demo_test |
| mysql |
| performance_schema |
| phpmyadmin |
| sys |
+--------------------+
7 rows in set (0.00 sec)
mysql>
mysql> use demo_test; /*選擇數(shù)據(jù)庫(kù)*/
Database changed
mysql> set foreign_key_checks=0; /*設(shè)置取消外鍵約束*/
Query OK, 0 rows affected (0.00 sec)
mysql> source ./abc.sql /*假如abc.sql是我們當(dāng)前要導(dǎo)入的數(shù)據(jù)庫(kù)文件*/
通過(guò)上述的一些步驟,我已經(jīng)創(chuàng)建好了數(shù)據(jù)庫(kù)谁撼。
-
修改環(huán)境配置文件.env歧胁,重新配置緩存
.env 文件:
DB_HOST=localhost /*填寫數(shù)據(jù)庫(kù)主機(jī)*/
DB_DATABASE=demo_sfabric /*填寫數(shù)據(jù)庫(kù)名稱*/
DB_USERNAME=root /*數(shù)據(jù)庫(kù)用戶名*/
DB_PASSWORD=root /*數(shù)據(jù)庫(kù)密碼*/
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 /*重新設(shè)置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登錄驗(yàn)證*/
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目錄的權(quán)限滋饲,要不然會(huì)出現(xiàn)500錯(cuò)誤,訪問(wèn)出現(xiàn)空白
這一步非常重要:
root@zhangshu-virtual-machine:/data/www/zhangshu.sz# chmod -R 777 storage/
-
進(jìn)入/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 /*編輯完成時(shí)屠缭,重啟httpd服務(wù)*/
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 /*在根目錄這里加一個(gè)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 /*進(jìn)入/etc 目錄編輯hosts文件*/
root@zhangshu-virtual-machine:/etc# init.d/networking restart /*重啟網(wǎng)絡(luò)*/
[ 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
-
用剛添加的域名訪問(wèn)
如果訪問(wèn)出現(xiàn)錯(cuò)誤或者空白崭参,建議把php.ini文件的錯(cuò)誤提示打開(kāi)呵曹,方便調(diào)試:
首先進(jìn)入到/usr/local/php/etc目錄,編輯php.ini文件何暮,把錯(cuò)誤顯示打開(kāi):
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里面的錯(cuò)誤提示打開(kāi)*/
-
最后奄喂,配置前端登錄passport驗(yàn)證
不是passport登錄的可以忽略這一步
配置到這一步時(shí),從前端登錄的時(shí)候會(huì)出現(xiàn)500的錯(cuò)誤海洼,token請(qǐng)求失敗跨新,現(xiàn)在要做的就是去storage目錄,修改兩個(gè)key文件的權(quán)限坏逢。
通過(guò)命令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#
我們需要把這兩個(gè)文件的所有者改為apache:
root@zhangshu-virtual-machine:/data/www/zhangshu.sz/storage# chown apache:apache oauth-*.key
修改完成時(shí)域帐,我們?cè)俅蔚卿洠鸵磺姓A恕?/p>