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
computing:selfhostedwp [2023/06/29 05:58] oemb1905computing:selfhostedwp [2023/12/16 20:33] (current) oemb1905
Line 15: Line 15:
   sudo apt install apache2 mariadb-server php8.2 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 apache2 mariadb-server php8.2 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
      
-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 specify the version you need 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 specify the version you need. Some packages are only available as ''php-xx'' so run the above command first and then the command below when those situations arise:
      
-  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,soap,opcache,apcu,bcmath}
      
 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: 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:
Line 29: Line 29:
      
   sudo apt remove libapache2-mod-php* --purge   sudo apt remove libapache2-mod-php* --purge
 +  sudo apt install php8.3-fpm php8.3-cgi
   sudo a2enmod ssl   sudo a2enmod ssl
   sudo a2enmod headers   sudo a2enmod headers
   sudo a2enmod cache   sudo a2enmod cache
   sudo a2enmod rewrite   sudo a2enmod rewrite
-  sudo a2enmod setenvif +  sudo a2enmod setenvif 
 +  sudo a2dismod php8.1
   sudo a2dismod php8.2   sudo a2dismod php8.2
 +  sudo a2dismod php8.3
   sudo a2dismod mpm_prefork   sudo a2dismod mpm_prefork
   sudo a2enmod mpm_event   sudo a2enmod mpm_event
   sudo a2enmod proxy   sudo a2enmod proxy
   sudo a2enmod proxy_fcgi   sudo a2enmod proxy_fcgi
-  sudo a2enconf php8.2-fpm +  sudo a2enconf php8.3-fpm 
-  sudo a2enconf php8.2-cgi+  sudo a2enconf php8.3-cgi
   sudo apache2ctl configtest     sudo apache2ctl configtest  
   sudo systemctl restart apache2   sudo systemctl restart apache2
-  sudo systemctl restart php8.2-fpm+  sudo systemctl restart php8.3-fpm
  
 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: 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:
Line 97: Line 100:
 Let's now shell into our instance and set up WordPress. Let's now shell into our instance and set up WordPress.
  
-  ssh root@wordpress.com +  ssh root@site1.com
-  mkdir Downloads +
-  cd ~/Downloads +
-  mkdir wpdownload +
-  cd wpdownload+
   curl -O https://wordpress.org/latest.tar.gz   curl -O https://wordpress.org/latest.tar.gz
   tar xzvf latest.tar.gz   tar xzvf latest.tar.gz
-  touch ~/Downloads/wpdownload/wordpress/.htaccess +  mv wordpress /var/www/site1.com/public_html 
-  sudo chmod 640 ~/Downloads/wpdownload/wordpress/.htaccess +  
-  cp ~/Downloads/wpdownload/wordpress/wp-config-sample.php ~/Downloads/wpdownload/wordpress/wp-config.php +
-  mkdir ~/Downloads/wpdownload/wordpress/wp-content/upgrade +
 Okay, we will need the files and directories I created once we get it running.  Now, let's move the wordpress directory to the proper location for self-hosting. Okay, we will need the files and directories I created once we get it running.  Now, let's move the wordpress directory to the proper location for self-hosting.
  
   sudo mv ~/Downloads/wpdownload/wordpress /var/www/site1.com/public_html   sudo mv ~/Downloads/wpdownload/wordpress /var/www/site1.com/public_html
  
-When the website is in productionuse these permissions:+Nowcreate proper permissions for your Word Press directories and files:
  
-  sudo chown -R www-data:www-data /var/www/wordpress.com/public_html+  sudo chown -R www-data:www-data /var/www/site1.com/public_html
   sudo find /var/www/site1.com/public_html -type d -exec chmod g+s {} \;   sudo find /var/www/site1.com/public_html -type d -exec chmod g+s {} \;
   sudo chmod 755 /var/www/site1.com/public_html/wp-content   sudo chmod 755 /var/www/site1.com/public_html/wp-content
Line 127: Line 123:
   <Replace the example salts with those you just downloaded using copy/paste>   <Replace the example salts with those you just downloaded using copy/paste>
      
-Let's also add the following line to the ''wp-config.php'' file for updatesMake sure to add this within the body of the php document. //This is required if you are not using libapache2-mod-php//.+Sometimes, for reasons I am not sure about, WordPress does not allow users direct uploading. If/when that happens, add the entry to wp-config.php. If anyone knows why this is needed, please let me know!
  
   sudo nano /var/www/site1.com/public_html/wp-config.php   sudo nano /var/www/site1.com/public_html/wp-config.php
   <define('FS_METHOD','direct');>   <define('FS_METHOD','direct');>
  
-Let's now visit site1.com in a web browser. Enter the credentials that you created for the database above. Choose the settings you prefer and set up an admin account and record your credentials securely. You should now have a proper WordPress site! Now that you have a WordPress, check the SiteHealth tab and follow its advice and/or know why you don't. In my case, I typically adjust cache, rewrites, expiry+Let's now visit site1.com in a web browser. Enter the credentials that you created for the database above. Choose the settings you prefer and set up an admin account and record your credentials securely. You should now have a proper WordPress site! Now that you have a WordPress, check the SiteHealth tab and follow its advice and/or know why you don't. In my case, I typically adjust cache, rewrites, and headers.
  
   apt install memcached   apt install memcached
   nano /etc/default/memcached   nano /etc/default/memcached
 +  <ENABLE_MEMCACHED=yes>
   a2enmod cache   a2enmod cache
 +  a2enmod expires
 +  a2enmod headers
 +  a2enmod rewrite
  
-Optimizing and securing WordPress usually boils down to some cache and header settingsCache and/or page expiry settings: +After isntalling memcached and enabling those modules, navigate to your web root and adjust your .htaccess as follows:
- +
-  apt install memcached +
-  nano /etc/default/memcached +
-  a2enmod cache +
-  a2enmod expires+
  
   <IfModule mod_expires.c>   <IfModule mod_expires.c>
Line 157: Line 152:
   </IfModule>   </IfModule>
  
-Enable re-writes: 
- 
-  a2enmod rewrite 
   <IfModule mod_rewrite.c>   <IfModule mod_rewrite.c>
           RewriteEngine On           RewriteEngine On
Line 173: Line 165:
   </IfModule>   </IfModule>
  
-Enable headers: 
- 
-  a2enmod headers 
   <IfModule mod_headers.c>   <IfModule mod_headers.c>
           Header always set X-Content-Type-Options "nosniff"           Header always set X-Content-Type-Options "nosniff"
Line 231: Line 220:
 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, site2.cooldomain.com, etc. If that's the case, then hop on over to my [[https://wiki.haacksnetworking.com/doku.php?id=computing:wpmultisite|Word Press Multisite]] tutorial.  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, site2.cooldomain.com, etc. If that's the case, then hop on over to my [[https://wiki.haacksnetworking.com/doku.php?id=computing:wpmultisite|Word Press Multisite]] tutorial. 
  
- --- //[[jonathan@haacksnetworking.org|oemb1905]] 2023/06/29 04:29//+ --- //[[jonathan@haacksnetworking.org|oemb1905]] 2023/06/30 03:23//
computing/selfhostedwp.1688018333.txt.gz · Last modified: 2023/06/29 05:58 by oemb1905