How to Replace a String in Multiple Files in a Linux Folder?
written by sysadmin | 17 January 2026
I want to replace a string that is in multiple files in a Linux folder.
Problem
How to replace a string in multiple files in a Linux folder?
Solution
For example, I want to search for the database.php word scattered across multiple PHP files in a folder, and I use the Linux command below:
grep -R database.php *
Find the string in multiple folders
In the image above, the word is scattered across multiple Linux files and in different Linux folders. So that you don’t go into the file that is in a different folder one by one and then change the word database.php, for example, to config.php manually, but you can run the command below:
find . -type f -name "*.php" -exec sed -i 's/database\.php/config.php/g' {} +
which results in the image below:
Replace the string in multiple folders
In the image above, you can see that the word has been successfully changed to config.php, which is not found when you search for database.php. If you just change the database.php word to config.php in a folder, as shown in the image below:
Find the string in a folder
You can use the format below to replace the word:
sed -i's/old_word/new_word/g' filename
So you can run the command below to change the word database.conf to config.php
sed -i 's/database\.php/config.php/g' *.php
So it will look like the image below:
Replace the string in a folder
In the image above, you can see that the string database.php has been changed to config.php.
Note
If you’re still unsure about running the two commands above to change a word scattered across multiple files, you can preview the results you expect. For example, if you want to preview the results first before you permanently change the changes in a folder, then you can run the command below:
sed 's/database\.php/config.php/g' *.php | grep database.php
and the result will be as shown in the image below:
Preview the result
And if you want to automatically back up when changing a string in multiple files, then use the command below:
sed -i.bak 's/database\.php/config.php/g' *.php
Then the result will be as shown in the image below:
Back up the file(s) automatically
In the image, you can see that files that have the word database.php are automatically backed up to files with the .bak extension.
Akses ke MariaDB dan jalankan query-query di Bawah ini:
CREATE DATABASE uptime_kuma;
CREATE USER 'kuma-user'@'%' IDENTIFIED BY 'kumapass123';
GRANT ALL PRIVILEGES ON uptime_kuma.* TO 'kuma-user'@'%';
FLUSH PRIVILEGES;
\q
3. Configure web server
If you use Apache, create a file at /etc/apache2/sites-available/kuma.conf and copy the script below to the file:
Check if there is an error in Apache and if there is no error, reload Apache using the command below:
apachectl -t
sudo systemctl reload apache2
INFO
If your server is running an nginx webserver, then in the file /etc/nginx/conf.d/uptime-kuma.conf insert the script below:
server {
listen 80;
server_name uptime-kuma.yourdomainname.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Added WebSocket support
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
# Improve performance of this reverse proxy
proxy_buffering off;
}
# Redirect HTTP to HTTPS if needed for encryption
# Uncomment the following lines if you have SSL enabled
# return 301 https://$host$request_uri;
}
Use the command below to check if there is an error in the nginx configuration and then reload nginx:
sudo nginx -t
sudo systemctl reload nginx
4. Access uptime kuma
Open your browser, and type:
http://ip_server:3001
then there will be a display like below:
Click the MariaDB/MySQL button
Click MariaDB/MySQL, your screen will appear similar to the picture below:
Fill in the columns for the database
Enter in the columns above the values that correspond to the query commands. Click the Next button, your screen will show up similar to the one below:
Setting up the database
You have to wait until finish, and after that, your screen will appear similar to the image shown below:
Fill in the columns for the admin account
Enter in the columns above the value you want and press the Create button then a display will appear similar to the image provided below:
Display of uptime kuma application
If you want to monitor the website, click the Add New Monitor button at the top left of the site , an image similar to the one shown will appear:
Create a new host or a website to monitor in uptime kuma
Fill in the required fields (at least fill in the Monitor Type, Friendly Name, and URL columns) and press the Save button, then the host you have filled in will look like in the image below:
Monitor the host
If you just want to display the status without displaying many attributes then you can click the Status Pages button at the top right of the site like the image below:
Click the Status Pages button
After you press the Status Pages button, the following image will appear:
Create the Status Page page
Click the New Status Page button, and an image will appear similar to the one shown below:
Create the Status Page page
Enter the name and slug you want (I wrote the sites for the name and slug), then press the Next button, then there will be a display as below:
Insert the host or the monitor in the Status Page
Enter the host you want to display on the Status Page, after that click the Save button, then there will be a display as below:
Display of Status Page
You can see that the hosts to be monitored look simpler and you can give the URL to other parties to also monitor these hosts.
Note
If you want to check the status of uptime kuma in the server, run the command below :
sudo pm2 status server/server.js --name uptime-kuma
Check the status of uptime kuma
But if you want stop uptime kuma in the server, run the command below :
How to Install Uptime Kuma in Docker with MariaDB on the Host?
written by sysadmin | 17 January 2026
The previous article explained how to install the Kuma uptime application using Docker and using the MariaDB database which also runs on Docker. This article will explain about installing the Kuma uptime application using Docker but using MariaDB on the host.
Problem
How to install uptime kuma in docker with MariaDB on the host?
Solution
Here are the steps to install the kuma uptime application using docker but using MariaDB on the host:
1. Configure MariaDB
Make sure you have installed the MariaDB database on your server and then change the file /etc/mysql/mariadb.conf.d/50-server.cnf in the bind-address section to be as below:
bind-address = 0.0.0.0
Next, restart MariaDB using the command:
sudo systemctl restart mariadb
After that, access to MariaDB and run the command below:
CREATE DATABASE uptime_kuma;
CREATE USER 'kuma-user'@'%' IDENTIFIED BY 'kumapass123';
GRANT ALL PRIVILEGES ON uptime_kuma.* TO 'kuma-user'@'%';
FLUSH PRIVILEGES;
\q
2. Create a docker compose file
Create a compose folder in the /opt folder using the command below:
sudo mkdir -p /opt/compose/uptime-kuma/
cd /opt/compose/uptime-kuma/
After that, create a docker-compose.yaml file and copy the script below:
Check if there is an error in Apache and if there is no error, reload Apache using the command below:
apachectl -t
sudo systemctl reload apache2
INFO
If your server is running an nginx webserver, then in the file /etc/nginx/conf.d/uptime-kuma.conf insert the script below:
server {
listen 80;
server_name uptime-kuma.yourdomainname.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Added WebSocket support
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
# Improve performance of this reverse proxy
proxy_buffering off;
}
# Redirect HTTP to HTTPS if needed for encryption
# Uncomment the following lines if you have SSL enabled
# return 301 https://$host$request_uri;
}
Use the command below to check if there is an error in the nginx configuration and then reload nginx:
sudo nginx -t
sudo systemctl reload nginx
4. Access uptime kuma
Open your browser, and type:
http://ip_server:3001
then there will be a display like below:
Fill in the columns for the admin account
Enter in the columns above the value you want and press the Create button then a display will appear similar to the image provided below:
Display of uptime kuma
If you want to make sure uptime kuma use MariaDB database, run the command below:
docker logs uptime-kuma | grep DB
Your screen will appear similar to the picture shown below:
Check the running database
If you want to monitor the website, click the Add New Monitor button at the top left, an image similar to the one shown will appear:
Create a new host or a website to monitor in uptime kuma
Fill in the required fields (at least fill in the Monitor Type, Friendly Name, and URL columns) and press the Save button, then the host you have filled in will look like in the image below:
Monitor the host or the website
If you just want to display the status without displaying many attributes then you can click the Status Pages button at the top right of the site like the image below:
Click the Status Page button
After you press the Status Page button, the following image will appear:
Create the Status Page page
Click the New Status Page button, and an image will appear similar to the one shown below:
Create the Status Page page
Enter the name and slug you want (I wrote the sites for the name and slug), then press the Next button, then there will be a display as below:
Insert the host or the monitor in the Status Page
Enter the host you want to display on the Status Page, after that click the Save button, then there will be a display as below:
Display of Status Page
You can see that the hosts to be monitored look simpler and you can give the URL to other parties to also monitor these hosts.
Note
Go to this page if you want to backup the MariaDB database and for how to restore the database, you can go to this page.
How to Backup And Restore Uptime Kuma Database in Docker?
written by sysadmin | 17 January 2026
The previous article explained how to install Uptime Kuma using Docker on Linux. This article will explain how to back up and restore the Kuma uptime database in Docker.
Problem
How to back up and restore the Uptime Kuma database in Docker?
Solution
Below are the steps to back up and restore the Uptime Kuma database in Docker:
A. Database SQLite
Here is the method to back up and restore a SQLite database in Docker:
1. Backup database
If you want to back up the Uptime Kuma database in Docker, you can run the command below to get the Kuma database on your host:
docker run --rm
-v uptime-kuma:/data
-v $(pwd):/backup
alpine tar czf /backup/kuma-backup.tar.gz /data
After that, look in your current folder; the database should appear like the image below:
Back up the uptime Kuma database
However, if you want to back up automatically, then follow the steps below:
a. Create a backup folder on the host
Run the commands below to create a backup folder in the host:
Before you restore the database, make sure the container has been running first. If you want to restore the Uptime Kuma database that you have previously backed up, then you can run the command below on the host:
docker run --rm \
-v uptime-kuma:/data \
-v /opt/kuma-backup:/backup \
alpine \
tar xzf /backup/kuma-backup-YYYYMMDD-HHMMSS.tar.gz -C /
If the restore process is complete, the hosts that were monitored in the previous container should be monitored again by the new container.
B. Database MariaDB
Here is the method to back up and restore a MariaDB database in Docker:
1. Backup database
If you want to back up the MariaDB database in Docker, you can run the command below to get the database on your host:
And you can insert the script above in the crontab.
2. Restore database
Before you restore the database, make sure the container has been running first. If you want to restore the database that you have previously backed up, then you can run the command below on the host:
The previous article explained how to install the Uptime Kuma application using Docker. However, by default, Uptime Kuma uses a SQLite database, and you want to change the database to MariaDB for some reasons.
Problem
How to install Uptime Kuma and MariaDB in Docker?
Solution
Although SQLite serves as a superb embedded database option for numerous scenarios, certain inherent limitations render it inappropriate for particular applications. If your application has a large amount of traffic and uses a lot of write modes simultaneously, and the data growth is very fast, your application is not suitable for using a SQLite database. Likewise, with the Uptime Kuma application. If you monitor many hosts using low intervals, it will cause very fast data growth, so you have to think about another database solution besides the SQLite database.
1. Create a Docker Compose file
Create a compose folder in the /opt folder using the command below:
sudo mkdir -p /opt/compose/uptime-kuma/
cd /opt/compose/uptime-kuma/
After that, create docker-compose.yaml file and copy the script below:
Check if there is an error in Apache, and if there is no error, reload Apache using the command below:
apachectl -t
sudo systemctl reload apache2
INFO
If your server is running an nginx webserver, then in the file /etc/nginx/conf.d/uptime-kuma.conf insert the script below:
server {
listen 80;
server_name uptime-kuma.yourdomainname.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Added WebSocket support
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
# Improve performance of this reverse proxy
proxy_buffering off;
}
# Redirect HTTP to HTTPS if needed for encryption
# Uncomment the following lines if you have SSL enabled
# return 301 https://$host$request_uri;
}
Use the command below to check if there is an error in the nginx configuration and then reload nginx:
sudo nginx -t
sudo systemctl reload nginx
3. Access uptime kuma
Open your browser, and type:
http://ip_server:3001
Then there will be a display like below:
Choose MariaDB/MySQL
Click MariaDB/MySQL, and your screen will appear similar to the picture below:
Fill in the columns for the database
Enter in the columns above the values that correspond to the .env file. Click the Next button, and your screen will show up similar to the one below:
Setting up the database
You have to wait until finishes, and after that, your screen will appear similar to the image shown below:
Fill in the columns for the admin account
Enter in the columns above the value you want and press the Create button, then a display will appear similar to the image provided below:
Display of uptime kuma
If you want to make sure Uptime Kuma uses a MariaDB database, run the command below:
docker logs uptime-kuma | grep DB
Your screen will appear similar to the picture shown below:
Check the running database
If you want to monitor the website, click the Add New Monitor button at the top left of the site, and an image similar to the one shown will appear:
Create a new host or a website to monitor in Uptime Kuma
Fill in the required fields (at least fill in the Monitor Type, Friendly Name, and URL columns) and press the Save button, then the host you have filled in will look like in the image below:
Monitor the host or the website
If you just want to display the status without displaying many attributes, then you can click the Status Pages button at the top right of the site, like the image below:
Click the Status Page button
After you press the Status Page button, the following image will appear:
Create the Status Page page
Click the New Status Page button, and an image will appear similar to the one shown below:
Create the Status Page page
Enter the name and slug you want (I wrote the sites for the name and slug), then press the Next button, and then there will be a display as below:
Insert the host or the monitor in the Status Page
Enter the host you want to display on the Status Page, after that, click the Save button, then there will be a display as below:
Display of Status Page
You can see that the hosts to be monitored look simpler, and you can give the URL to other parties to also monitor these hosts.
Note
If you want to back up the MariaDB database running on Docker and learn how to restore the database, you can go to this page.
Uptime Kuma is a self-hosted monitoring solution created to measure the uptime and performance of websites and services. It offers live status updates, flexible alerting choices, and comprehensive metrics to help guarantee that your websites and services stay functional.
This article will explain how to install Kuma using Docker.
1. Install uptime kuma
Make sure you installed Docker in your server and you can see how to install Docker on this page. After that, run the command below to install uptime kuma using docker:
Check if there is an error in apache and if there is no error, reload apache using the command below:
apachectl -t
sudo systemctl reload apache2
INFO
If your server is running an nginx webserver, then in the file /etc/nginx/conf.d/uptime-kuma.conf insert the script below:
server {
listen 80;
server_name uptime-kuma.yourdomainname.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Added WebSocket support
proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
# Improve performance of this reverse proxy
proxy_buffering off;
}
# Redirect HTTP to HTTPS if needed for encryption
# Uncomment the following lines if you have SSL enabled
# return 301 https://$host$request_uri;
}
Use the command below to check if there is an error in the nginx configuration and then reload nginx:
nginx -t
sudo systemctl reload nginx
3. Configure database
If you install uptime kuma using docker, you don’t need to install the database because in the docker there is already a SQLite database where you can view it by using the command below:
docker exec -it uptime-kuma ls /app/data
Check the database in the uptime kuma container
4. Access uptime kuma
Open your browser, and type:
http://ip_server:3001
then there will be a display like below:
Create username and password for Uptime Kuma
Enter the username and password you want then press the Create button, there will be a display as below:
Display of uptime kema application
If you want to monitor a host or a website, click the Add New Monitor button like in the below image:
Create a new host or a website to monitor in uptime kuma
Fill in the required fields (at least fill in the Monitor Type, Friendly Name, and URL columns) and press the Save button, then the host you have filled in will look like in the image below:
Monitor the host or the website
If you just want to display the status without displaying many attributes then you can click the Status Pages button at the top right of the layer then there will be a display like below:
Click the New Status Page button
Click the New Status page button, then there will be a display as below:
Create the Status Page page
Enter the name and slug you want (I wrote the sites for the name and slug), then press the Next button, then there will be a display as below:
Insert the host or the monitor in the Status Page
Enter the host you want to display on the Status Page, after that click the Save button, then there will be a display as below:
Display of Status Page
You can see that the hosts to be monitored look simpler and you can give the URL to other parties to also monitor these hosts.
Note
If you want to backup the uptime kuma database running on docker and how to restore the database, you can go to this page.
The previous article explained how to install phpMyAdmin with the nginx web server. This article will explain how to protect phpMyAdmin from unauthorized users using nginx.
Problem
How to protect phpMyAdmin using nginx?
Solution
There are several methods to protect phpMyAdmin using nginx:
1. Allowing certain IPs
The phpMyAdmin application can only be accessed by users who have certain IP addresses. For example, you want the IP localhost, and only 192.168.56.1 to be able to access phpMyAdmin. Then add the script below to the /etc/nginx/sites-available/default file in the location /phpmyadmin section:
allow 127.0.0.1;
allow 192.168.56.1;
deny all;
For more details, take a look at the image below:
Allowing certain IPS
After that, use the command below to reload nginx:
sudo nginx -t
sudo systemctl reload nginx
If any user who uses an IP other than the localhost and 192.168.56.1 wants to access phpMyAdmin, then that user will not be able to access phpMyAdmin, as shown in the image below:
Forbidden access
2. Add a password
To make it safer, phpMyAdmin should be given additional HTTP Auth so that users who want to access the application must enter a password. Use the command below to install HTTP auth:
so that the default file changes to look like the image below:
Change the URL in Nginx
Use the command below to reload nginx:
sudo nginx -t
sudo systemctl reload nginx
Open http://ip_server/pma in your browser, then you should be able to access phpMyAdmin as in the image below:
Change the URL
Note
There is one more method so that your phpMyAdmin application can be secure, namely, using SSL. You can use a Let’s Encrypt SSL certificate for your phpMyAdmin site because the certificate is free. However, if you want the phpmyadmin application not to be accessed by the public, I think, then there is no need to use SSL.