YOURLS短网址

一、说明

之前用的短网址转换是用flask自己写的。因为做的简单,所以用起来不方便,所以一直想重新写一个。后来想起,别人也肯定写过,就从网上搜了搜。发现了好几个,最好选用了YOURLS。

二、安装条件

Server

  • Apache (httpd) version 2.4 or greater, with mod_rewrite enabled
  • PHP version 7.4 or greater
    • PHP cURL extension is required if you plan on playing with the API
  • MySQL version 5.0 or greater, or MariaDB version 10.0 or greater.

We also suggest that you use a host with HTTPS support.

If you are installing your own server, see this file for the PHP extensions YOURLS will use.

三、安装流程

1.安装php

参考网上博客,我之前已经安装了。

2.下载

mkdir /opt/shorturl/
wget -S https://github.com/YOURLS/YOURLS/archive/refs/tags/1.9.2.tar.gz
tar -zxvf 1.9.2.tar.gz
mv YOURLS-1.9.2 YOURLS
cp /opt/shorturl/YOURLS/user/config-sample.php  cp /opt/shorturl/YOURLS/user/config.php  

3.配置

 #数据库用户名
define( 'YOURLS_DB_USER', 'xxxxxx' );

#数据库密码
define( 'YOURLS_DB_PASS', 'xxxxxx' );

#数据库名
define( 'YOURLS_DB_NAME', 'xxxxxx' );

#数据库连接地址
define( 'YOURLS_DB_HOST', 'localhost' );

#数据库表前缀,一般保持默认
define( 'YOURLS_DB_PREFIX', 'yourls_' );

#设置用户名和密码,可设置多个用户
$yourls_user_passwords = array(
        'username' => 'password',
        // 'username2' => 'password2',
        // You can have one or more 'login'=>'password' lines
        );
 
#设置站点域名
define( 'YOURLS_SITE', 'http://demo.com' );
#GMT时间偏移
define( 'YOURLS_HOURS_OFFSET', '-5' );
#是否私有
define( 'YOURLS_PRIVATE', 'true' );

4.nginx配置

这里nginx请求php使用的php-phm

server {

  # HTTP over IPv4 & IPv6
  listen 80;
  listen [::]:80;

  # HTTPS over IPv4 & IPv6
  # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
  listen 443 ssl;
  listen [::]:443 ssl;
  ssl_certificate     example.com.crt;
  ssl_certificate_key example.com.key;

  # Server names
  # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
  server_name example.com www.example.com;

  # Root directory
  # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
  root /path/to/yourls/files;

  # Rewrites
  location / {
    try_files $uri $uri/ /yourls-loader.php$is_args$args;
    # if YOURLS is installed in a subdirectory, change the path
    # to yourls-loader.php accordingly, eg
    # try_files $uri $uri/ /subdir/yourls-loader.php$is_args$args;
  }

  # PHP engine
  location ~ \.php$ {
    include fastcgi.conf;
    # OR
    # include fastcgi_params;

    fastcgi_index index.php;

    # MUST BE EDITED TO REFLECT YOUR CONFIGURATION
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  }

}

5.浏览器访问网址

http://你的网址/admin完成安装

四、参考博文

官方博客

YOURLS/YOURLS

开源免费的短网址源码: YOURLS,使用教程搭建自己的短网址站

YOURLS短网址系统nginx伪静态规则

Previous Post

主角与路人

Next Post

错误宝贵,不要浪费

Related Posts