如何在 Ubuntu 20.04 LTS 上安装 Yourls

[ad_1]

在本教程中,我们将向您展示如何在 Ubuntu 20.04 LTS 上安装 Yourls。 对于那些不知道的人,YOURLS 代表 Your Own URL Shortener。 它是一个小型的免费开源 PHP 脚本,可让您运行自己的 URL 缩短服务。 YOURLS 让您可以完全控制您的数据、详细统计数据、分析、插件等。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,并且最重要的是,您在自己的 VPS 上托管您的站点。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 到获得 root 权限的命令。 我将向您展示在 Ubuntu 20.04 (Focal Fossa) 上逐步安装 Yourls 开源 URL 缩短。 您可以按照针对 Ubuntu 18.04、16.04 和任何其他基于 Debian 的发行版(如 Linux Mint)的相同说明进行操作。

在 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 未加固。 您可以使用以下方法保护 MariaDB mysql_secure_installation 脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 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

更改与您的数据库设置匹配的以下行,并提供您的域名和 admin 密码:

*
 ** 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 "https://sho.rt", don't use "https://www.sho.rt" in your browser (and vice-versa) */
define( 'YOURLS_SITE', 'https://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 https://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
   );

Save 和 close 然后该文件更改所有权并授予对 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

添加以下几行:

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/YOURLS
ServerName your-domain.com
ServerAlias www.your-domain.com
<Directory /var/www/html/YOURLS/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/your-domain.com-error_log
CustomLog /var/log/apache2/your-domain.com-access_log common
</VirtualHost>

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

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 界面。

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

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

[ad_2]

Related Posts