在阿里云上部署 Laravel 第一课作业
正好趁双十一活动,阿里 ECS 打折优惠挺大的。买了 3 年的入门打算把我的 laravel 作业给交了(域名还没买)。
基于上一篇记录的部署环境:
博客:阿里云 Ubuntu16.04 部署 LNMP 环境
这一篇就记录代码上线了。
首先配置下 nginx 站点。
默认的 nginx 配置文件路径在 /etc/nginx/sites-available/ 下,复制默认配置文件。
cp default sample.com
修改 sample.com 配置
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/sample.com;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
root 目录路径做相对修改,index 中加入 index.php,关联运行的 php 。
sample.com 占用 80 端口,所以把 default 配置里的端口 80 改为 8000;
修改好后在目录 /etc/nginx/sites-enabled/ 下做一个站点配置的软连接
ln -s /etc/nginx/sites-available/sample.com sample.com
重新加载 nginx 配置
nginx -t #检查配置正确性
service nginx reload
创建目录 /var/www/sample.com 及 index.php 抛出 phpinfo();访问 IP 正常输出。
Mysql 服务端已安装好了,但本地想远程连接查看下。但客户端 Navicat 始终连接不上。上网搜,有老哥遇到相同问题,逐步按照老哥的设置连接成功。感谢! https://blog.csdn.net/hohaizx/article/deta...
新环境中缺了好多工具:Git,Composer,NPM 都没有。还好 apt 安装比较方便。
Git 安装
sudo apt install git
Composer 安装
sudo apt install -y composer
Nodejs 安装
sudo apt-get install nodejs
NPM 安装
sudo apt install npm
切换 NPM 源为淘宝源
npm config set registry https://registry.npm.taobao.org
git 拉取代码到 /var/www/sample.com目录。运行了一次
composer install
报错了。缺少 php 扩展,mbstring,dom。
继续装!
sudo apt-get install php-mbstring
sudo apt-get install php7.2-dom
安装好了在跑一次,还是报错还缺少 zip 扩展。
继续
sudo apt-get install php7.2-zip
在运行一次终于正常了。赶紧运行下 php artisan key:generate
成功。
之前的 sample.com Nginx配置目录需要重新修改下,要指定到 public 入口文件夹下 并重新加载 nginx。
root /var/www/sample.com/public
service nginx reload
修改 storage 目录为可写权限。
继续报错
PHP mysql扩展也没有装。
sudo apt-get update
sudo apt install php7.2-mysql
安装顺利,查看 phpinfo()
扩展已经装好。
继续报错
好吧,数据库还没创建。
创建好 sample 数据库,做下数据表迁移:
php artisan migrate
在访问,终于看到久违的界面了。点击相关页面发现 404 了。nginx 配置还有问题。
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri /index.php?$query_string;
}
重启 nginx
,页面可以正常访问了,在测试相关功能,注册用户时发现报错,是注册成功后发送邮件,没有配置 SMTP
,邮件驱动直接改为 log 。
用户注册,发微博功能到正常了,到这算是大功告成了。
附上作业地址:http://47.101.155.173/
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: