前期准备
更新 apt-get
sudo apt-get update
安装常用工具
sudo apt-get install -y curl vim
sudo apt-get install git
sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring
// 安装必要/可选的包
sudo apt-get install zip unzip php-zip
解决有可能存在的语言问题
apt-get install -y language-pack-en-base
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
安装Nginx
安装
sudo apt-get install -y nginx
配置文件位置
> /etc/nginx/nginx.conf
> /etc/nginx/conf.d/*.conf
默认主目录
> /usr/share/nginx/html/
管理nginx服务
sudo service nginx start // 启动
sudo service nginx stop // 停止
sudo service nginx restart // 重启
测试
curl localhost
安装 PHP7
# 添加php的仓库
sudo apt-get install -y software-properties-common
#> 中途按下回车
sudo add-apt-repository ppa:ondrej/php
# 安装php7.0,可以选择指定版本,我看了下5.4以上的有,安装前先使用apt-cache search php7.0类似命令搜索下
sudo apt-get update
中途报错
1. W: GPG error: http://ppa.launchpad.net trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6C
# 注意后面的KEY要对应
gpg --keyserver keyserver.ubuntu.com --recv 4F4EA0AAE5267A6C
gpg --export --armor 4F4EA0AAE5267A6C > key.asc
cat key.asc | sudo apt-key add -
sudo apt-get install -y php7.0 php7.0-mysql php7.0-fpm php7.0-curl php7.0-xml php7.0-mcrypt php7.0-json php7.0-gd php7.0-mbstring php7.0-zip php-mongodb php-memcached php-redis
安装 php7.1
sudo apt-get install software-properties-common
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install php7.1
sudo apt-get -y install php7.1-mysql
sudo apt-get install php7.1-fpm
apt-get install php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring
# 测试 (如果有结果,则表示安装成功)
php -v
配置php.ini
vim /etc/php/7.1/fpm/php.ini
将cgi.fix_pathinfo=1这一行去掉注释,将1改为0
> / 是vi查找的命令
配置php-fpm
sudo vim /etc/php/7.1/fpm/pool.d/www.conf
修改
listen = /var/run//php7.1-fpm.sock
配置nginx
vim /etc/nginx/sites-enabled/default
1. 将`index index.html index.htm;`改成`index index.php index.html index.htm;`
2. 在`service`里面,`location /{}`下面增加以下配置
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3. 修改nginx.conf文件
vi /etc/nginx/nginx.conf
# 在 http{ 括号结束之前加上以下代码
include /apps/vhost/*.conf;
创建目录
# 创建项目目录,并给权限
mkdir /apps
chmod -R 777 /apps/
# 创建vhost目录,并给权限
mkdir /apps/vhost
chmod -R 777 /apps/vhost
创建项目 vhost(nginx) 配置文件
vi /apps/vhost/demo.cc
.conf 模版
server {
listen 80;
root /apps/demo/public;
index index.php index.html index.htm;
server_name demo.com demo.cc;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
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;
}
}
重启
启动php-fpm
service php7.1-fpm start
重启 Nginx ,检测配置是否成功
# service nginx stop
# service nginx start
service nginx reload
安装MySQL
安装过程中会提示输入密码及确认密码,输入即可
apt-get install -y mysql-server-5.6
测试
输入密码后进入到mysql表示安装成功
退出
service mysql start
mysql -uroot -p
exit
配置composer
安装composer
sudo curl -sS https://getcomposer.org/installer | sudo php -d detect_unicode=Off
更改文件权限
sudo chmod a+x composer.phar
切换到全局安装文件夹
sudo mv composer.phar /usr/local/bin/composer
更新版本
sudo composer self-update
将 Composer 源更换为国内
composer config -g repo.packagist composer https://packagist.phpcomposer.com
本地生成密钥,配置到 coding 项目中
// 47.92.38.123 是服务器密钥
cd ~
ssh-keygen -t rsa -C "47.92.38.123" //一直按回车
cd ~/.ssh/
cat id_rsa.pub >> authorized_keys
cat id_rsa.pub
git 下载项目
cd /apps/
git@git.coding.net:demo/d.git
部署laravel项目
sudo composer install //加载项目依赖
sudo chmod -R 777 storage //给项目权限
sudo chmod -R 777 bootstrap/cache
cp .env.example .env //配置项
php artisan key:generate //配置项目密钥
git config core.filemode false //设置忽略 给文件权限造成的Git版本冲突