搭一個自己的視頻網站,從此看電影再也不用開會員啦
0. 說明
只做記錄
系統centos7.6
網上都是用寶塔自動建站,自己有現成的lnmp架構和服務器,就直接在nginx裏添加一個新站點的server配置好即可,域名自行在阿里雲或者騰訊雲購買備案,域名備案之後還需要配置解析記錄,如果要配置SSL加密證書,可以去騰訊雲免費申請一年的證書來進行配置。
1. php、mysql、nginx下載
#主機使用的阿里雲的yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#下載php的源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum clean all && yum makecache
#安裝php
yum install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb -y
#安裝數據庫,這裏直接用的mariadb
yum install mariadb-server -y
#下載nginx
yum install nginx -y
#啓動nginx、mariadb
systemctl restart nginx && systemctl enable nginx
systemctl start mariadb.service && systemctl enable mariadb.service
#爲數據庫設置密碼
mysqladmin -uroot -p password 123456
2. 修改LNMP環境配置
2.1 Nginx與php的連接
#修改/etc/php-fpm.d/www.conf中的user與group爲nginx
[root@lcx01 ~]# egrep -n '^user|^group' /etc/php-fpm.d/www.conf
8:user = nginx
10:group = nginx
#啓動php-fpm服務並檢測端口
systemctl restart php-fpm.service && systemctl enable php-fpm.service
ss -lntup|grep 9000
ps -ef |grep php
#切換到nginx默認站點目錄下添加php測試文件
cd /usr/share/nginx/html
vim info.php
<?php
phpinfo();
?>
EOF
瀏覽器查看網頁http://ip地址/info.php
出現此頁面則連接成功
2.2 php與mysql的連接
#切換到nginx默認站點目錄下創建mysqli.php測試文件
cd /usr/share/nginx/html
vim mysql.php
<?php
$servername = "localhost";
$username = "root";
$password = "password";
// 創建連接
$conn = mysqli_connect($servername, $username, $password);
// 檢測連接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "php連接MySQL數據庫成功";
?>
瀏覽器查看網頁http://ip地址/mysql.php
出現此頁面則連接成功
3. 解壓cms代碼包到站點目錄下
#下載cms代碼包到站點目錄下解壓
wget http://www.maccmsv10.com/static/maccms10.zip
mkdir -p /usr/share/nginx/html/maccms/
unzip -d /usr/share/nginx/html/maccms/ maccms10.zip
#修改站點目錄權限(如果後臺設置有報錯則需要將maccms站點下全部添加讀寫權限)
cd /usr/share/nginx/html/maccms/
chmod -R 777 ./runtime/
chmod -R 777 ./application/
chmod -R 777 ./upload/
4. 創建數據庫和用戶
mysql -uroot -p
create database maccms;
grant all on maccms.* to 'maccms'@'%' identified by 'password';
grant all on maccms.* to 'maccms'@'localhost' identified by 'password';
5. 配置nginx文件
#註釋默認配置文件的server模塊並打開include指向文件功能
[root@lcx01 ~]# cat /etc/nginx/nginx.conf |egrep -v '^$|#'
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf; #解除註釋
}
#添加maccms.conf文件
[root@lcx01 ~]# cd /etc/nginx/conf.d/
[root@lcx01 conf.d]# cat maccms.conf
[root@centos ~]# cat /etc/nginx/conf.d/maccms.conf
server {
listen 80;
server_name www.linuxcx.cn; #域名或ip
access_log /var/log/nginx/access_blog.log main;
root /usr/share/nginx/html/maccms10; #站點目錄
#僞靜態規則
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^/admin.php(.*)$ /admin.php?s=$1 last;
rewrite ^/api.php(.*)$ /api.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
location / {
index index.php index.html index.htm;
}
location ~* \.(php|php5)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#nginx檢測文件正常後重啓服務
[root@lcx01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
#平滑重啓nginx
systemctl reload nginx
6. cms站點的配置修改
關閉驗證碼登錄
#登錄後臺時輸入驗證碼會一直提示輸入錯誤,所以關閉即可
sed -i "s#'admin_login_verify' => '1',#'admin_login_verify' => '0',#g" application/extra/maccms.php
上傳下載文件大小限制
#需要重啓php-fpm
[root@centos maccms10]# egrep 'upload_max_filesize|post_max_size' /etc/php.ini
post_max_size = 10M
upload_max_filesize = 10M
systemctl restart php-fpm.service
7.安裝後登錄後臺進行採集視頻
推薦採集資源網站:http://www.zuidazy4.com/
MaccmsV10的採集配置說明:http://www.zuidazy3.net/help/#MacCms10
後臺默認登錄地址(建議修改以防被攻擊): http://ip/admin.php
8. 站點目錄說明
│─application //應用目錄
│ │─admin //後臺模塊
│ │─api //api模塊
│ │─common //公共模塊
│ │─extra //配置文件
│ │─index //前臺模塊
│ │─install //安裝模塊
│─extend //擴展目錄
│─runtime //緩存目錄
│─static //靜態文件目錄
│─template //前臺模板目錄
│─thinkphp //tp目錄
│─upload //附件目錄
│─vendor //第三發庫目錄
└─index.php //入口文件