User Tools

Site Tools


computing:selfhostedwp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
computing:selfhostedwp [2023/06/29 04:29] oemb1905computing:selfhostedwp [2023/06/29 05:11] oemb1905
Line 19: Line 19:
   sudo apt-get install php8.2-{common,cgi,cli,zip,mysql,mbstring,intl,fpm,curl,gd,imagick,xml,xmlrpc,gpm,soap,opcache,apcu,bcmath}   sudo apt-get install php8.2-{common,cgi,cli,zip,mysql,mbstring,intl,fpm,curl,gd,imagick,xml,xmlrpc,gpm,soap,opcache,apcu,bcmath}
      
-In this particular configuration, I am not using libapache2-mod-php. Instead I am using mpm_event and php-fpm. This is not necessary for many smaller instances or self-hosted scenarios. If you are new to self-hosting, then in addition to the above steps, you should do ''sudo apt install libapache2-mod-php8.x'' and ignore the fpm-based steps below.+Apache2 will set up a 000-default.conf automatically and your host should now resolve. Be sure to set up TLS with certbot. Here's my preferred method: 
 + 
 +  sudo apt install certbot letsencrypt python3-certbot-apache 
 +  sudo certbot --authenticator standalone --installer apache -d wordpress.com --pre-hook "systemctl stop apache2" --post-hook "systemctl start apache2" 
 +  crontab -e 
 +  <30 2 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log> 
 +   
 +Once you have the LAMP stack setup and TLS properly configured, it's time to make some decisions on your php handler and your apache2 multi-processing module (mpm). There's extensive debate on this which you can read up on [[https://www.datadoghq.com/blog/monitoring-apache-web-server-performance/#prefork-mpm|here]]. In this tutorial, I've chosen not to use mpm_prefork and libapache2-mod-php. Instead I am using mpm_event and php-fpm. This is not necessary for many smaller instances or self-hosted scenarios. If you are new to self-hosting, simply run ''sudo apt install libapache2-mod-php8.x'' and remove the php-fpm and mpm_event steps below.
      
   sudo apt remove libapache2-mod-php --purge   sudo apt remove libapache2-mod-php --purge
Line 37: Line 44:
   sudo systemctl restart apache2   sudo systemctl restart apache2
   sudo systemctl restart php8.2-fpm   sudo systemctl restart php8.2-fpm
-   
-Move index.php to the top priority as follows: 
-   
-  sudo nano /etc/apache2/mods-enabled/dir.conf 
-  <DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm> 
-   
-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, however, this will disable the use of .htaccess in your WordPress root which is not ideal. The next common way which I prefer and use here, is to add a FilesMatch condition to your virtual host as follows. Within the <Include> and </Include> portion of your default-ssl.conf virtual host, add something like:
 +
 +  <FilesMatch ".+\.ph(ar|p|tml)$">
 +      SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost"
 +  </FilesMatch>
 +
 +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's three tools that can help: phpmyadmin, phpinfo page, and configuration checking. If your page does not even resolve, your first recourse should be to check the php handler, multi-processing modules, and your apache config files:
 +
 +  sudo apachectl -M | grep 'mpm'
 +  sudo apachectl -M | grep 'proxy'
 +  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 "Syntax OK". If the output of the above commands is incorrect and/or you simply want a graphical way to check your handler and mult-processing module, then you can either create a phpinfo page or install phpadmin. There are many additional benefits to using phpmyadmin, so let's review how to install that first:
 +
 +  sudo apt install phpmyadmin
   sudo htpasswd -c /etc/apache2/.phpmyadmin phpmyadmin     sudo htpasswd -c /etc/apache2/.phpmyadmin phpmyadmin  
-  sudo nano /usr/share/phpmyadmin/.htaccess +  sudo nano /usr/share/phpmyadmin/.htaccess  
-   +
-Enter the following in the file that opens: +
-  +
   <AuthType Basic>   <AuthType Basic>
   <AuthName "Restricted Files">   <AuthName "Restricted Files">
   <AuthUserFile /etc/apache2/.phpmyadmin>   <AuthUserFile /etc/apache2/.phpmyadmin>
   <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 /var/www/wordpress.com/public_html/info.php
 +  sudo htpasswd -c /etc/apache2/.phpinfo phpinfo  
 +  sudo nano /usr/share/phpinfo/.htaccess  
 +  <AuthType Basic>
 +  <AuthName "Restricted Files">
 +  <AuthUserFile /etc/apache2/.phpinfo>
 +  <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 /etc/apache2/mods-enabled/dir.conf 
 +  <DirectoryIndex //index.php// index.html index.cgi index.pl index.xhtml index.htm> 
 + 
 +Close and save the file. Let'now set up a database now for the WordPress instance as follows:
  
   sudo mysql -u root -p   sudo mysql -u root -p
Line 201: Line 228:
   </IfModule>   </IfModule>
  
- --- //[[jonathan@haacksnetworking.org|oemb1905]] 2023/06/29 04:09//+ --- //[[jonathan@haacksnetworking.org|oemb1905]] 2023/06/29 04:29//
computing/selfhostedwp.txt · Last modified: 2023/12/16 20:33 by oemb1905