How to Install liteshort on Ubuntu Server Latest
In this tutorial, we will walk through the steps to install liteshort on Ubuntu Server Latest. liteshort is a lightweight open source URL shortener developed in PHP.
Prerequisites
Before we can start with the installation of liteshort, we need to meet the following prerequisites:
- An instance of Ubuntu Server Latest should be up and running.
- A user account with sudo privileges.
- A webserver (like Apache or Nginx) installed on Ubuntu Server.
Step 1: Install PHP and MySQL
We need to install PHP and MySQL to be able to run liteshort. Run the following commands to install these dependencies:
sudo apt-get update
sudo apt-get install php php-mysql mysql-server -y
Step 2: Download liteshort
We will download liteshort from the Git repository. Run the following command:
git clone https://git.ikl.sh/132ikl/liteshort.git
Step 3: Configure Apache or Nginx
The next step is to configure Apache or Nginx for liteshort.
For Apache
Run the following commands to enable the Apache rewrite module and create a virtual host configuration file:
sudo a2enmod rewrite
sudo touch /etc/apache2/sites-available/liteshort.conf
sudo nano /etc/apache2/sites-available/liteshort.conf
Add the following content to the liteshort.conf file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/liteshort/public
ServerName example.com
<Directory /var/www/liteshort/public>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/liteshort_error.log
CustomLog ${APACHE_LOG_DIR}/liteshort_access.log combined
</VirtualHost>
Replace example.com with your domain name or IP address.
Save and close the file.
Run the following commands to enable the virtual host and restart the Apache webserver:
sudo a2ensite liteshort.conf
sudo systemctl restart apache2
For Nginx
Run the following commands to create a virtual host configuration file for Nginx:
sudo touch /etc/nginx/sites-available/liteshort.conf
sudo nano /etc/nginx/sites-available/liteshort.conf
Add the following content to the liteshort.conf file:
server {
listen 80;
listen [::]:80;
root /var/www/liteshort/public;
index index.php;
server_name example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
Replace example.com with your domain name or IP address.
Save and close the file.
Run the following commands to enable the virtual host and restart the Nginx webserver:
sudo ln -s /etc/nginx/sites-available/liteshort.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Step 4: Create MySQL Database and User
We need to create a MySQL database and user for liteshort to store the data. Run the following commands to log in to MySQL as the root user and create a new liteshort database and user:
sudo mysql -u root
CREATE DATABASE liteshort;
CREATE USER 'liteshortuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON liteshort.* TO 'liteshortuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace strongpassword with a strong password for the liteshortuser.
Step 5: Configure liteshort
Copy the example configuration file provided in the config directory and change the values accordingly:
cp config/config.example.ini config/config.ini
nano config/config.ini
Change the following parameters in the config.ini file:
database.host = "localhost"
database.username = "liteshortuser"
database.password = "strongpassword"
database.database = "liteshort"
Save and close the file.
Step 6: Install Composer and Dependencies
We will use Composer to manage the dependencies of liteshort. Run the following commands to install Composer:
sudo apt-get install composer -y
composer install
Step 7: Testing
Open your web browser and navigate to http://example.com/install (replace example.com with your domain name or IP address). Follow the instructions on the screen to complete the installation of liteshort.
Conclusion
In this tutorial, we have successfully installed liteshort on Ubuntu Server Latest, configured Apache or Nginx, created a MySQL database and user, configured liteshort, and tested the installation.