版本
- centos:7.6
- nginx:1.1
- mysql:5.7
- php:7.2
- laravel:5.5
關閉防火牆
systemctl stop firewalld.service
systemctl disable firewalld.service
配置阿裡yum源
參考
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install wget
mv CentOs-Base.repo CentOs-Base.repo.bak
mv Centos-7.repo CentOs-Base.repo
yum clean all
yum makecache
yum update
php7.2
參考
php7.2源
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php72w-fpm php72w-opcache php72w-cli
// 安裝相應的依賴,請在php7.2源中查找
systemctl start php-fpm.service
systemctl enable php-fpm.service
nginx
參考
yum -y install nginx
systemctl start nginx.service
systemctl enable nginx.service
mysql
參考
wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
yum install -y mysql-community-server
systemctl start mysqld
systemctl enable mysqld
- 檢視資料庫密碼
grep 'temporary password' /var/log/mysqld.log
- 配置utf8
vim /etc/my.cnf
在[mysqld]下面添加,不需要分号
字元集:注意是utf8而不是utf-8!
character-set-server=utf8
- 增加使用者并且可以遠端通路,參考
- php-fpm配置,這裡我設定的為nginx使用者群組,和nginx保持一樣的權限
vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
- 把nginx使用者設定為可登入
vim /etc/passwd // 找到nginx使用者,把 /sbin/nologin 改為 /bin/bash
passwd <user_name(nginx)> // 再輸入新密碼即可
composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ //設定阿裡鏡像
安裝node
參考
- 需要注意,請安裝node較新版本,推舉10以上
安裝yarn
參考
安裝git
yum install git
git config --global user.name 'xxx'
git config --global user.email '[email protected]'
ssh-keygen -t rsa -c '[email protected]'
ssh-add ~/.ssh/id_rsa // 如果報錯,先執行 evel`ssh-agent`,在執行本行指令
cat ~/.ssh/id_rsa.pub
配置vsftpd
yum -y install vsftpd
mkdir data // 在根目錄下建立檔案夾,用于放代碼
//
cd /etc/vsftpd
vim choot_list // 增加 nginx ,然後儲存
vim /etc/selinux/config // 修改為SELINUX=disable,再儲存
//
vim /etc/vsftpd/vsftpd.conf
- 修改對應内容
local_root=/data
use_localtime=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
anonymous_enable=NO
// 在最底部增加
pasv_min_port=61001
pasv_max_port=62000
前端代碼(spa)
- 目錄 /data/html_source/bbs_front
- 用 FileZilla 用之前配置的nginx賬号登入上傳代碼
後端代碼(Laravel)
- 目錄 /data/php_source
- composer create-project laravel/laravel Laravel --prefer-dist “5.5.*”
- 根據報錯,去安裝php相應的依賴
配置nginx
- vim /etc/nginx/nginx.conf,在下面的server做增加如下内容
# 這裡沒有做域名比對,如果做二級域名,需修改為對應的
server_name _;
# 這裡為前端項目目錄
root /data/html_source/bbs-front;
# 這裡為前端單頁應用上傳位址
location / {
try_files $uri $uri/ /index.html;
root /data/html_source/bbs-front;
index index.html index.htm;
}
# 這裡是接口位址
location /api {
try_files $uri $uri/ /index.php?$query_string;
}
# 這裡配置php相關,root為laravel項目路徑
location ~ \.php$ {
root /data/php_source/Laravel/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# error_page 404 /404.html;
# location = /40x.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
注意的地方
- /data ,使用者和使用者組,要設定為 nginx,并且要有讀寫權限
- 以上服務更改後,都需要重新開機,如:systemctl restart nginx
- 還有端口相關的配置,自行百度