在 Ubuntu 22.04|20.04|18.04 上安装 YOURLS - 您自己的 URL 缩短器
本指南将帮助您在 Ubuntu 22.04|20.04|18.04 LTS 服务器上安装 YOURLS(您自己的 URL 缩短器)。 YOURLS 是一组免费且开源的 PHP 脚本,可让您运行您自己的 URL 缩短程序。
YOURLS 允许您完全控制您的数据、详细统计数据、分析、插件等。它具有以下一组功能
- 它是完全免费的开源软件。
- 私人(仅限您的链接)或公共(每个人都可以创建短链接,适合内部网)
- 连续或自定义 URL 关键字
- 方便的书签,可轻松缩短和共享链接
- 很棒的统计数据:历史点击报告、推荐人跟踪、访客地理位置
- 简洁的 Ajax 界面
- 出色的插件架构,可轻松实现新功能
- 很酷的开发者 API
- 完整的 jsonp 支持
- 友好的安装程序
- 用于创建您自己的公共界面等的示例文件
YOURLS 服务器要求
- Nginx/Apache (httpd) 版本 2.4 或更高版本,启用 mod_rewrite
- PHP 版本 5.3 或更高版本
- MySQL 版本 5.0 或更高版本
- PHP cURL 扩展
请按照以下步骤在 Ubuntu 20.04|18.04 Linux 上设置 YOURLS。
第 1 步:安装 PHP 和 cURL 扩展
YOURLS 需要在主机系统上安装 PHP 才能运行。使用以下命令在 Ubuntu 22.04|20.04|18.04 上安装 PHP
sudo apt update
sudo apt install -y php php-fpm php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
第2步:安装MariaDB数据库
下载并安装 MariaDB 数据库服务器:
sudo apt -y install mariadb-server
安装 MariaDB 后,访问 shell:
sudo mysql -u root
为 YOURLS 创建数据库和用户。
CREATE USER 'yourls'@'localhost' IDENTIFIED BY 'StrongPassword';
CREATE DATABASE yourls;
GRANT ALL PRIVILEGES ON yourls.* TO 'yourls'@'localhost';
FLUSH PRIVILEGES;
QUIT;
第 3 步:下载并安装 YOURLS
我们会将 YOURLS 下载放到 /srv
目录中。您可以将内容放置在您希望 Web 服务器加载的任何目录中。
cd /srv
git clone https://github.com/YOURLS/YOURLS.git
将user/config-sample.php
复制到user/config.php
cd YOURLS/user
cp config-sample.php config.php
设置数据库连接
*
** MySQL settings - You can get this info from your web host
*/
/** MySQL database username */
define( 'YOURLS_DB_USER', 'yourls' );
/** MySQL database password */
define( 'YOURLS_DB_PASS', 'StrongPassword' );
/** The name of the database for YOURLS */
define( 'YOURLS_DB_NAME', 'yourls' );
/** MySQL hostname.
** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );
/** MySQL tables prefix */
define( 'YOURLS_DB_PREFIX', 'yourls_' );
为 YOURLS 设置网站 URL
/** YOURLS installation URL -- all lowercase, no trailing slash at the end.
** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) */
define( 'YOURLS_SITE', 'http://yourls.example.com' );
设置您的时区 GMT 偏移量
** Server timezone GMT offset */
define( 'YOURLS_HOURS_OFFSET', '+3' );
添加允许访问该网站的用户名
和密码
。密码可以是纯文本,也可以是加密的哈希值。 YOURLS 将自动加密此文件中的纯文本密码
/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
** YOURLS will auto encrypt plain text passwords in this file
** Read http://yourls.org/userpassword for more information */
$yourls_user_passwords = array(
'admin' => 'AdminPassword',
'jmutai' => 'MyStrongPassword',
// You can have one or more 'login'=>'password' lines
);
您可以根据自己的喜好调整其他设置。完成后保存并关闭文件。
第四步:下载并配置Nginx
我选择的网络服务器是 Nginx
,但您也可以使用 Apache。通过运行以下命令在 Ubuntu 18.04 上安装 Nginx:
sudo apt install -y nginx
创建一个新的配置 /etc/nginx/conf.d/yourls.conf
文件,其中包含以下内容
server {
listen 80;
server_name example.com www.example.com;
root /srv/YOURLS;
index index.php index.html index.htm;
listen [::]:80;
location / {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include fastcgi_params;
}
}
检查nginx语法确保没问题
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
将 Nginx Web 用户所有权授予 /srv/YOURLS
目录。
sudo chown -R www-data:www-data /srv/YOURLS
重启nginx服务
sudo systemctl restart nginx
最后,打开 URL http://example.com/admin/
完成 YOURLS 设置。
点击“安装您的”开始安装。它将进行检查并设置数据库,您应该收到操作成功的消息
单击“YOURLS 管理页面”链接访问管理仪表板。使用之前添加的任何用户帐户登录。
您应该进入管理页面。
要缩短网址,请在“输入网址”框中输入,然后点击“缩短网址”以获取简短版本的网址。
感谢您使用我们的指南在 Ubuntu 18.04 Bionic Beaver Linux 上安装 YOURLS – 您自己的 URL 缩短器。请继续关注更多操作指南。