Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
server_configuration:apache [2021/01/13 17:02] – david | server_configuration:apache [2025/04/02 09:49] (current) – david | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | So many problems with cache in browsers. | + | ====== Apache2 Configuration ====== |
- | Good to test with a browser which can have all data cleared, and do work in private browsing. | + | The configuration is built from a DigitalOcean Droplet, preconfigured with LAMP and WordPress: |
+ | * Droplet Information: | ||
+ | * The WordPress One-Click Quickstart guide: https://do.co/ | ||
- | Using wget to test the apache | + | ===== Core configuration |
+ | Note: If no site is " | ||
+ | |||
+ | Site configuration file location(s): | ||
<code bash> | <code bash> | ||
- | # Run a command to get the default page, and view the http redirects as returned by the server | + | # All configuration files |
- | wget --verbose datablog.roman-halliday.com | + | / |
- | # Reload apache configuration | + | # Enabled sites |
- | sudo service | + | /etc/apache2/ |
</ | </ | ||
- | https://www.digitalocean.com/ | + | Enable/ |
- | - https:// | + | <code bash> |
+ | # Disable | ||
+ | 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> | ||
+ | # Site content owned by www-data so webserver can modify files | ||
+ | chown -R www-data: | ||
- | ====== SSL - Let's Encrypt ====== | + | # Configuration owned by root for security |
- | + | chown -R root:root /etc/apache2 | |
- | How To Secure Apache with Let's Encrypt on Ubuntu 20.04 | + | </code> |
- | - https://www.digitalocean.com/community/ | + | |
+ | ===== Refresh Configuration ===== | ||
+ | Use one of: | ||
<code bash> | <code bash> | ||
- | certbot --apache | + | systemctl reload apache2 |
+ | service apache2 reload | ||
</ | </ | ||
+ | |||
+ | ===== SSL - Let's Encrypt ===== | ||
+ | SSL Encryption (the use of '' | ||
+ | |||
+ | * DigitalOcean Community Documentation: | ||
+ | |||
+ | If you configure the http (non secure) websites under ''/ | ||
<code bash> | <code bash> | ||
- | systemctl reload apache2 | + | certbot --apache |
- | service ssh reload | + | |
</ | </ | ||
- | < | + | ====== Apache2 Migration ====== |
- | # All configuration files | + | <code bash> |
- | / | + | ############################################################################### |
+ | # Backup | ||
+ | ################################################################################ | ||
- | # Enabled sites | + | cd / |
- | / | + | |
+ | sudo cp -r / | ||
+ | sudo cp -r /var/www . | ||
+ | sudo cp -r /etc/letsencrypt . | ||
</ | </ | ||
- | Make sure all files are owned correctly: | ||
<code bash> | <code bash> | ||
- | # Site content owned by www-data so webserver can modify | + | ################################################################################ |
- | chown -R ../ www-data: | + | # Fix hostname |
+ | ################################################################################ | ||
+ | sudo hostnamectl set-hostname roman-halliday | ||
+ | |||
+ | ################################################################################ | ||
+ | # Install LAMP Stack | ||
+ | ################################################################################ | ||
+ | sudo apt-get install apache2 libapache2-mod-php php-mysql php-pgsql | ||
+ | |||
+ | ################################################################################ | ||
+ | # MySQL - See : https://www.digitalocean.com/ | ||
+ | ################################################################################ | ||
+ | sudo apt-get install mysqld | ||
+ | ################################################################################ | ||
+ | # MySQL : Manage security setup script | ||
+ | |||
+ | ALTER USER ' | ||
+ | |||
+ | #> 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 / | ||
+ | |||
+ | 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 | ||
- | # Configuration owned by root | ||
- | chown -R ../ root:root / | ||
</ | </ | ||
+ | ====== Troubleshooting ====== | ||
- | Note: If no site is " | + | * https://help.servmask.com/ |
+ | |||
+ | |||
+ | ===== PHP testing page ===== | ||
Hosting can be tested with the file: | Hosting can be tested with the file: | ||
Line 61: | 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> |