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阅读 156,265评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,274评论 1 288
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,087评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,479评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,782评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,218评论 1 207
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,594评论 2 309
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,316评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 33,955评论 1 237
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,274评论 2 240
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,803评论 1 255
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,177评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,732评论 3 229
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,953评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,687评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,263评论 2 267
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,189评论 2 258

推荐阅读更多精彩内容