如何在 Ubuntu 20.04 LTS 上安装 Yourls
admin
2023-07-31 08:11:26
0

YOURLS 代表 Your Own URL Shortener。它是一个小型的免费开源 PHP 脚本,可让您运行自己的 URL 缩短服务。YOURLS 让您可以完全控制您的数据、详细统计数据、分析、插件等。

在 Ubuntu 20.04 LTS Focal Fossa 上安装 Yourls

步骤 1. 首先,通过apt在终端中运行以下命令确保所有系统包都是最新的。

sudo apt update
sudo apt upgrade

步骤 2. 安装 LAMP 堆栈。

需要 Ubuntu 20.04 LAMP 服务器。如果您没有安装 LAMP,您可以在本站搜一搜按照我们的教程进行操作。

步骤 3. 为您的用户配置 MariaDB。

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

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 根密码并按 Enter。登录数据库服务器后,需要为Yourls安装创建数据库:

MariaDB [(none)]> create database yourlsdb character set utf8mb4;
MariaDB [(none)]> grant all on yourlsdb.* to \'yourls\'@\'localhost\' identified by \'your-strong-password\';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;

步骤 4. 在 Ubuntu 20.04 上安装 Yourls。

现在我们从 Git 存储库下载最新版本的 YOURLS:

cd /var/www/html
git clone https://github.com/YOURLS/YOURLS.git

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

cd YOURLS/user/
cp config-sample.php config.php

接下来,编辑配置文件并定义数据库设置:

nano 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-password\' );

/** 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 设置网站 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.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\' => \'Ngadimin\',
  \'jmutai\' => \'Admin-Strong-Password\',
   // You can have one or more \'login\'=>\'password\' lines
   );

保存并关闭文件,然后更改所有权并为YOURLS目录赋予适当的权限:

chown -R www-data:www-data /var/www/html/YOURLS
chmod -R 775 /var/www/html/YOURLS

步骤 5. 为您的用户配置 Apache。

现在我们在 Apache 中创建一个新的虚拟主机指令。例如,在您的虚拟服务器上创建一个名为“ ”的新 Apache 配置文件:yourls.conf

touch /etc/apache2/sites-available/yourls.conf
ln -s /etc/apache2/sites-available/yourls.conf /etc/apache2/sites-enabled/yourls.conf
nano /etc/apache2/sites-available/yourls.conf

添加以下行:


ServerAdmin admin@your-domain.com
DocumentRoot /var/www/html/YOURLS
ServerName your-domain.com
ServerAlias www.your-domain.com

Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

ErrorLog /var/log/apache2/your-domain.com-error_log
CustomLog /var/log/apache2/your-domain.com-access_log common

现在,我们可以重新启动Apache Web服务器,以便进行更改:

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

步骤 6. 配置防火墙

如果您启用了UFW防火墙并且对apache Web服务器发出了防火墙阻止请求,请在防火墙中打开一个端口:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

步骤 7. 访问 Yourls Web 界面。

默认情况下,Yourls 将在 HTTP 端口 80 上可用。打开您喜欢的浏览器并导航至并完成完成安装所需的步骤。http://yourls.your-domain.com

yourls-web-interfaceyourls-web-interface

恭喜你!您已成功安装 Yourls。感谢您使用本教程在 Ubuntu 20.04 LTS Focal Fossa 系统上安装 Yourls (Your Own URL Shortener)。如需其他帮助或有用信息,我们建议您查看Yourls 官方网站。

相关内容

热门资讯

Windows 11 和 10... Windows 11/10 文件夹属性中缺少共享选项卡 – 已修复 1.检查共享选项卡是否可用 右键...
Radmin VPN Wind... Radmin VPN 是一款免费且用户友好的软件,旨在牢固地连接计算机以创建一个有凝聚力的虚拟专用网...
如何修复 Steam 内容文件... Steam 内容文件锁定是当您的 Steam 文件无法自行更新时出现的错误。解决此问题的最有效方法之...
事件 ID 7034:如何通过... 点击进入:ChatGPT工具插件导航大全 服务控制管理器 (SCM) 负责管理系统上运行的服务的活动...
在 Windows 11 中打... 什么是链路状态电源管理? 您可以在系统控制面板的电源选项中看到链接状态电源管理。它是 PCI Exp...
Hive OS LOLMine... 目前不清退的交易所推荐: 1、全球第二大交易所OKX欧意 国区邀请链接: https://www.m...
在 iCloud 上关闭“查找... 如果您是 Apple 的长期用户,您肯定会遇到过 Find My 应用程序,它本机安装在 iPhon...
farols1.1.501.0... faro ls 1.1.501.0(64bit)可以卸载,是一款无需连接外部PC机或笔记本计算机即可...
如何在 iPhone 14 P... Apple 的 iPhone 14 Pro 是第一款配备 48MP 传感器的 iPhone。所有以前...
balenaEtcher烧录后... balenaEtcher烧录后u盘或者内存卡无法识别不能使用的解决方法想要恢复原来的方法,使用win...