Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| server_configuration:apache [2021/01/13 15:44] – created david | server_configuration:apache [2025/04/02 09:49] (current) – david | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Apache2 Configuration ====== | ||
| + | The configuration is built from a DigitalOcean Droplet, preconfigured with LAMP and WordPress: | ||
| + | * Droplet Information: | ||
| + | * The WordPress One-Click Quickstart guide: https:// | ||
| + | ===== Core configuration ===== | ||
| + | Note: If no site is " | ||
| - | https:// | + | Site configuration file location(s): |
| - | - https://help.servmask.com/2018/ | + | <code bash> |
| + | # All configuration files | ||
| + | /etc/apache2/sites-available/ | ||
| - | | + | # Enabled sites |
| + | / | ||
| + | </ | ||
| - | ====== SSL - Let's Encrypt ====== | + | Enable/ |
| - | + | <code bash> | |
| - | How To Secure Apache with Let's Encrypt on Ubuntu 20.04 | + | # Disable |
| - | - https://www.digitalocean.com/ | + | sudo a2dissite datablog.roman-halliday.com.conf |
| + | # Enable | ||
| + | sudo a2ensite datablog.roman-halliday.com.conf | ||
| + | </ | ||
| + | ===== File Ownership ===== | ||
| + | Make sure all files are owned correctly: | ||
| <code bash> | <code bash> | ||
| - | certbot | + | # Site content owned by www-data so webserver can modify files |
| + | chown -R www-data: | ||
| + | |||
| + | # Configuration owned by root for security | ||
| + | chown -R root:root / | ||
| </ | </ | ||
| + | ===== Refresh Configuration ===== | ||
| + | Use one of: | ||
| <code bash> | <code bash> | ||
| systemctl reload apache2 | systemctl reload apache2 | ||
| - | service | + | service |
| </ | </ | ||
| - | < | + | ===== SSL - Let's Encrypt ===== |
| + | SSL Encryption (the use of '' | ||
| - | # All configuration files | + | * DigitalOcean Community Documentation: |
| - | /etc/apache2/sites-available/ | + | |
| - | # Enabled sites | + | If you configure the http (non secure) websites under '' |
| - | / | + | |
| + | <code bash> | ||
| + | certbot --apache | ||
| </ | </ | ||
| - | Make sure all files are owned correctly: | + | ====== Apache2 Migration ====== |
| <code bash> | <code bash> | ||
| - | # Site content owned by www-data so webserver can modify files | + | ################################################################################ |
| - | chown -R ../ www-data: | + | # Backup |
| + | ################################################################################ | ||
| - | # Configuration owned by root | + | cd / |
| - | chown -R ../ root: | + | |
| + | sudo cp -r / | ||
| + | sudo cp -r /var/www . | ||
| + | sudo cp -r /etc/letsencrypt . | ||
| </ | </ | ||
| + | <code bash> | ||
| + | ################################################################################ | ||
| + | # Fix hostname | ||
| + | ################################################################################ | ||
| + | sudo hostnamectl set-hostname roman-halliday | ||
| - | Note: If no site is " | + | ################################################################################ |
| + | # Install LAMP Stack | ||
| + | ################################################################################ | ||
| + | sudo apt-get install apache2 libapache2-mod-php php-mysql php-pgsql | ||
| + | |||
| + | ################################################################################ | ||
| + | # MySQL - See : https:// | ||
| + | ################################################################################ | ||
| + | sudo apt-get install mysqld | ||
| + | ################################################################################ | ||
| + | # MySQL : Manage security setup script | ||
| + | |||
| + | ALTER USER 'root'@' | ||
| + | |||
| + | #> I wasn’t able to login to mysql with sudo mysql after running ALTER USER ' | ||
| + | #> I fixed this by logging it with mysql -p, then running ALTER USER ' | ||
| + | |||
| + | ALTER USER ' | ||
| + | |||
| + | FLUSH PRIVILEGES; | ||
| + | |||
| + | SELECT * FROM mysql.user \G | ||
| + | SELECT Host, User, plugin, password_last_changed FROM mysql.user \G | ||
| + | |||
| + | sudo systemctl restart mysql | ||
| + | |||
| + | # Uninstall (if you borked it) | ||
| + | sudo apt remove --purge mysql\* -y | ||
| + | sudo find / -name mysql | ||
| + | |||
| + | |||
| + | ################################################################################ | ||
| + | # WordPress requirements: | ||
| + | sudo apt-get install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip | ||
| + | |||
| + | ################################################################################ | ||
| + | # Firewall | ||
| + | ################################################################################ | ||
| + | sudo ufw allow Apache Full | ||
| + | |||
| + | |||
| + | ################################################################################ | ||
| + | # Backup (original configurations/ | ||
| + | ################################################################################ | ||
| + | sudo apt-get install bzip2 | ||
| + | mkdir -p ~/backups | ||
| + | sudo tar -cjf ~/ | ||
| + | sudo tar -cjf ~/ | ||
| + | sudo tar -cjf ~/ | ||
| + | |||
| + | ################################################################################ | ||
| + | # Restore Files (from backup) | ||
| + | ################################################################################ | ||
| + | |||
| + | cd /mnt/ | ||
| + | |||
| + | sudo cp -r apache2 / | ||
| + | sudo cp -r www /var/www | ||
| + | sudo cp -r letsencrypt / | ||
| + | |||
| + | sudo chown -R www-data: | ||
| + | |||
| + | ################################################################################ | ||
| + | # Restore Configs - letsencrypt | ||
| + | # Also see: | ||
| + | # | ||
| + | # | ||
| + | ################################################################################ | ||
| + | |||
| + | # View dir | ||
| + | cd / | ||
| + | # Migrate backup | ||
| + | cp -r / | ||
| + | |||
| + | ################################################################################ | ||
| + | # Find apache2 log directories | ||
| + | ################################################################################ | ||
| + | # List all | ||
| + | find / | ||
| + | find / | ||
| + | find / | ||
| + | |||
| + | # Get path names | ||
| + | find / | ||
| + | |||
| + | ################################################################################ | ||
| + | # Create missing | ||
| + | ################################################################################ | ||
| + | sudo mkdir -p / | ||
| + | |||
| + | sudo chown -R root:adm / | ||
| + | |||
| + | sudo ls -lh / | ||
| + | ################################################################################ | ||
| + | # Make DNS Changes | ||
| + | ################################################################################ | ||
| + | # Enable sistes | ||
| + | ################################################################################ | ||
| + | # Get site names (without SSL version) | ||
| + | find / | ||
| + | |||
| + | # Enable | ||
| + | sudo a2ensite david-halliday.co.uk.conf | ||
| + | |||
| + | # Disable | ||
| + | sudo a2dissite david-halliday.co.uk.conf | ||
| + | |||
| + | # Restart Apache | ||
| + | sudo systemctl reload apache2 | ||
| + | |||
| + | ################################################################################ | ||
| + | # Refresh certificates (letsencrypt) | ||
| + | ################################################################################ | ||
| + | sudo certbot --apache | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== Troubleshooting ====== | ||
| + | |||
| + | * https:// | ||
| + | |||
| + | |||
| + | ===== PHP testing page ===== | ||
| Hosting can be tested with the file: | Hosting can be tested with the file: | ||
| Line 51: | Line 206: | ||
| </ | </ | ||
| + | ===== Managing Page redirects/ | ||
| + | So many problems with cache in browsers. Good to test with a browser which can have all data cleared, and do work in private browsing. | ||
| + | |||
| + | Using wget to test the apache configuration, | ||
| + | |||
| + | <code bash> | ||
| + | # Run a command to get the default page, and view the http redirects as returned by the server | ||
| + | wget --verbose datablog.roman-halliday.com | ||
| + | |||
| + | # Reload apache configuration | ||
| + | sudo service apache2 reload | ||
| + | </ | ||
| - | ====== Bug: extra index ====== | + | ===== Bug: extra index ===== |
| I had an extra '' | I had an extra '' | ||
| <code html> | <code html> | ||