宝塔管理面板使用Composer安装YOURLS短网址程序帮助教程,通过Composer安装项目。

2021年4月26日 2590点热度 6人点赞 0条评论

在宝塔管理面板使用中PHP管包管理工具Composer安装YOURLS短网址程序帮助教程,也可以通过Composer安装其他支持Composer的项目。

宝塔通过Composer安装YOURLS短网址程序

安装前准备

1、宝塔版本:7.5.2

2、PHP版本:7.4

3、MySql版本:>= 5.5

4、composer版本:2.0.12

5、确认域名DNS指向当前网站

创建网站

1、首先我们使用宝塔面板创建一个站点,如图:

宝塔面板创建一个站点

2、更新当前PHP的composer版本

更新当前PHP的composer版本

3、点击网站目录,进入目录,并且删除站点下默认创建的文件。

删除站点下默认创建的文件

删除站点下默认创建的文件

4、在PHP设置中取消putenv、proc_open 函数的禁用。

禁用原因:在使用composer安全管理其他时,需要putenv、proc_open这两个函数才可以安装成功,所以要取消禁用,等安装完成不使用之后,可以禁用。

proc_open   安全原因:执行一个命令并打开文件指针用于读取以及写入。
putenv   安全原因:用于在 PHP 运行时改变系统字符集环境。在低于 5.2.6 版本的 PHP 中,可利用该函数修改系统字符集环境后,利用 sendmail 指令发送特殊参数执行系统 SHELL 命令。

不取消禁用情况下的报错相关:

PHP Warning:  putenv() has been disabled for security reasons in phar:///usr/bin/composer/vendor/composer/xdebug-handler/src/Process.php on line 160

Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/vendor/composer/xdebug-handler/src/Process.php on line 160
PHP Warning:  putenv() has been disabled for security reasons in phar:///usr/bin/composer/bin/composer on line 59

Warning: putenv() has been disabled for security reasons in phar:///usr/bin/composer/bin/composer on line 59
Creating a "yourls/yourls" project at "./"
Installing yourls/yourls (1.8.1)
  - Installing yourls/yourls (1.8.1): Extracting archive
    The Process class relies on proc_open, which is not available on your PHP installation.
    The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
    Unzip with unzip command failed, falling back to ZipArchive class

                            
  [ErrorException]          
  Undefined index: process

 

PHP设置中取消putenv、proc_open

PHP设置中取消putenv、proc_open

5、使用composer安装YOURLS程序

[caption id="attachment_324" align="alignnone" width="600"]使用composer安装YOURLS程序 进入终端之后,在命令行执行下面命令。后面是有个 “ . ”的[/caption]

composer create-project yourls/yourls .

[caption id="attachment_325" align="alignnone" width="600"]使用composer安装YOURLS程序 到这里通过composer已经将YOURLS安装至当前网站目录了,和刷新文件查看。[/caption]

6、禁用PHP中putenv、proc_open函数,也就是我们刚刚取消禁用的函数

在这里,为了安全考虑我们要禁用我们之前取消禁用的PHP函数,在下次使用composer的时候可以在手动取消禁用。

putenv
proc_open

禁用PHP中putenv、proc_open函数

配置YOURLS程序

在之前的安装过程,我们已经将YOURLS安装好了,现在开始需要做一些配置相关,才可以正确使用。

1、配置user/config.php

首选我们进入刚刚创建好YOURLS程序的user目录,找到config-sample.php文件:
路径应为 YOURLS网站根目录->user/config-sample.php
选择config-sample.php文件,将期重命名为config.php
重命名完成之后,请执行下面操作

1、编辑config.php配置文件

1、打开config.php文件进入编辑页面, 会看的以下内容

/*
 ** MySQL settings - You can get this info from your web host
 */

/** 数据库用户名称, 刚刚创建网站时名称 */
define( 'YOURLS_DB_USER', 'test_yiem_net' );

/** 数据库用户密码, 创建网站时的数据库密码 */
define( 'YOURLS_DB_PASS', 'sasas1020300' );

/** 数据库名称,刚刚创建网站时的数据库名
 ** 数据库名称只能是[a-z]小写字母、[0-9]数字以及下划线[_] */
define( 'YOURLS_DB_NAME', 'test_yiem_net' );

/** 数据库地址
 ** 数据库地址一般默认为localhost,端口为3306,如果你的端口不是默认的3306的话,也可以localhost:4489 这种形式,当然如果你的数据库是独立的情况下,可以直接输入的你数据库地址和端口如:10.0.1.1:8892;*/
define( 'YOURLS_DB_HOST', 'localhost' );

/** 数据库表前缀,不知道什么意思默认就好
 ** 可以自定义为,如:yiem_, baidu_, qq_等等前缀形式
 ** 只能是[a-z]小写字母、[0-9]数字以及下划线[_] */
define( 'YOURLS_DB_PREFIX', 'yourls_' );

/*
 ** Site options, 网站设置
 */

/** 网址
 ** 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)
 ** To use an IDN domain (eg http://héhé.com), write its ascii form here (eg http://xn--hh-bjab.com)
 ** 你的域名网址 */
define( 'YOURLS_SITE', 'http://test.yien.net' );

/** YOURLS language, 显示的语言
 ** Change this setting to use a translation file for your language, instead of the default English.
 ** That translation file (a .mo file) must be installed in the user/language directory.
 ** See http://yourls.org/translations for more information 
 ** 因为当前程序支持简体中文,所以输入zh_CN 就可以, 更多语言参考这里https://github.com/YOURLS/awesome-yourls#translations-
 ** 打开这个语言链接,下载简体中文的.mo 文件, 上传至user/language目录中。
 */
define( 'YOURLS_LANG', 'zh_CN' );

/** Allow multiple short URLs for a same long URL, Ture的情况下,一个短url对应一个长url(如:url.cn/bd,是www.baidu.com/yiem的短版),False的情况下,多个短url可对应一个长url(如:url.cn/bd,url.cn/bai, url.cn/b001都是www.baidu.com/yiem的短网址)
 ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior)
 ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */
define( 'YOURLS_UNIQUE_URLS', true );

/** Private means the Admin area will be protected with login/pass as defined below., True情况下是有管理员地址的http://sho.rt/admin/, False情况下是所有人都可以管理, 默认就好
 ** Set to false for public usage (eg on a restricted intranet or for test setups)
 ** Read http://yourls.org/privatepublic for more details if you're unsure */
define( 'YOURLS_PRIVATE', true );

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated
 ** Hint: copy from http://yourls.org/cookie
 cookie设置, 打开这个网站http://yourls.org/cookie, 复制内容,替换下面内容就可以
 */
define( 'YOURLS_COOKIEKEY', 'r@]7Wt#AY-9xw)]3x}YkzC&xIQyHxAj1&w-T5sWj' );

/** 允许访问自网站的用户密码,管理员的配置也在这里
 ** 以[ '用户名' => '密码', ]的形式添加多个用户
 ** 密码在下次运行是自动加密至哈希值,如果修改密码的话,直接把哈希值替换成你的密码就可以如:12345
 ** 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 = [
	'yiem' => '123456',
	// 'username2' => 'password2',
	// You can have one or more 'login'=>'password' lines
];

/** URL shortening method: 36 or 62
 ** 36: generates all lowercase keywords (ie: 13jkm), 36 位为小写字母混合
 ** 62: generates mixed case keywords (ie: 13jKm or 13JKm) 62位为大小写字母混合,如果链接非常多的情况下请提前设置为62为
 ** 62为的尺度比32为长 */
define( 'YOURLS_URL_CONVERT', 36 );

/** Debug mode to output some internal information, 调试模式,默认就好
 ** Default is false for live site. Enable when coding or before submitting a new issue */
define( 'YOURLS_DEBUG', false );

/**
* 关键字排除,排除http地址中的违规关键字,如http:www.sex.com 等, 关键字可以新增;
* 都是对于http中,如果www.test.com/1231, 这种就无法屏蔽。
* Reserved keywords (so that generated URLs won't match them)
* Define here negative, unwanted or potentially misleading keywords.
*/
$yourls_reserved_URL = [
	'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick',
];

/* 更多多配置请看官方:https://yourls.org/#Config;site
 ** Personal settings would go after here.
 */

3、配置规则

1)Apache .htaccess 根目录情况规则, 具体查看https://github.com/YOURLS/YOURLS/wiki/.htaccess

# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS

2)Nginx规则

location / {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
}

4、打开解析好的域名地址如:http://url.yiem.net/admin/ , 会自动打开YOURLS管理页面如下

YOURLS管理页面

YOURLS管理页面

直接点击进入YOURLS管理页面,用户名是你在配置文件中输入的配置的用户名和密码。

5、这个时候,你直接访问url.yiem.net提示的是403,这个提示是正常的,因为我们配置的是私有的。

这个时候有两种解决方法

1、将值的私有设置为False,变为公有
define('YOURLS_PRIVATE',false);

2、设置API接口,通过API访问,就不需要设置define('YOURLS_PRIVATE',false);为公有了。

安装完成

到了这里我们就安装完成了,剩余的api相关的,以及插件等等相关的在之后的教程中体现。

帮助教程

提供最新的帮助教程,方便使用。

文章评论