Apache site setup basic
The steps you outlined are correct, but there are a few adjustments needed in your configuration to reflect the correct domain and directory names. Here is the corrected version:
Step-by-Step Instructions:
Create a directory for the new site:
sudo mkdir -p /var/www/html/sitename.com sudo chown -R $USER:$USER /var/www/html/sitename.com
Create an index.html file:
echo "<html><body><h1>Welcome to sitename.com!</h1></body></html>" | sudo tee /var/www/html/sitename.com/index.html
Create a new virtual host configuration file:
sudo nano /etc/apache2/sites-available/sitename.com.conf
Add the following content to the file:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/sitename.com ServerName sitename.com ServerAlias www.sitename.com ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined <Directory /var/www/html/sitename.com> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Enable the new site:
sudo a2ensite sitename.com.conf sudo systemctl reload apache2
Install Certbot (if not already installed):
sudo apt update sudo apt install certbot python3-certbot-apache -y
Run Certbot to obtain the SSL certificate:
sudo certbot --apache -d sitename.com -d www.sitename.com
Follow the prompts to complete the certificate installation.
Verification:
- Open a browser and navigate to
http://sitename.com
to ensure the site is working. - After obtaining the SSL certificate, navigate to
https://sitename.com
to ensure the SSL certificate is working.
This should help you set up your new site and obtain an SSL certificate. If you encounter any issues, let me know, and I will assist you further.
Please run the following command to obtain and install the SSL certificate:
sudo certbot certonly --apache -d el-switcheroo.scribbled.space -d www.el-switcheroo.scribbled.space
This command will attempt to obtain and install a new SSL certificate for your domain.
Once the certificate is obtained, update your Apache virtual host configuration to use SSL as mentioned before:
- Edit your Apache virtual host configuration file:
sudo nano /etc/apache2/sites-available/el-switcheroo.scribbled.space.conf
- Update the configuration to include the SSL settings:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/el-switcheroo.scribbled.space
ServerName el-switcheroo.scribbled.space
ServerAlias www.el-switcheroo.scribbled.space
ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log
CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =el-switcheroo.scribbled.space [OR]
RewriteCond %{SERVER_NAME} =www.el-switcheroo.scribbled.space
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
<Directory /var/www/html/el-switcheroo.scribbled.space>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/el-switcheroo.scribbled.space
ServerName el-switcheroo.scribbled.space
ServerAlias www.el-switcheroo.scribbled.space
ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log
CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/el-switcheroo.scribbled.space/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/el-switcheroo.scribbled.space/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
<Directory /var/www/html/el-switcheroo.scribbled.space>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
- Save and close the file.
- Reload Apache to apply the new configuration:
sudo systemctl reload apache2
Visit your domain in a browser to verify that the SSL certificate is working correctly. If you encounter any issues, please share the specific error messages or behavior you're experiencing.
2/2
root@ferociousbutterfly:~# ps aux | grep certbot root 116989 0.0 0.0 4020 2004 pts/8 S+ 03:44 0:00 grep –color=auto certbot certbot is not still running?
ChatGPT
Since certbot
is not running, you can safely proceed with obtaining the SSL certificate. Please run the following command to obtain and install the SSL certificate for your domain:
sudo certbot certonly --apache -d el-switcheroo.scribbled.space -d www.el-switcheroo.scribbled.space
This command will attempt to obtain and install a new SSL certificate for your domain using the Apache plugin.
If you encounter any issues or errors during this process, please provide the specific error messages so we can troubleshoot further.
Saving debug log to /var/log/letsencrypt/letsencrypt.log Requesting a certificate for el-switcheroo.scribbled.space and www.el-switcheroo.scribbled.space Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/el-switcheroo.scribbled.space/fullchain.pem Key is saved at: /etc/letsencrypt/live/el-switcheroo.scribbled.space/privkey.pem This certificate expires on 2024-10-03. These files will be updated when the certificate renews. Certbot has set up a scheduled task to automatically renew this certificate in the background. – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – If you like Certbot, please consider supporting our work by: * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate * Donating to EFF: https://eff.org/donate-le – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – root@ferociousbutterfly:~#
ChatGPT
Great! The SSL certificate for el-switcheroo.scribbled.space
has been successfully obtained and installed. Here are the next steps to ensure that your Apache server is correctly configured to use this new certificate:
Update the Virtual Host Configuration for HTTPS:
Create a new virtual host configuration file for HTTPS:
sudo nano /etc/apache2/sites-available/el-switcheroo.scribbled.space-ssl.conf
Add the following content to this file:
<VirtualHost *:443> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/el-switcheroo.scribbled.space ServerName el-switcheroo.scribbled.space ServerAlias www.el-switcheroo.scribbled.space ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined SSLEngine on SSLCertificateFile /etc/letsencrypt/live/el-switcheroo.scribbled.space/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/el-switcheroo.scribbled.space/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf <Directory /var/www/html/el-switcheroo.scribbled.space> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Enable the New Virtual Host Configuration and SSL Module:
sudo a2ensite el-switcheroo.scribbled.space-ssl.conf sudo a2enmod ssl sudo systemctl reload apache2
Redirect HTTP to HTTPS:
Update your existing HTTP virtual host configuration file (
/etc/apache2/sites-available/el-switcheroo.scribbled.space.conf
) to redirect HTTP traffic to HTTPS. Add the following lines within the<VirtualHost *:80>
block:RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
The updated configuration should look like this:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/el-switcheroo.scribbled.space ServerName el-switcheroo.scribbled.space ServerAlias www.el-switcheroo.scribbled.space ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L] <Directory /var/www/html/el-switcheroo.scribbled.space> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Reload Apache:
sudo systemctl reload apache2
This configuration will ensure that all HTTP requests are redirected to HTTPS and that your site is properly secured with the SSL certificate. Verify that your site is accessible over HTTPS by navigating to https://el-switcheroo.scribbled.space
in your web browser.
Create DB
- Log in to MySQL or MariaDB:
sudo mysql -u root -p
You'll be prompted to enter the root password for MySQL or MariaDB.
- Create the Database and User:
Once you're logged in to the MySQL or MariaDB command line, run the following commands:
CREATE DATABASE mat0moDbs3switcher0o;
CREATE USER 'spiffyswitcheroo'@'localhost' IDENTIFIED BY 'H0m0!508smp-fag';
GRANT ALL PRIVILEGES ON mat0moDbs3switcher0o.* TO 'spiffyswitcheroo'@'localhost';
FLUSH PRIVILEGES;
- Exit the MySQL or MariaDB Client:
EXIT;
After you've created the database and user, follow the steps provided previously to export the existing database and import it into the new one, then update the Matomo configuration file.
Moving a site
Got it. Here are the revised steps to move your Matomo site from ferociousbutterfly.com
to el-switcheroo.scribbled.space
:
Step 1: Backup the Website Files
Create a backup of your Matomo files:
sudo tar -czvf ferociousbutterfly_backup.tar.gz -C /var/www/html/ferociousbutterfly.com .
Move the backup to the new site's directory:
sudo mv ferociousbutterfly_backup.tar.gz /var/www/html/el-switcheroo.scribbled.space/
Extract the backup in the new site's directory:
cd /var/www/html/el-switcheroo.scribbled.space/ sudo tar -xzvf ferociousbutterfly_backup.tar.gz
Step 2: Backup the Database
Export the Matomo database:
mysqldump -u your_db_user -p your_db_name > ferociousbutterfly_db_backup.sql
Move the database backup to the new site's directory:
sudo mv ferociousbutterfly_db_backup.sql /var/www/html/el-switcheroo.scribbled.space/
Step 3: Create a New Database and Import the Backup
Create a new database and user (if needed):
CREATE DATABASE el_switcheroo_db; CREATE USER 'el_switcheroo_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON el_switcheroo_db.* TO 'el_switcheroo_user'@'localhost'; FLUSH PRIVILEGES;
Import the database backup into the new database:
mysql -u el_switcheroo_user -p el_switcheroo_db < /var/www/html/el-switcheroo.scribbled.space/ferociousbutterfly_db_backup.sql
Step 4: Update Configuration Files
Update the Matomo configuration file (
config/config.ini.php
) to reflect the new database settings:[database] host = "localhost" username = "el_switcheroo_user" password = "your_password" dbname = "el_switcheroo_db" tables_prefix = "matomo_"
Update any references to the old domain in your Matomo database.
mysql -u nsaffiliates -p; show databases; MOJO: use db_nsaffiliates; show tables;
MariaDB [db_nsaffiliates]> show tables; +—————————+ | Tables_in_db_nsaffiliates | +—————————+ | nsxxxmemberids | | peterfevernakedsword | | timvideovault | +—————————+
select * from nsxxxmemberids;
SELECT nsID FROM timvideovault WHERE timvvID = 1710003388;
You can run SQL commands to update the domain references:
UPDATE matomo_site SET main_url = 'http://el-switcheroo.scribbled.space' WHERE main_url = 'http://ferociousbutterfly.com';
Step 5: Update Apache Configuration
Update the Apache configuration for the new site.
Edit the
el-switcheroo.scribbled.space.conf
file to point to the new DocumentRoot:<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName el-switcheroo.scribbled.space ServerAlias www.el-switcheroo.scribbled.space DocumentRoot /var/www/html/el-switcheroo.scribbled.space <Directory /var/www/html/el-switcheroo.scribbled.space> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined </VirtualHost>
Enable the site and reload Apache:
sudo a2ensite el-switcheroo.scribbled.space.conf sudo systemctl reload apache2
Step 6: Test the New Site
Check that the new site is working: Visit
http://el-switcheroo.scribbled.space
in your browser and verify that everything is functioning correctly.Request a new SSL certificate for the new site:
sudo certbot --apache -d el-switcheroo.scribbled.space -d www.el-switcheroo.scribbled.space
These steps will move your Matomo site and its database to el-switcheroo.scribbled.space
, ensuring that all references and configurations are updated accordingly.
If you have deleted the database backup, you'll need to create a new backup from the original database and then import it into the new one. Here are the steps to do that:
Step 1: Create a New Database Backup
Log in to MySQL:
mysql -u root -p
Export the original database to a file:
mysqldump -u root -p original_database_name > /path/to/backup/ferociousbutterfly_db_backup.sql
Replace
original_database_name
with the name of your original Matomo database. Provide the root password when prompted.
Step 2: Import the Backup into the New Database
Create the new database and user if not already created:
CREATE DATABASE mat0moDbs3switcher0o; CREATE USER 'spiffyswitcheroo'@'localhost' IDENTIFIED BY 'H0m0!508smp-fag'; GRANT ALL PRIVILEGES ON mat0moDbs3switcher0o.* TO 'spiffyswitcheroo'@'localhost'; FLUSH PRIVILEGES;
Import the backup into the new database:
mysql -u spiffyswitcheroo -p mat0moDbs3switcher0o < /path/to/backup/ferociousbutterfly_db_backup.sql
Provide the password for
spiffyswitcheroo
when prompted.
Step 3: Update the URLs in the New Database
Log in to the new database:
mysql -u spiffyswitcheroo -p mat0moDbs3switcher0o
Update the Matomo URLs:
UPDATE matomo_site SET main_url = 'http://el-switcheroo.scribbled.space' WHERE main_url = 'http://ferociousbutterfly.com';
Step 4: Configure Apache for the New Site
Update the Apache configuration file for the new site:
sudo nano /etc/apache2/sites-available/el-switcheroo.scribbled.space.conf
Ensure it includes the following:
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName el-switcheroo.scribbled.space DocumentRoot /var/www/html/el-switcheroo.scribbled.space <Directory /var/www/html/el-switcheroo.scribbled.space> Options FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /var/www/html/el-switcheroo.scribbled.space/.well-known/acme-challenge> Options None AllowOverride None Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/el-switcheroo_error.log CustomLog ${APACHE_LOG_DIR}/el-switcheroo_access.log combined </VirtualHost>
Enable the new site and reload Apache:
sudo a2ensite el-switcheroo.scribbled.space.conf sudo systemctl reload apache2
Step 5: Request an SSL Certificate for the New Site
Request the certificate:
sudo certbot certonly --webroot -w /var/www/html/el-switcheroo.scribbled.space -d el-switcheroo.scribbled.space --dry-run
Once you have successfully created and imported the database backup, updated the URLs, configured Apache, and requested the SSL certificate, your Matomo site should be up and running on the new domain with HTTPS.