如何在CentOS 7上安装YOURLS
Anne655
・9 分钟阅读
YOURLS(你自己的URL Shortener)是一个开源URL缩短和数据分析应用程序。
在本文中我们将介绍在CentOS 7服务器上安装YOURLS的进程。
前提条件
- CentOS 7x64服务器实例,
- 一个sudo用户 ,
- 指向你的服务器地址IP的域
example.com
,
步骤1:更新系统
以sudo用户身份登录,然后使用下面的命令更新系统:
sudo yum install epel-release -y
sudo yum clean all && sudo yum update -y && sudo shutdown -r now
重新引导后,使用相同的sudo用户重新登录到服务器。
步骤2:安装Web服务器apache
使用YUM安装Apache网络服务器:
sudo yum install httpd -y
删除Apache欢迎页面:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
禁止Apache在访问者的网页浏览器中公开文件:
sudo sed -i"s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
启动Apache服务并将它设置为在系统启动时自动启动:
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
步骤3:安装MariaDB 10.x
安装最新版本的MariaDB,MariaDB 10.1,如下所示:
3.1创建MariaDB 10.1 YUM repo文件
cat <<EOF | sudo tee -a /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.1 CentOS repository list - created 2017-01-14 03:11 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
3.2 Install MariaDB 10.1使用YUM
sudo yum install MariaDB-server MariaDB-client -y
3.3启动MariaDB服务,并将它设置为在系统启动时自动运行
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
3.4保护MariaDB的安装
sudo /usr/bin/mysql_secure_installation
回答以下问题,并确保你将使用你自己的MariaDB root密码:
- 输入root 的当前密码: 按下
Enter
按钮即可 - 设置root密码[Y/n] :
Y
? - 新密码:
your-root-password
- 输入新密码:
your-root-password
- 删除匿名用户[Y/n] :
Y
? - 不允许远程登录root[Y/n] :?
Y
- 删除测试数据库并访问它? [Y/n] :
Y
- 现在重新加载权限表[Y/n] :?
Y
3.5为YOURLS创建MariaDB数据库
以root
的形式登录到MySQL shell :
mysql -u root -p
键入你自己的MariaDB root密码,然后按Enter
。
在MySQL shell中,创建数据库yourls
,数据库用户yourlsuser
和用户yourpassword
的数据库密码如下。
注意:出于安全考虑,你应该使用你自己的用户密码,而不是使用例子中的密码yourpassword 。
CREATE DATABASE yourls DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci;
CREATE USER 'yourlsuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON yourls.* TO 'yourlsuser'@'localhost' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
步骤4: Install PHP 7.1和必需的PHP 7.1扩展
安装PHP 7.1和几个PHP 7.1扩展,如下所示:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-mysqlnd php71w-common
步骤5安装你的RLS
5.1从GitHub YOURLS repo 获取最新的YOURLS代码
sudo yum install git -y
cd /var/www/html/
sudo git clone https://github.com/YOURLS/YOURLS.git
sudo chown -R apache:apache /var/www/html/YOURLS
cd YOURLS
5.2 配置你的YOURLS
sudo cp user/config-sample.php user/config.php
sudo chown apache:apache user/config.php
使用vi
文本编辑器打开 /var/www/html/YOURLS/user/config.php
文件:
sudo vi user/config.php
查找下面的行:
define( 'YOURLS_DB_USER', 'your db user name' );
define( 'YOURLS_DB_PASS', 'your db password' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'http://your-own-domain-here.com' );
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );
$yourls_user_passwords = array(
'username' => 'password',
按如下方式逐个替换它们:
define( 'YOURLS_DB_USER', 'yourlsuser' );
define( 'YOURLS_DB_PASS', 'yourpassword' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'http://example.com' );
define( 'YOURLS_COOKIEKEY', 'fmoi4jfsjfasfjlkfjalfgcggjkihdgfjjgdfolsfmwemlgjhgigjgitjaaewesfsdfsdogmbnsin' ); // Use a long string consists of random characters.
$yourls_user_passwords = array(
'username1' => 'password1', // Use your own username and password.
保存和退出:
:wq
!5,3为你的RLS创建虚拟主机:
cat <<EOF | sudo tee -a /etc/httpd/conf.d/yourls.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/YOURLS/
ServerName yourls.example.com
ServerAlias www.yourls.example.com
<Directory /var/www/html/YOURLS/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/yourls.example.com-error_log
CustomLog /var/log/httpd/yourls.example.com-access_log common
</VirtualHost>
EOF
5.4应用你的设置:
sudo systemctl restart httpd.service
5.5修改防火墙规则:
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
5.6网页访问:
将网络浏览器指向http://example.com/admin
,然后单击Install YOURLS
链接以完成安装。
如果已成功安装YOURLS,请单击YOURLS Administration Page链接以访问YOURLS管理界面,然后使用用户名username1和密码password1登录。
5.7 安装后的安全措施
出于安全考虑,你应该在安装后限制对YOURLS的权限:
sudo chown -R root:root /var/www/html/YOURLS
如果需要升级程序或安装插头,可以按如下方式恢复该用途的严格权限:
sudo chown -R apache:apache /var/www/html/YOURLS
这是我们的教程,感谢阅读。