Introduction
This page describes how Alexis Huxley installed and configured WordPress.
Procedure
- Clean up any crud:
apt-get --purge autoremove wordpress mysql-server apache2 cd /etc && rm -fr php/7.0 mysql apache2 wordpress cd /var/lib && rm -fr wordpress* mysql* cd /etc/www/html && rm -fr wordpress*
- Install WordPress and its prerequisites with:
apt-get install wordpress mysql-server apache2
- Create a database:
mysql -u root create database wordpress; create user wordpress@localhost identified by '<set-password-here>'; grant all privileges on wordpress.* TO wordpress@localhost; flush privileges; exit
- Note that it is important that WordPress content appears to be somewhere under /var/www since /etc/apache2/apach2.conf only allows access to trees /usr/share and /var/www; although symlinking seems to be adequate. This is taken into consideration in the next two steps.
- Edit /etc/apache2/sites-available/wordpress.conf and add content:
Alias /wordpress/wp-content /var/www/html/wordpress/wp-content <Directory /var/www/html/wordpress/wp-content> Options FollowSymLinks Order allow,deny Allow from all </Directory> Alias /wordpress /usr/share/wordpress <Directory /usr/share/wordpress> Options FollowSymLinks AllowOverride Limit Options FileInfo DirectoryIndex index.php Order allow,deny Allow from all </Directory>
- Run:
ln -s ../../lib/wordpress /var/www/html/wordpress
- Run:
a2ensite wordpress service apache2 reload
- At this point it is essential that the URL you enter into your browser to access the site is the URL that the site will have when it goes into production! (I tried installing with a different name and then renamed it and the HTML source of the pages still referred to the pre-production URL!) I suggest to this this by adding the following the the front-end proxying webserver:
RewriteCond %{REMOTE_ADDR} ^<your-client-ip-with-dots-escaped>$ RewriteRule ^/(wordpress/.*) http://<new-wordpress-server>/$1 [P] ProxyPassReverse / http://<new-wordpress-server>/ RewriteCond %{REMOTE_ADDR} !^<your-client-ip-with-dots-escaped>$ RewriteRule ^/(wordpress/.*) http://<old-wordpress-server>/$1 [P] ProxyPassReverse / http://<old-wordpress-server>/
(Note the ‘!’ in the first line of the second stanza.)
- Edit /etc/wordpress/config-<public-name-of-your-server>.php and add content:
<?php define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpress'); define('DB_PASSWORD', '<set-password-here>'); define('DB_HOST', 'localhost'); define('WP_CONTENT_DIR', '/var/lib/wordpress/wp-content');
- Go to http://<your-server>/wordpress/ and fill in the fields as follows:
- sitename: <your-internet-visible-hostname>
- username: alexis
- password: <something-strong>
- your email: <publicly-valid-email-address>
- Press ‘Install WordPress’.
- Make the following general settings changes:
- To prevent the creation of month-based upload directories:
- Go to Dashboard–>Settings–>Media, disable ‘Organize my uploads into month- and year-based folders’
- Run:
rm -fr /var/lib/wordpress/wp-content/uploads/201*
- To allow human-readable URLs:
- Run:
a2enmod rewrite service apache2 restart
- Go to Dashboard–>Settings–>Permalinks, select Custom Structure and add ‘/about/’ in the box (I’m not sure if this is needed any more) and save settings.
- Click on the Permalinks link again and verify that the setting has stuck.
- Edit /etc/wordpress/htaccess to contain only:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L] </IfModule>
- Run:
- To allow plugins to be installed without FTP:
- Edit /etc/wordpress/config-<public-name-of-your-server>.php and add:
define( 'FS_METHOD', 'direct' );
- Run:
chown -R www-data:www-data /var/lib/wordpress/wp-content
- Edit /etc/wordpress/config-<public-name-of-your-server>.php and add:
- To prevent the creation of month-based upload directories:
- Allow existing themes to be upgraded by running:
rm /var/lib/wordpress/wp-content/plugins/akismet # symlink pointing to read-only area prevents update
- Allow existing themes to be upgraded by running:
rm /var/lib/wordpress/wp-content/themes/twentysixteen # symlink pointing to read-only area prevents update
- Download and activate the following plugins:
- Akismet
- Cleaner Gallery
- Easy Fancybox
- Embed OSM
- Manage Upload Types
- Media File Manager
- W3 Total Cache
- Tablepress
- WordPress Importer
- Slim Stat Analytics
- Contact Form WpDevArt
- Hide Title
- Configure those plugins as follows:
- Easy Fancybox:
- Go to Dashboard–>Media–>Settings and enable handling Youtube links
- Embed OSM:
- Set the image size to 900×400
- hide links tolarger maps
- Manage Upload Types
- Scan any previous uploads directory for the largest file and filetypes by running:
cd /var/lib/wordpress/wp-content/uploads find . -type f | sed 's/.*\.//' | sort -u du -ax * | sort -rn | grep '\t*.*\.' | head -1
- In the new installation, go to Dashboard–>Settings–>Media, for each filetype add it to the list. For me that was:
gpx application/gpx+xml dsc text/dsc torrent application/x-bittorrent svg image/svg+xml iso application/iso-image img application/x-img vfd application/x-vfd - Edit /etc/php/7.0/apache2/php.ini and set:
post_max_size = <size-in-MB-of-largest-file-plus-50%-plus-1>M # E.g. post_max_size = 201M upload_max_filesize = <size-in-MB-of-largest-file-plus-50%-plus-2>M # E.g. upload_max_filesize = 202M
- and then run:
service apache2 reload
- Scan any previous uploads directory for the largest file and filetypes by running:
- W3 Total Cache
- Go to Dashboard–>Performance and, if any instructions are displayed about what to add to /usr/share/wordpress/.htaccess then edit /etc/wordpress/htaccess (which the former is symlinked to) and add them.
- Contact Form WpDevArt
- Edit /var/lib/wordpress/wp-content/plugins/contact-forms-builder/frontend/skins/default.css and set:
... .wpdevart-forms.default-skin [type="button"]{ ... /* font-size:16px; */ /* font-weight:600; */ ... color:#b12930 !important; } ... .success_message.reply_msg{ background-color: #b12930; ... } ...
- This will make forms more like the Reddle theme.
- Edit /var/lib/wordpress/wp-content/plugins/contact-forms-builder/frontend/skins/default.css and set:
- Core
- Edit /etc/wordpress/config-<your-server>.php and add:
define('WP_CACHE', true);
- Edit /etc/wordpress/config-<your-server>.php and add:
- Easy Fancybox:
- If plagued by messages like:
An automated WordPress update has failed to complete - please attempt the update again now
then:
- Edit /etc/wordpress/config-<your-server>.php and set:
define( 'WP_AUTO_UPDATE_CORE', false );
- Reload the dashboard and if the problem is solved them skip the next steps.
- Edit /usr/share/wordpress/wp-admin/includes/update.php locate the following code:
function maintenance_nag() { include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version global $upgrading; $nag = isset( $upgrading );
and immediately after it add:
delete_site_option('auto_core_update_failed');
- Reload the dashboard, verify the message is gone.
- Remove the just-added line (yes, really!).
- Reload the dashboard again, verify the message is still gone.
- See https://wordpress.stackexchange.com/questions/5468/an-automated-wordpress-update-has-failed-to-complete-please-attempt-the-updat for more information.
- Edit /etc/wordpress/config-<your-server>.php and set:
- Download and activate the following themes:
- twentysixteen
- twentyseventeen
- Reddle
- Activate the Reddle theme.
- Modify the Reddle theme slightly:
- Edit /var/lib/wordpress/wp-content/themes/reddle/footer.php and change the site-info div to:
<div id="site-info"> <a href=/wordpress/>Home</a> <span> | </span> Powered by <a href="http://wordpress.org/">Wordpress</a> <span> | </span> Themed by <a href="http://wordpress.com/themes/reddle/">Reddle</a> </div>
- To get rid of horizontal scrollbars in preformatted blocks, go to Dashboard–>Appearance –>Editor and locate the CSS code:
overflow-x: scroll;
and change this to:
overflow-x: auto;
- To remove the header text go to Dashboard–>Appearance–>Customize–>Site Identity, set the site title, remove the tagline and uncheck the ‘Display Header Text’ box. (The site title will appear on the browser title bar even if is prevented from appearing on the page.)
- To remove all the stuff on the right of the page, go to Dashboard–>Appearance–>Widgets and remove all widgets.
- Edit /var/lib/wordpress/wp-content/themes/reddle/footer.php and change the site-info div to:
- Configure the logging of client IPs as described at Apache procedures.
Migrating content
- On the old WordPress server, install the Media File Manager plugin.
- On the new WordPress server, increase the timeout by editing /etc/apache2/apache2.conf and setting:
Timeout 3600
- Increase the memory PHP may claim by editing /etc/wordpress/config-<your-server>.php and setting:
define( 'WP_MAX_MEMORY_LIMIT' , '512M' );
- Apply the above changes by running:
service apache2 restart
- Run:
mysqldump --add-drop-table wordpress > ~/wordpress-empty.sql
- Prior to performing the actual migration, the content on the old WordPress server needs to be tweaked to allow some scripts to run. Do this as follows:
- Run:
svn co https://svn.pasta.freemyip.com/main/webtools/trunk /tmp/webtools export SRC_UPLOADS_DIR=<path-to-uploads-dir> # e.g. export SRC_UPLOADS_DIR=/var/lib/wordpress/wp-content/uploads /tmp/webtools/bin/find-duplicately-named-uploads
and for each file listed, use Media File Manager to rename one of the multiple occurrences of those files, in order to ensure there are no duplicately named uploads. You can call the script again to check you have renamed everything satisfactorily. (There is no need to edit the pages that reference the attachments; Media File Manager will do that automatically.)
- Use Media File Manager to move all banners to common/banners.
- Run:
- On the old WordPress server, export content.
- On the new WordPress server, import content, being sure to tick the ‘ Expect some failures to be reported, as shown here:
Failed to import Media “grosstiefental-map” Failed to import Media “5_20021124-1025_de-brauneck-lenggries_brauneck1” Failed to import Media “5_20021124-1028_de-brauneck-brauneckschneid_cross-michael1” Failed to import Media “5_20021124-1033_de-brauneck-brauneckhutte_risserkogel1” Failed to import Media “5_20021124-1034_de-brauneck-brauneckhutte_kotzen1” Failed to import Media “5_20040222-2482_de-brauneck-lenggries_hotel-alpenrose1” Failed to import Media “map1” Failed to import Media “x” Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Failed to import Media “bra2wie” Failed to import Media “no-ip-com-reset-button” Failed to import Media “no-ip-com-reset-butto2n” Failed to import Media “no-ip-com-update-hostnames” Media “directory-of-european-campsites” already exists. Media “” already exists. Media “” already exists. Media “” already exists. Failed to import Media “cz-sk-ku-track-annotated” Failed to import Media “cz-sk-hu-track-20150813TO20150904” Failed to import Media “pinion-gear-comparison” Failed to import “Hiking”: Invalid post type ec-template Failed to import “Software”: Invalid post type ec-template
(I could not see any obvious cause of these failures.)
- On the new WordPress server, run:
mysqldump --add-drop-table wordpress > ~/wordpress-post-import-pre-fix.sql rsync -a /var/lib/wordpress/wp-content/uploads/ /var/lib/wordpress/wp-content/uploads-pre-fix/
- On the old WordPress server, run:
/tmp/webtools/bin/gen-retrieve-missing-uploads
and follow the prompts regarding copying the just generated script across to the new WordPress server and running it there.
- To remove the header text go to Dashboard–>Appearance–>Customize–>Static Front Page, select ‘A static page’ and set the page to your intented top level page (for me this is the ‘Welcome!’ page). (This could not be done until the content had been migrated.
- On the old WordPress server, run:
/tmp/webtools/bin/gen-relocate-uploads
and follow the prompts regarding copying the just generated script across to the new WordPress server and running it there.
- Use the Media File Manager to move the remaining top level images to the right location.
- I do not use posts, so all example posts should be deleted.
- A lot of manual editing was required, especially for:
- TablePress table indices needed offsetting (e.g. references to table 23 needed to be changed to table 21)
- some banners were not displayed
- thumbnails secondary lengths (i.e. the width or height that was not one of 150, 300 or 1024) changed by one pixel, with the result that the old thumbnails became part of the media library and needed deleting
- galleries thumbnails (i.e. what was displayed prior to launching the fancybox window) changed from square to various rectangles and needed to be deleted and reuploaded
- Decrease the timeout in /etc/apache2/apache2.conf again.
- If the server is behind a front-end proxy then:
- Configure the logging of client IPs as explained in Apache procedures
- configure the proxying of requests to WordPress on the front-end server
- To support a Zabbix web scenario to check access to WordPress run:
cd /etc/wordpress ln -s config-<your-server>.php config-$(uname -n).php