短链服务YOURLS部署指南详解

也可以看文档:https://blog.csdn.net/qq_41475058/article/details/105656375?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159756012919724835836781%2522%252C%2522scm%2522%253A%252220140713.130102334%E2%80%A6%2522%257D&request_id=159756012919724835836781&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_v2~rank_v28-4-105656375.pc_first_rank_v2_rank_v28&utm_term=yourls%E5%AE%89%E8%A3%85&spm=1018.2118.3001.4187

一、运行 YOURLS 的最低配置

Version 1.8.2 Requirements · YOURLS/YOURLS Wiki (github.com)

Apache (httpd) version 2.4 or greater, with mod_rewrite enabled
PHP version 7.4 or greater
MySQL version 5.0 or greater
实测 php-8.0、mysql-5.6、nginx-1.20可运行

php安装:https://www.iplayio.cn/post/739811

sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
sudo yum-config-manager --disable ‘remi-php*’
sudo yum-config-manager --enable remi-php80
sudo yum -y install php php-{cli,fpm,mysqlnd,zip,devel,gd,mbstring,curl,xml,pear,bcmath,json}

php --version

启动php-fpm服务

systemctl start php-fpm

systemctl enable php-fpm

systemctl status php-fpm

二、安装 YOURLS

到代码仓库下载压缩包解压或直接GIT拉取代码
https://github.com/YOURLS/YOURLS
将解压后yourls目录下 /user 中 config-sample.php 重命名成 config.php,修改配置
define( ‘YOURLS_DB_USER’, ‘【数据库用户名】’ );

/** MySQL database password */
define( ‘YOURLS_DB_PASS’, ‘【数据库密码】’ );

/** The name of the database for YOURLS */
define( ‘YOURLS_DB_NAME’, ‘【数据库名】’ );

define( ‘YOURLS_SITE’, ‘【域名】https://short.guozh.net’ );
/** https://api.yourls.org/services/cookiekey/1.0/ 生成随机串 */
define( ‘YOURLS_COOKIEKEY’, ‘【自己生成】’ );

$yourls_user_passwords = array(
‘【用户名】’ => ‘【密码】’,
// ‘username2’ => ‘password2’,
// You can have one or more ‘login’=>‘password’ lines
);

添加/修改可选配置,语言包需要去上面 GitHub 仓库下载,然后将两个文件放在 ./user/languages 下

define( ‘YOURLS_HOURS_OFFSET’, +8 );

define( ‘YOURLS_LANG’, ‘zh_CN’ );

服务器配置
详见 Home · YOURLS/YOURLS Wiki (github.com)

.htaccess 文件(必须) 使用niginx需要手动添加编辑,放在yourls根目录下。内容如下:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]

Nginx 配置(必须),看起来像下面这样。注意 location / 必须要加
server {
listen 80;
server_name short-test.[xxxx].com;
rewrite ^(.*)$ https://$host$1 permanent;
}

server {
listen 443 ssl;
server_name short-test.xxxx.com;

ssl on;

ssl_certificate cert/6649241__xxxx.com.pem;
ssl_certificate_key cert/6649241__xxxx.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_prefer_server_ciphers on;

index index.php index.html index.htm default.php default.htm default.html;
root /usr/software/yourls/short-test.xxxx.com;
#access_log logs/host.access.log main;

location / {

index index.html index.htm;

try_files $uri $uri/ /index.html;

try_files $uri u r i / / y o u r l s − l o a d e r . p h p uri/ /yourls-loader.php uri//yourlsloader.phpis_args$args;
}

location ~ ^/.+.php {
fastcgi_index index.php;
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED d o c u m e n t r o o t document_root documentrootfastcgi_path_info;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000; #这个端口是php-fpm服务端口
}

}

配置完后添加站点,访问 https://网站域名/admin(http)进行yourls安装(数据库表初始化等)

三、插件
https://github.com/YOURLS/awesome-yourls

四、其他

还有个小问题,如果就这样安装,默认生成的短链是按数字从 1 开始自增

如果想改成随机一串,需要修改代码,找到 includes–functions.php

搜索 yourls_get_next_decimal,将$id = yourls_get_next_decimal() 改成 $id = time()

2、config.php文件权限改下

cd /usr/software/yourls/short-test.xxxx.com/user

chmod 777 config.php

你可能感兴趣的:(linux运维,apache,linux,php)