This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
computing:selfhostedwp [2023/06/29 04:16] – oemb1905 | computing:selfhostedwp [2023/06/29 06:09] – oemb1905 | ||
---|---|---|---|
Line 11: | Line 11: | ||
------------------------------------------- | ------------------------------------------- | ||
- | This tutorial is for setting up a self-hosted WordPress instance on Debian GNU/ | + | This tutorial is for setting up a self-hosted WordPress instance on Debian GNU/Linux. This tutorial assumes you have some familiarity setting up a LAMP stack. If you need help with that, check out [[https:// |
- | sudo apt install php-common php-cgi php-cli php-zip php-mysql php-mbstring php-intl php-fpm php-curl php-gd php-imagick php-xml php-xmlrpc php-soap php-opcache php-apcu php-bcmath memcached wget unzip | + | sudo apt install |
| | ||
- | Alternately, you can specify the php version as follows: | + | Sometimes dpkg can choose which version of php you want and it's not always the version you want. In those cases, you can explicitly |
| | ||
sudo apt-get install php8.2-{common, | sudo apt-get install php8.2-{common, | ||
| | ||
- | Okay, let' | + | Apache2 will set up a 000-default.conf automatically and your host should now resolve. Be sure to set up TLS with certbot. Here' |
+ | |||
+ | sudo apt install certbot letsencrypt python3-certbot-apache | ||
+ | sudo certbot --authenticator standalone --installer apache -d site1.com --pre-hook " | ||
+ | crontab -e | ||
+ | <30 2 * * 1 / | ||
+ | |||
+ | Once you have the LAMP stack setup and TLS properly configured, it's time to make some decisions on your php handler | ||
| | ||
+ | sudo apt remove libapache2-mod-php* --purge | ||
+ | sudo a2enmod ssl | ||
+ | sudo a2enmod headers | ||
+ | sudo a2enmod cache | ||
sudo a2enmod rewrite | sudo a2enmod rewrite | ||
+ | sudo a2enmod setenvif | ||
+ | sudo a2dismod php8.2 | ||
+ | sudo a2dismod mpm_prefork | ||
+ | sudo a2enmod mpm_event | ||
+ | sudo a2enmod proxy | ||
sudo a2enmod proxy_fcgi | sudo a2enmod proxy_fcgi | ||
- | sudo a2enconf | + | sudo a2enconf |
+ | sudo a2enconf php8.2-cgi | ||
sudo apache2ctl configtest | sudo apache2ctl configtest | ||
- | | + | sudo systemctl restart |
- | Move index.php to the top priority as follows: | + | |
- | + | ||
- | | + | |
- | | + | |
- | + | ||
- | Optionally, we can install phpmyadmin, and if you do, you should secure as follows: | + | |
+ | There are two standard ways to configure php-fpm. One of those is to use ProxyPassReverse, | ||
+ | |||
+ | < | ||
+ | SetHandler " | ||
+ | </ | ||
+ | |||
+ | That takes care of configuring php-fpm and mpm_event. Before proceeding, navigate to your tld.domain in a web browser and make sure that your site resolves properly. If it does not, then you should debug your setup. To do that, there' | ||
+ | |||
+ | sudo apachectl -M | grep ' | ||
+ | sudo apachectl -M | grep ' | ||
+ | sudo apache2ctl configtest | ||
+ | |||
+ | The output of mpm should show mpm_event and the output of proxy grep should show proxy_module and proxy_fcgi_module in use. If not, trace back over the steps above and see what went wrong. As for configtest, it should either tell you what's wrong or return " | ||
+ | |||
+ | sudo apt install phpmyadmin | ||
sudo htpasswd -c / | sudo htpasswd -c / | ||
- | sudo nano / | + | sudo nano / |
- | + | ||
- | Enter the following in the file that opens: | + | |
- | + | ||
< | < | ||
< | < | ||
< | < | ||
<Require valid-user> | <Require valid-user> | ||
+ | |||
+ | If you don't need something as heavy as phpmyadmin, you can optionally create a phpinfo page instead: | ||
+ | |||
+ | sudo nano / | ||
+ | sudo htpasswd -c / | ||
+ | sudo nano / | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <Require valid-user> | ||
+ | |||
+ | Use these tools to make sure your handler and multi-processing module are configured to your preference and functional. After that's all working, let's make sure that your WordPress index.php is set to top priority as follows: | ||
| | ||
- | Close and save the file. Let's set up a database now for the WordPress instance: | + | sudo nano / |
+ | < | ||
+ | |||
+ | Close and save the file. Let' | ||
sudo mysql -u root -p | sudo mysql -u root -p | ||
Line 51: | Line 90: | ||
EXIT; | EXIT; | ||
- | Next up, it is time to allow overrides in your primary apache configuration: | + | Next up, it is time to allow overrides in your primary apache configuration. This is optional but/and it allows WordPress extensions to make configuration changes to .htaccess and/or other changes to the web server. It's often helpful, but you can leave it off if you prefer and configure everything manually. |
sudo nano / | sudo nano / | ||
- | < | ||
< | < | ||
| | ||
- | If you have not set the fully qualified domain name, you may get an error - that can safely be ignored unless you desire it. If you want to get rid of that, navigate to ''/ | + | Let's now shell into our instance |
+ | ssh root@wordpress.com | ||
+ | mkdir Downloads | ||
cd ~/Downloads | cd ~/Downloads | ||
mkdir wpdownload | mkdir wpdownload | ||
Line 73: | Line 113: | ||
sudo mv ~/ | sudo mv ~/ | ||
- | Now, let's set up permissions | + | When the website is in production, use these permissions: |
- | sudo chown -R www-data: | + | sudo chown -R www-data: |
sudo find / | sudo find / | ||
sudo chmod 755 / | sudo chmod 755 / | ||
Line 81: | Line 121: | ||
sudo chmod -R 755 / | sudo chmod -R 755 / | ||
- | Ok, time to grab ' | + | It's now time to configure your '' |
| | ||
curl -s https:// | curl -s https:// | ||
sudo nano / | sudo nano / | ||
+ | <Replace the example salts with those you just downloaded using copy/ | ||
| | ||
- | Let's also add the following line to the '' | + | Sometimes, for reasons I am not sure about, WordPress does not allow users direct uploading. If/when that happens, |
sudo nano / | sudo nano / | ||
< | < | ||
- | Visit wordpress site and configure by opening | + | Let's now visit site1.com in a web browser. |
- | + | ||
- | apt install memcached | + | |
- | nano /etc/ | + | |
- | a2enmod cache | + | |
- | + | ||
- | Put this snippet under ''# | + | |
- | + | ||
- | sudo systemctl restart proftpd.service | + | |
- | + | ||
- | Optimizing and securing WordPress usually boils down to some cache and header settings. Cache and/or page expiry settings: | + | |
apt install memcached | apt install memcached | ||
Line 166: | Line 197: | ||
</ | </ | ||
- | Personally, I don't think anyone should be using ftp or even sftp right now, but many still do. If so, here' | + | Personally, I don't think anyone should be using ftp. Sftp is fine, and if someone needs that, here's an example of a simple |
- | + | ||
- | You can optionally require an sftp server instead of using the default installer. | + | |
sudo apt install proftpd ftp ftp-ssl | sudo apt install proftpd ftp ftp-ssl | ||
+ | sudo a2enmod tls | ||
cd / | cd / | ||
sudo openssl req -new -x509 -days 7305 -nodes -out ftpd-rsa.pem -keyout ftpd-rsa-key.pem | sudo openssl req -new -x509 -days 7305 -nodes -out ftpd-rsa.pem -keyout ftpd-rsa-key.pem | ||
sudo nano / | sudo nano / | ||
- | | + | |
| | ||
+ | Next, enter the TLS module in tls.conf underneath ''# | ||
+ | |||
+ | sudo nano / | ||
< | < | ||
| | ||
Line 188: | Line 221: | ||
| | ||
</ | </ | ||
+ | sudo systemctl restart proftpd.service | ||
+ | | ||
+ | Refresh WordPress and it should see the sftp server and allow you to make changes that way. Note: The sftp server is public and anyone can access this with proper credentials even if it not for WordPress so use a proper password and make sure your TLS configuration is working. Your instance should now be pretty solid. The only other thing you might want is more than one WordPress site subdomain, for example, site1.cooldomain.com, | ||
- | --- // | + | --- // |