How to Install YOURLS on NixOS Latest
This tutorial will guide you through the process of installing YOURLS on NixOS Latest operating system. YOURLS is a free and open-source URL shortening and link tracking software. It allows users to create and manage their own custom short URLs.
Prerequisites
Before proceeding with the installation process, you must have the following prerequisites:
- A server running NixOS Latest
- Root access to the server
- Basic knowledge of Linux commands
Step 1 - Install required packages
The first step is to install the necessary packages required for YOURLS to work properly. Open your terminal and run the following command:
sudo nix-env -i php nginx mariadb phpMyAdmin
This command will install PHP, Nginx, MariaDB, and phpMyAdmin.
Step 2 - Create a database
Next, we need to create a database for YOURLS. Run the following command to log in to MySQL with root privileges:
sudo mysql -u root
Once you are logged in, run the following commands to create a new database and user for YOURLS:
CREATE DATABASE yourls;
CREATE USER 'yourlsuser'@'localhost' IDENTIFIED BY 'yourlspassword';
GRANT ALL PRIVILEGES ON yourls.* TO 'yourlsuser'@'localhost';
FLUSH PRIVILEGES;
Step 3 - Download and extract YOURLS
Now that we have installed the required packages and created a database, we can proceed to download YOURLS. Run the following command to download the latest version of YOURLS:
wget https://github.com/YOURLS/YOURLS/archive/refs/tags/1.7.12.tar.gz
Once the download is complete, extract the archive using the following command:
tar -zxvf 1.7.12.tar.gz
This will extract the YOURLS files in a directory named YOURLS-1.7.12.
Step 4 - Configure Nginx
The next step is to configure Nginx to serve YOURLS. Create a new server block in the Nginx configuration file by running the following command:
sudo nano /etc/nginx/sites-available/yourls.conf
Add the following configuration to the file:
server {
listen 80;
server_name yourls.example.com;
root /path/to/YOURLS-1.7.12;
index index.php;
location / {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
Replace yourls.example.com with your domain name and update the root path to the path where you extracted YOURLS files in Step 3.
Save and close the file.
Now symlink the new file to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/yourls.conf /etc/nginx/sites-enabled/
Step 5 - Configure YOURLS
Navigate to the YOURLS directory by running the following command:
cd /path/to/YOURLS-1.7.12
Copy the user/config-sample.php file to user/config.php using the following command:
cp user/config-sample.php user/config.php
Open the user/config.php file with your favorite text editor and modify the following lines:
define( 'YOURLS_DB_USER', 'yourlsuser' );
define( 'YOURLS_DB_PASS', 'yourlspassword' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_SITE', 'http://yourls.example.com' );
Replace yourlsuser and yourlspassword with the username and password you created in Step 2, and replace yourls with the name of the database you created.
Replace http://yourls.example.com with your domain name.
Save and close the file.
Step 6 - Test your installation
Restart Nginx and PHP-FPM using the following commands:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
Now access YOURLS by navigating to http://yourls.example.com in your web browser.
You should see the YOURLS welcome page, indicating that the installation was successful.
Conclusion
In this tutorial, you learned how to install YOURLS on NixOS Latest operating system. You also learned how to configure Nginx and YOURLS, and how to create a database for YOURLS to use. Good luck with your YOURLS installation!