WordPress – kapn*net https://kapn.net Mon, 25 Mar 2024 13:28:56 +0000 en-US hourly 1 https://kapn.net/wp-content/uploads/2023/12/cropped-kapn-net-star-whiteBG-32x32.png WordPress – kapn*net https://kapn.net 32 32 Set up your wordpress site on dokku https://kapn.net/support/set-up-your-wordpress-site-on-dokku/ Fri, 21 May 2021 15:49:16 +0000 https://kapn.net/?post_type=epkb_post_type_1&p=609 […]]]> This is mostly cribbed from Jasmine Tracey’s excellent post at dev.to. There were a couple things that needed to be added and some local tweaks for me, so I put this here for my own reference. The most critical thing is the need for SSL settings in wp-config.php. I have enough sites that I should move to this model, that I may script it to save steps (I tried, but I don’t think I have enough sites to make it worth solving all the problems that scripting this generates). To speed re-use, I have put the commands/steps needed for re-deployments of existing sites in red.

Creating or migrating a WordPress site to Dokku

DNS prep

We need to prep for the ssl cert and final move by ensuring the DNS has a short TTL to allow for a quick dns change at the end.

Create the app and database

In your dokku terminal run the following command to create your app. I will be using testapp as my app name feel free to use another name. If you will be creating an app at a specific FQDN (app.kapn.net), use that as the app name. Otherwise the web address will be a subdomain of the server address.

Additionally, add other domains that might be used to access the website.

dokku apps:create testapp.tld
dokku domains:add testapp.tld domain.tld
dokku domains:add testapp.tld add.domain.tld

If you run dokku apps:list you should see your newly created application.

Now will install the mariadb plugin, create a database and link it to our app so that it has access to it. I found that the default Mariadb settings would hang forever on ‘waiting for container to be ready‘ and so I used the instructions here to add a specific, known working, mariadb version. Probably worth trying the mariadb:create command without the -i flag and everything following to see what happens.

# Install app
sudo dokku plugin:install https://github.com/dokku/dokku-mariadb.git mariadb

# Create database
dokku mariadb:create testappdb -i mariadb -I 10.4.17

# Link database to app
dokku mariadb:link testappdb testapp.tld

Setting up application storage on dokku server

I trimmed this down from the three directories that Jasmine used (themes, plugins, uploads). Maybe that’s a bad call, but I think it works.

# Create the folders (might require sudo)
sudo mkdir -p /var/lib/dokku/data/storage/testapp.tld/wp-content

# Change the permission (might require sudo)
# it's 32767 because that's what dokku needs. Not sure why
sudo chown 32767:32767 /var/lib/dokku/data/storage/testapp.tld/wp-content

# Mount the storage to the container
dokku storage:mount testapp.kapn.net /var/lib/dokku/data/storage/testapp.tld/wp-content:/app/wp-content

# if the container has already been deployed, then it'll have to be restarted
dokku ps:restart testapp.kapn.net

If we are migrating a site, we’ll need to inject the sql dump file into the new db:

dokku mariadb:import testappdb < testapp.dump.sql

Creating a local wordpress instance (or moving an existing one)
and pushing it to dokku

On your local machine clone the wordpress github project. Or fetch your archive of an existing site.

# Download and unzip wordpress files
curl -LO https://wordpress.org/latest.zip
unzip latest.zip
OR
rsync sitearchive_MWP_12345678.zip user@servername.tld:
ssh user@servername.tld
mkdir working_directory
cd working_directory
unzip sitearchive.zip

# Change directory to downloaded project
cd wordpress

# Download wordpress gitignore file
curl https://raw.githubusercontent.com/github/gitignore/master/WordPress.gitignore > .gitignore

# Initialize repository and make initial commit 
git init
git add .
git commit -m "Initial commit of wordpress files"

We are going to update the values of our config file so it knows to look for the dokku environment variables. Edit wp-config.php. Then update the following sections. This is slick, thanks, Jasmine.

// ** MySQL settings - You can get this info from your web host ** //
$url = parse_url(getenv("DATABASE_URL"));

$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);

/** The name of the database for WordPress */
define( 'DB_NAME', $database );

/** MySQL database username */
define( 'DB_USER', $username );

/** MySQL database password */
define( 'DB_PASSWORD', $password );

/** MySQL hostname */
define( 'DB_HOST', $host );

We also want to change authentication keys and salts so go to https://api.wordpress.org/secret-key/1.1/salt/ copy and paste the generated salts in the wp-config.php file replacing the following:

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

One more change to wp-config.php and we’ll save it. This ensures that when we go SSL, the site doesn’t just immediately break. More details of why at supportmyidea.com.

/** Ensure ssl is detected and responded to appropriately */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
    $_SERVER['HTTPS'] = 'on';
}

We also need to create a custom_php.ini file to improve some settings

upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 60
memory_limit = 512M

Now we need to tell dokku to use those settings when running the project to do that we will create a Procfile in the root of the project. Jasmine used Nginx, but I’m an old Apache guy.

web: vendor/bin/heroku-php-apache2 -i custom_php.ini

Commit and Push

Now we will commit and push our changes to our dokku server

# commit changes
git add .
git commit -m "updated config to work with dokku url"

# Add the dokku url to the downloaded project
# If your server is dokkuserver.com and your app is going to be 
# reached at testapp.kapn.net this would be:
git remote add dokku dokku@servername.tld:testapp.tld

# push changes
git push dokku master

Copy local files

This is why we created that mount earlier, so we can have persistent storage and a place to do updates as needed.

sudo rsync -avz wp-content/ /var/lib/dokku/data/storage/testapp.tld/wp-content/
sudo chown -R 32767:32767 /var/lib/dokku/data/storage/testapp.tld/wp-content

DNS switch

Change your website’s DNS A record to point at your dokku server.

Enable SSL

We are almost finished. To ensure we have a secure site, we will add https using lets encrypt

# Install plugin
sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git

# Set the global email
dokku config:set --global DOKKU_LETSENCRYPT_EMAIL=your@email.tld

# Setup cronjob to auto-renew certificates when they expire
dokku letsencrypt:cron-job --add

# Add https to site
dokku letsencrypt:enable testapp.tld

Testing

Go to your url application url in your browser you should see the installation page of your wordpress site. OR better still your migrated site.

]]>
CiviCRM Shortcodes for WordPress https://kapn.net/support/civicrm-shortcodes-for-wordpress/ https://kapn.net/support/civicrm-shortcodes-for-wordpress/#respond Tue, 11 Aug 2020 20:22:00 +0000 https://kapn.net/?post_type=epkb_post_type_1&p=507 […]]]> The five possible components are:

  • Contribution: [civicrm component="contribution" id="x"] shows a contribution page specified by the id attribute.
  • Event: [civicrm component="event" action="register" id="x"] and [civicrm component="event" action="info" id="x"] shows either a registration or information page for the event specified by the id attribute.
  • User dashboard: [civicrm component="user-dashboard"] shows the current user’s dashboard page. There are no additional options. To identify what related information you have setup to be displayed within the user dashboard i.e. contributions, memberships, etc. navigate to Administer > Customize Data and Screens > Display Preferences and select all of the information you would like to have visible to the user.
  • Profile: [civicrm component="profile" mode="y" gid="x"] shows a page for displaying a user’s profile. This can be one of 4 modes – edit, view, create or search. The default is create. The gid attribute selects which profile group is displayed.
  • Petition: [civicrm component="petition" id="x"] displays a petition form specified by the id attribute.
  • Form Builder: [civicrm component="afform" name="x"] displays a Form Builder form (afform) page. Where x is the name given to the page, for example: afsearchMemberDirectory

Contribution and Event components can be put in test mode with mode="test"

In addition, any of these can specify a hijack option and they will replace all other content on that page rather than being display inline. This looks like hijack="1".

Force: A force attribute is mentioned in the code but I’m not clear what it does and have not tested it myself: force=1 means it will display the table, force=0 means it will display the search box for the table and you will see the results of the search for the table after you search.

I think force probably only relates to profiles which could have search results and have default values.


Mostly taken from drkane’s answer on civicrm.stackexchange.com with some bits from the official documentation: Using shortcodes to publish CiviCRM content in WordPress.

]]>
https://kapn.net/support/civicrm-shortcodes-for-wordpress/feed/ 0
CiviCRM WordPress Upgrade checklist https://kapn.net/support/civicrm-upgrade/ https://kapn.net/support/civicrm-upgrade/#respond Mon, 04 May 2020 19:03:39 +0000 https://kapn.net/?post_type=epkb_post_type_1&p=393 System […]]]> A quick list version of the upgrading doc at CiviCRM.org with a few personal notes.

  1. ssh to server
  2. ensure everything is backed up right now, not last night. This is normally handled automatically on a daily basis by ManageWP and also by a local msqldump process.
  3. Disable CiviCRM logging because of DB upgrade issues. Administer->System Settings->Misc
  4. Disable InnoDB full text search because of DB upgrade issues. Administer->Customize Data->Search Prefs
  5. cd to /var/www
  6. visit https://civicrm.org/download in a browser and get the download links
  7. download civicrm-….zip (and if needed, the localisation files.tar.gz) to somewhere convenient using wget
  8. cd to wp-content/plugins directory of site
  9. mv civicrm directory to /var/www/sitename/civicrm.bak (This is to backup what we have just in case of trouble and to get the existing one out of the way for the new code.)
  10. unzip civicrm-….zip to plugins directory
  11. IF NEEDED: cd to civicrm directory and tar xvzf civicrm…_l10n.tar.gz
  12. cd to wp-content/uploads/civicrm/templates_c and delete everything inside templates_c
  13. upgrade the database by visiting /wp-admin/admin.php?page=CiviCRM&q=civicrm/upgrade&reset=1
  14. re-enable logging if needed
  15. re-enable InnoDB full text search if needed
  16. may need to www-unlock and www-lockdown once or twice to correct permissions.
  17. confirm site function
    1. test a contribution form
    2. test a mailing
    3. test public pages

]]>
https://kapn.net/support/civicrm-upgrade/feed/ 0