如何在 Ubuntu 22.04 LTS 上安装 YOURLS
admin
2023-07-31 20:52:10
0

YOURLS代表您自己的URL缩短器,这是一个免费的开源PHP脚本,可让您创建自定义URL缩短服务。它允许您创建简短和自定义的URL,跟踪点击统计信息并控制您的数据。yourls-logoyourls-logo

在 Ubuntu 22.04 LTS Jammy Jellyfish 上安装 YOURLS

第 1 步。在开始安装过程之前,最好更新系统以确保我们拥有最新的软件包。为此,请打开终端并运行以下命令:

sudo apt update
sudo apt upgrade
sudo apt install wget apt-transport-https gnupg2

第 2 步。在 Ubuntu 22.04 上安装 LAMP 堆栈。

YOURLS需要Web服务器,数据库和PHP才能运行。如果您没有安装 LAMP 堆栈,您可以按照我们的指南进行操作。

第 3 步。配置 MariaDB。

默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方仔细阅读,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限:mysql_secure_installation

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

接下来,我们需要登录到 MariaDB 控制台并为 YOURLS 创建一个数据库。运行以下命令:

mysql -u root -p
  • 这将提示您输入密码,因此请输入您的MariaDB root密码并按Enter键。登录到数据库服务器后,您需要为Yourls安装创建一个数据库:
MariaDB [(none)]> create database yourlsdb character set utf8mb4;
MariaDB [(none)]> grant all on yourlsdb.* to \'yourls\'@\'localhost\' identified by \'your-strong-passwd\';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

有关安装 MariaDB 的其他资源,请阅读以下帖子:

  • 如何在 Ubuntu Linux √ 上安装 MariaDB

第 4 步。在 Ubuntu 22.04 上安装 YOURLS。

默认情况下,YOURLS 在 Ubuntu 22.04 基础存储库上不可用。现在运行以下命令,从官网下载最新版本的YOURLS:

wget https://github.com/YOURLS/YOURLS/archive/refs/tags/1.9.2.tar.gz

接下来,提取下载的存档:

sudo tar -xvzf 1.9.2.tar.gz
sudo mv YOURLS-1.9.2/* /var/www/yourls/
sudo rm -rf YOURLS-1.9.2/

之后,将 YOURLS 目录的所有权更改为 Apache 用户:

sudo chown -R www-data:www-data /var/www/yourls
sudo chmod -R 755 /var/www/yourls
sudo chmod 777 /var/www/yourls/user/config.php

接下来,复制到:user/config-sample.phpuser/config.php

cp user/config-sample.php user/config.php
nano user/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\', \'your-strong-passwd\' );

/** The name of the database for YOURLS */
define( \'YOURLS_DB_NAME\', \'yourlsdb\' );

/** 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 设置网站网址:

/** 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.your-domain.com\' );

接下来,设置用户和密码:

/** 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\' => \'meilana\',
  \'jmutai\' => \'meilana-Strong-Password\',
   // You can have one or more \'login\'=>\'password\' lines
   );

保存并关闭文件。

第5步。配置 Apache 虚拟主机。

现在为 YOURLS 创建虚拟主机配置文件:

nano /etc/apache2/sites-available/yourls.conf

添加以下文件:



ServerName url.unixcop.com
DocumentRoot /var/www/yourls


      Options FollowSymlinks
      AllowOverride All
      Require all granted
 

ErrorLog ${APACHE_LOG_DIR}/yourls.your-domain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourls.your-domain.com_access.log combined

保存并关闭文件,然后重新启动 Apache,以便进行更改:

sudo a2enmod rewrite
sudo a2ensite yourls.conf
sudo systemctl restart apache2

有关安装和管理 Apache 的其他资源,请阅读下面的帖子:

  • 如何在 Ubuntu Linux √ 上安装 Apache。

第 6 步。使用Let\’s Encrypt SSL保护YOURLS。

首先,使用以下命令安装 Certbot 客户端:

sudo apt install certbot python3-certbot-apache2

接下来,按照以下步骤使用Let\’s Encrypt获取SSL证书:

certbot --apache -d yourls.your-domain.com

让我们加密证书的有效期为 90 天,强烈建议在证书过期之前续订证书。您可以通过运行以下命令来测试证书的自动续订:

sudo certbot renew --dry-run

步骤 7.配置防火墙。

现在我们使用Apache设置了一个简单防火墙(UFW),以允许在HTTP和HTTPS的默认Web端口上进行公共访问:

sudo ufw allow OpenSSH
sudo ufw allow \'Apache Full\'
sudo ufw enable

第8步。访问 YOURLS 网页界面。

成功安装后,现在打开您的网络浏览器并使用 URL 访问 YOURLS Web UI。您将被重定向到以下页面:https://yourls.your-domain.com

yourls-web-interfaceyourls-web-interface

感谢您使用本教程在 Ubuntu 22.04 LTS Jammy Jellyfish 系统上安装 YOURLS(您自己的 URL 缩短器)。如需其他帮助或有用信息,我们建议您查看 YOURLS 网站。

相关内容

热门资讯

Windows 11 和 10... Windows 11/10 文件夹属性中缺少共享选项卡 – 已修复 1.检查共享选项卡是否可用 右键...
Radmin VPN Wind... Radmin VPN 是一款免费且用户友好的软件,旨在牢固地连接计算机以创建一个有凝聚力的虚拟专用网...
如何修复 Steam 内容文件... Steam 内容文件锁定是当您的 Steam 文件无法自行更新时出现的错误。解决此问题的最有效方法之...
在 Windows 11 中打... 什么是链路状态电源管理? 您可以在系统控制面板的电源选项中看到链接状态电源管理。它是 PCI Exp...
iPhone 屏幕上有亮绿色斑... iPhone 是市场上最稳定的智能手机之一,这主要归功于专为它们设计的 iOS 操作系统。然而,他们...
事件 ID 7034:如何通过... 点击进入:ChatGPT工具插件导航大全 服务控制管理器 (SCM) 负责管理系统上运行的服务的活动...
QQ浏览器怎么制作简历 QQ浏览器是腾讯公司开发的一款极速浏览器,支持电脑,安卓,苹果等多种终端;更快的浏览体验,更安全的浏...
Hive OS LOLMine... 目前不清退的交易所推荐: 1、全球第二大交易所OKX欧意 国区邀请链接: https://www.m...
Apple Watch Ult... 所有运行 watchOS 7 或更高版本的 Apple Watch 型号都包含一项名为“优化电池充电...
统信UOS每次开机后不直接进入... 统信UOS每次开机后不直接进入系统而是进入到recovery模式 按方向上键选择UOS 20 SP1...