Install Apache web server
yum install httpd -y
Remove the Apache welcome page:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
Prevent Apache from exposing files in visitors’ web browser:
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
Once installed, start the web server and enable it to start at system boot
systemctl start httpd.service
systemctl enable httpd.service
注:Apache httpd默认端口为80,因本人的服务器80端口已占用,现修改端口为9386
#查询httpd.conf
find / -name httpd.conf
#修改httpd.conf配置
vi /etc/httpd/conf/httpd.conf
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#Listen 12.34.56.78:80
Listen 9386
#查询服务是否启动
systemctl status httpd.service
安装mysql
请参考我安装mysql的文章
#创建数据库
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;
Install PHP 7.1 and necessary PHP 7.1 extensions
Install PHP 7.1 and several PHP 7.1 extensions as follows:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-mysqlnd php71w-common
Install and configure YOURLS
We have to download YOURLS from their official GitHub repository, so make sure that git is installed on your server
yum install git -y
Get YOURLS from GitHub
cd /var/www/html/
git clone https://github.com/YOURLS/YOURLS.git
Change the ownership of YOURLS files
chown -R apache:apache YOURLS/
Copy the sample YOURLS configuration file
cd YOURLS/
cp user/config-sample.php user/config.php
chown apache:apache user/config.php
Open the configuration file and update the following lines
vi user/config.php
define( 'YOURLS_DB_USER', 'yourlsuser' );
define( 'YOURLS_DB_PASS', 'YOUR_PASSWORD' );
define( 'YOURLS_DB_NAME', 'yourlsdb' );
define( 'YOURLS_DB_HOST', 'localhost' );
define( 'YOURLS_SITE', 'http://yourdomain.com' );
#define( 'YOURLS_SITE', 'http://52wss.com:9386' );#如果你的端口不是80、443,在域名后面加上你的端口号
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );
$yourls_user_passwords = array(
'user' => 'password', // Use your actual username and password
Create Apache virtual host
Create a virtual host directive, so you can access YOURLS with your domain name.
vi /etc/httpd/conf.d/yourls.conf
ServerAdmin admin@52wss.com
DocumentRoot /var/www/html/YOURLS/
ServerName 52wss.com
ServerAlias www.52wss.com
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
ErrorLog /var/log/httpd/yourdomain.com-error_log
CustomLog /var/log/httpd/yourdomain.com-access_log common
Save the file and restart Apache for the changes to take effect.
Now, go to http://yourdomain.com and follow the on-screen instructions to complete the YOURLS installation.
How to Install YOURLS on CentOS 7
Published on: Fri, Feb 10, 2017 at 12:13 pm EST
CentOS Linux Guides Server Apps System Admin Web Servers
YOURLS (Your Own URL Shortener) is an open source URL shortening and data analytics application.
In this article, we will cover the process of installing YOURLS on a CentOS 7 server.
Prerequisites
A CentOS 7 x64 server instance.
A sudo user.
A domain example.com that points to your server’s IP address.
Step 1: Update the system
Log in as a sudo user, and then use the below commands to update the system:
sudo yum install epel-release -y
sudo yum clean all && sudo yum update -y && sudo shutdown -r now
After the reboot, log back into the server using the same sudo user.
Step 2: Install a web server—Apache
Install the Apache web server using YUM:
sudo yum install httpd -y
Remove the Apache welcome page:
sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf
Prevent Apache from exposing files in visitors’ web browser:
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf
Start the Apache service and set it to auto-start on system boot:
sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Step 3: Install MariaDB 10.x
Install the latest stable release of MariaDB, MariaDB 10.1 as below:
3.1 Create the MariaDB 10.1 YUM repo file
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 using YUM
sudo yum install MariaDB-server MariaDB-client -y
3.3 Start the MariaDB service and set it as running at system startup
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
3.4 Secure the installation of MariaDB
sudo /usr/bin/mysql_secure_installation
Answer questions as below, and ensure that you will use your own MariaDB root password:
这里有可能会提示没有密码,直接回车就行
Enter current password for root (enter for none): Just press the Enter button
Set root password? [Y/n]: Y
New password: your-root-password
Re-enter new password: your-root-password
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
3.5 Create a MariaDB database for YOURLS
Log into the MySQL shell as root:
mysql -u root -p
Type your own MariaDB root password and then press Enter.
In the MySQL shell, create a database yourls, a database user yourlsuser, and the database user’s password yourpassword as follows.
Note: For security purposes, you should use your own user password instead of the sample password 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;
Step 4: Install PHP 7.1 and necessary PHP 7.1 extensions
Install PHP 7.1 and several PHP 7.1 extensions as follows:
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y mod_php71w php71w-mysqlnd php71w-common
Step 5: Install YOURLS
5.1 Get the latest YOURLS code from YOURLS GitHub repo:
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 Configure YOURLS:
sudo cp user/config-sample.php user/config.php
sudo chown apache:apache user/config.php
Use the vi text editor to open the /var/www/html/YOURLS/user/config.php file:
sudo vi user/config.php
Find the below lines:
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',
Replace them one by one as follows:
define( 'YOURLS_DB_USER', 'yourlsuser' );
define( 'YOURLS_DB_PASS', 'yourpassword' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'http://example.com' );
#define( 'YOURLS_SITE', 'http://52wss.com:9386' );#如果你的端口不是80、443,在域名后面加上你的端口号
define( 'YOURLS_COOKIEKEY', 'fmoi4jfsjfasfjlkfjalfgcggjkihdgfjjgdfolsfmwemlgjhgigjgitjaaewesfsdfsdogmbnsin' ); // Use a long string consists of random characters.
$yourls_user_passwords = array(
'username1' => 'password1', // Use your own username and password.
Save and quit:
:wq!
5.3 Create a virtual host for YOURLS:
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
#如果你监控的是其他的端口
cat <<EOF | sudo tee -a /etc/httpd/conf.d/yourls.conf
<VirtualHost *:9386>
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 Apply your settings:
sudo systemctl restart httpd.service
5.5 Modify firewall rules:
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
5.6 Web access:
Point your web browser to http://example.com/admin, and then click the Install YOURLS link to finish the installation.
Having YOURLS successfully installed, click the YOURLS Administration Page link to visit the YOURLS Admin interface, and then use the username username1 and password password1 to log in.
5.7 Post-installation security measures
For security purposes, you should restrict permissions to YOURLS after the installation:
sudo chown -R root:root /var/www/html/YOURLS
When you need to upgrade the program or install a plug-in, you can revert the strict permissions for that purpose as follows:
sudo chown -R apache:apache /var/www/html/YOURLS
That concludes our tutorial. Thanks for reading.
问题
PHP PDO问题
PHP Fatal error: Class ‘PDO’ not found in /var/www/html/YOURLS/includes/vendor/aura/sql/src/ExtendedPdo.php on line 23
解决方法:
yum install php-pdo
yum install php-pdo_mysql
service httpd restart
短链接无法访问
在/var/www/html/YOURLS根目录下创建.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
微信公众号,欢迎扫码关注
