How to install MyBB on NixOS Latest

Step 1 - Enable NixOS Package manager:

Run the following command to enable NixOS package manager:

sudo nix-channel --add https://nixos.org/channels/nixos-21.05 nixos
sudo nix-channel --update

This will add the NixOS channel and update it.

Step 2 - Install MyBB:

To install MyBB, run the following command:

sudo nix-env -iA nixos.mybb

This installs MyBB package and its dependencies.

Step 3 - Create a database

You need to create a database for MyBB. We will use MariaDB as our database. To install MariaDB, run the following command:

sudo nix-env -iA nixos.mariadb

After installing MariaDB, run the following command to start the MariaDB server:

sudo systemctl start mariadb

Now, create a new database:

mysql -u root -p

Enter the password for the root user when prompted. Then, create a new database using the following command:

CREATE DATABASE mybb_db;

Create a new user and grant the necessary privileges:

CREATE USER 'mybb_user'@'localhost' IDENTIFIED BY 'mybb_password';
GRANT ALL PRIVILEGES ON mybb_db.* TO 'mybb_user'@'localhost';
FLUSH PRIVILEGES;

Exit from MySQL with the following command:

exit

Step 4 - Configure MyBB

Now it's time to configure MyBB. Navigate to the MyBB directory (/var/lib/mybb/) and rename the file inc/settings.php to inc/settings.php.bak:

cd /var/lib/mybb/
sudo mv inc/settings.php inc/settings.php.bak

Copy the default settings file to the inc directory:

sudo cp inc/settings.default.php inc/settings.php

Then edit the inc/settings.php file with a command-line text editor like Nano:

sudo nano inc/settings.php

Set the database details in the settings.php file:

$config['database']['type'] = 'mysqli';
$config['database']['database'] = 'mybb_db';
$config['database']['table_prefix'] = 'mybb_';
$config['database']['hostname'] = 'localhost';
$config['database']['username'] = 'mybb_user';
$config['database']['password'] = 'mybb_password';

Save and exit the file.

Step 5 - Configure your web server

Now you need to configure your web server to serve MyBB. Here's an example of how to configure the Nginx web server to serve MyBB:

First, install Nginx:

sudo nix-env -iA nixos.nginx

Then, edit the Nginx configuration file with a command-line text editor like Nano:

sudo nano /etc/nginx/nginx.conf

Set the Nginx configuration as follows:

user nginx;  # Use nginx as the user
worker_processes auto;  # Use auto to determine the number of worker processes
error_log /var/log/nginx/error.log;  # Set up error logging
pid /run/nginx.pid; # Set the PID file location
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types; # Load the MIME types
    default_type application/octet-stream; # Set the default type
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log main; # Set up access logging
    sendfile on; # Enable sendfile
    keepalive_timeout 65; # Set the keepalive timeout
    server {
        listen 80; # Listen on port 80
        server_name example.com; # Change 'example.com' to your domain name
        root /var/lib/mybb; # Set the root to the MyBB directory
        index index.php; # Set the index.php file as the default index file
        location / {
            try_files $uri $uri/ /index.php?$args; # Try to serve a file, then try a directory, then pass to index.php
        }
        location ~ \.php$ {
            try_files $uri =404; # Try to serve the PHP file or return a 404 error
            fastcgi_pass unix:/run/php-fpm/php-fpm.sock; # Use PHP-FPM to handle PHP files
            fastcgi_index index.php; # Set the index.php file as the default index file
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
       }
    }
}

Save and exit the file.

Restart Nginx:

sudo systemctl restart nginx

Step 6 - Launch MyBB

Now you can launch MyBB in your web browser by visiting your domain (or IP address). MyBB's default login and password are: admin and password respectively.

Congratulations! You have successfully installed MyBB on NixOS.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!