如何在 Ubuntu 22.04 LTS 上安装 YOURLS

YOURLS代表您自己的URL缩短器,这是一个免费的开源PHP脚本,可让您创建自定义URL缩短服务。它允许您创建简短和自定义的URL,跟踪点击统计信息并控制您的数据。yourls-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 的其他资源,请阅读以下帖子:

第 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

添加以下文件:

<VirtualHost *:80>

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

<Directory /var/www/yourls/>
      Options FollowSymlinks
      AllowOverride All
      Require all granted
 </Directory>

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

</VirtualHost>

保存并关闭文件,然后重新启动 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-interface

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

未经允许不得转载:统信UOS之家 » 如何在 Ubuntu 22.04 LTS 上安装 YOURLS

相关文章