- 解决跨域:laravel-cors
- IDE帮助:laravel-ide-helper
- API插件:dingo
参考:七牛:php-sdk
$ composer require qiniu/php-sdk
// routes\api.php
Route::get('/qiniu', 'QiniuController@index');
php artisan make:controller QiuniuController
// QiniuController
use Qiniu\Auth;
class QiniuController extends Controller
{
public function index() {
// 用于签名的公钥和私钥
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
// 初始化签权对象
$auth = new Auth($accessKey, $secretKey);
$bucket = 'Bucket_Name';
// 生成上传Token
$token = $auth->uploadToken($bucket);
return $token;
}
}
参考http://www.cnblogs.com/tambor/archive/2013/04/21/3034017.html
参考:阿里云 ECS 部署:nginx+MySQL+Laravel+PHP7+Redis+Node.js
- Ubuntu 16.04.2 LTS
- Nginx 1.13.0
- PHP 7.0.19
- Mysql 5.7.18
为了终端操作更顺畅,首先选择安装配置on-my-zsh
$ sudo apt install zsh
$ chsh -s $(which zsh)
$ sh -c"$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
添加extract(x解压一切)和z(z到任何去过的目录)插件
$ vim ~/.zshrc
//.zshrc
plugins=(git extract z) //添加插件
iterm2终端本身就是一个完美的ssh工具,原来一直使用SSH Shell,因为它可以记录自己服务器足迹,免密码登陆。 但它快捷键我很不喜欢,主题也不可以定制!那iterm2可不可以免密码ssh呢,当然是可以的(设置完前还是需要输入自己密码的),只要下面几步就可以了,是不是很轻松:
$ ssh-keygen -t rsa //本地生成私钥 公钥
$ scp ~/.ssh/id_rsa.pub root@服务器IP:~/.ssh/ //本地公钥拷贝的服务器端
> cd .ssh
> cat id_rsa.pub >> authorized_keys //公钥添加到服务器认证密钥文件
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
echo "deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx">> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx">> /etc/apt/sources.list
sudo apt update
sudo apt install nginx
vim /etc/nginx/nginx.conf
//修改user
user www-data;
vim /etc/nginx/conf.d/default.conf
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name server_domain_or_IP;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo service nginx restart
sudo apt install python-software-properties software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.0-fpm php7.0-mysql php7.0-common php7.0-curl php7.0-cli php7.0-mcrypt php7.0-mbstring php7.0-dom php7.0-gd
sudo vim /etc/php/7.0/fpm/php.ini
找到cgi.fix_pathinfo选项,去掉注释;,然后将值设置为0 (这个操作是为了避免PHP7的一个漏洞,PS:vim使用“/”进入查找模式)
cgi.fix_pathinfo=0
sudo phpenmod mcrypt
sudo service php7.0-fpm restart
sudo apt install mysql-server-5.7 mysql-client-5.7
开启 公网3306端口
vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 将bind-address = 127.0.0.1注销
授权用户
mysql -u root -p
// 输入密码
// 授权外网王文密码和权限
mysql> grant all privileges on *.* to 'root'@'%' identified by '密码';
mysql> flush privileges;
sudo apt-get install curl
cd ~
wget -c https://getcomposer.org/composer.phar
chmod u+x composer.phar
sudo mv composer.phar /usr/local/bin/composer
sudo apt install zip unzip
sudo apt install git
cd /var
mkdir www
cd www
git clone your-project-git-link
sudo chown -R :www-data /var/www/laravel
sudo chmod -R 775 /var/www/laravel/storage
sudo chmod -R 775 /var/www/memei-api/bootstrap/cache
cd /var/www/laravel
composer install
cp .env.example .env
// 修改.env里的数据库相关配置
// 生成签名
php artisan key:generate
解决办法: 找到安全组 入方向允许 80 3306 TCP连接
DingoApi不会自动加api
中间件组,需要手动添加api
(Laravel Cors 中间件加在里面)
$api->version('v1', ['middleware' => 'api'], function ($api) {
...
}
}
Dingo version 路由 https://laravel-china.org/topics/1463/lumen-version-of-the-problem-using-dingo-api