短地址服务yourls的配置使用

yourls 是开源的PHP 项目,所以使用yourls 先要进行PHP 运行环境的配置,这个可以自己百度下,网上资料很多,LAMP 的环境装好之后,就可以进行yourls 的使用配置。1.yourl

yourls 是开源的PHP 项目,所以使用yourls 先要进行PHP 运行环境的配置,这个可以自己百度下,网上资料很多,LAMP 的环境装好之后,就可以进行yourls 的使用配置。

1.yourls 要用到数据库,在MySQL 中为其穿件一个数据库,假设名字取为yourls

2. 将yourls 项目放到Apache 的项目目录下,一般为/var/www/html下,如果自己做了修改,根据自己的修改而定。

3. 进行Apache 的Rewrite 功能的配置

(1)去除Apache 的配置文件httpd.conf 文件中"#LoadModule rewrite_module

modules/mod_rewrite.so"前面的"#"号; 如果没有则添上这句话

(2)修改httpd.conf 文件中的"AllowOverride None"为"AllowOverride all",同时最好将Options 也置为"all", 否则可能会出问题。

(3)在配置的项目目录中(例如上面的为/var/www/html即yourls 的同级目录中)建立.htaccess 文件,并打开按如下方法编辑内容

根据yourls 官网的内容,内容如下

如果配置在根目录,如http://yoursite/,则内容如下

# BEGIN YOURLS

RewriteEngine On

RewriteBase /

RewriteCond {REQUEST_FILENAME} !-f

RewriteCond {REQUEST_FILENAME} !-d

RewriteRule ^.*$ /yourls-loader.php [L]

# END YOURLS

如果配置在子目录中,如http://yoursite/somedir/,内容如下

# BEGIN YOURLS

RewriteEngine On

RewriteBase /somedir/

RewriteCond {REQUEST_FILENAME} !-f

RewriteCond {REQUEST_FILENAME} !-d

RewriteRule ^.*$ /somedir/yourls-loader.php [L]

# END YOURLS

4. 进入yourls/user里面,将config-sample.php 改名为config.php, 打开此文件进行配置

/** MySQL database username */

define('YOURLS_DB_USER', 'dbuser');// MySQL 数据库用户名

/** MySQL database password */

define('YOURLS_DB_PASS', 'dbpassword');// MySQL 数据库密码

,

/** The name of the database for YOURLS */

define('YOURLS_DB_NAME', 'yourls');// MySQL 为yourls 配置给他用的数据库名称

/** MySQL hostname */

define('YOURLS_DB_HOST', 'localhost');

// MySQL 数据库所在主机,99情况不用修改,000webhost 等空间需要修改。

/** MySQL tables prefix */

define('YOURLS_DB_PREFIX', 'yourls_');

/**创建的 Yourls 的表的名字,同一个数据库放多个 Yourls 程序时需要修改。*/

/** YOURLS installation URL, no trailing slash */

define('YOURLS_SITE', 'http://site.com'); //站点域名

/** Timezone GMT offset */

define('YOURLS_HOURS_OFFSET', 0); //时区修改,基本没必要

/** Allow multiple short URLs for a same long URL

** 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);

//只允许一个要被缩短网址对应一个短网址,若允许对应多个短网址写false

/** Private means protected with login/pass as defined below. Set to false for public usage. */ define('YOURLS_PRIVATE', true);//私人用还是公开用,公开的话写false

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated. Hint: copy from

define('YOURLS_COOKIEKEY', 'qQ4KhL_pu|s@Zm7n#:b^{A[vhm');

//访问 http://yourls.org/cookiekey.php 取得一个唯一的 Key 并且修改填入

/** Username(s) and password(s) allowed to access the site */

$yourls_user_passwords = array(

'username' => 'password',

'username2' => 'password2' // You can have one or more 'login'=>'password' lines

);/**username管理员用户名和password 密码,默认两组,可删除一组或增加N 组 */

$yourls_reserved_URL = array(

'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', 'gay',

);/** 保留词语,建议增加proxy 等词。*/

,

到此你的yourls 配置完毕,service httpd start启动你的Apache 服务器。访问http://site.com/admin/install.php 其中yoursite.com 就是你在define('YOURLS_SITE', 'http://site.com'); 中配置的站点名称。

登录账号和密码也是你在上面自己配置的账号和密码。

进去之后就可以使用了

标签: