Running MP-WP on a Modern Musl-Based Gentoo

February 11th, 2022

A lot has changed since I last wrote a guide on installing and running MP-WP. For one, the previous article reads like pure cringe when I go back and look at it now. I was more concerned with exhibiting the right affectations than producing something truly useful. Whatever usefulness (if any) it served at the time, I can assure you, was purely accidental. I now have a much better grasp of what I'm doing, so it's easier to filter out noise and highlight parts of the process that deserve attention. There have also been changes to Gentoo—subtle differences in the current upstream versions of Apache, MySQL, and PHP that require small tweaks and patches. Lastly, the guide that served as my initial reference for setting up MP-WP back in 2018 has since been lost to bitrot. This guide addresses the shortcomings of my previous guide and aims to be the only guide you'll need for setting up MP-WP on Gentoo.

Collecting the Patches and Pressing with V

This will be the only handwavy portion of this guide.1 First collect all the vpatches for MP-WP (along with all of the signatures) and press the tree using a working V. Now you should have a copy of the MP-WP source. Before you can use it you'll first have to install and configure some dependencies, so we'll leave the source alone for now and come back to it later.

Installing the Dependencies

MP-WP, derived from Wordpress 2.7, runs on top of Apache, MySQL, and PHP. So if you're on a fresh Gentoo install you'll need to first install and configure these before getting on to MP-WP.

MySQL 5.7

MP-WP is known to work with MySQL versions 5.5, 5.6, and 5.7. Since 5.7.36 was the version available upstream that's the one I selected. The process was mostly uneventful, except for a small incompatibility with musl2 while building mysql-connector-c. The bug was already known and a user had submitted a patch to Oracle with the fix. I took the changes in his patch, added them to a copy of the 5.7.36 ebuild, and saved it in my local overlay. With the changes in place MySQL emerged without any other issues.

For your convenience I've uploaded a tarball of the patched mysql-connector-c ebuild: mysql-connector-c-8.0.27-r1.tgz.

Download the tarball and extract to wherever you have your local overlay.3 To make the ebuild available to portage, run the following from inside the new directory:


# from inside /usr/local/portage/dev-db/mysql-connector-c/
sudo ebuild mysql-connector-c-8.0.27-r1.ebuild digest

The ebuild should now be available to portage and you can emerge it by specifying the version, like so:


# first install the patched mysql-connector-c dependency (skip this if on glibc)
sudo emerge -av =dev-db/mysql-connector-c-8.0.27-r1

# now you can emerge mysql
sudo emerge -av =dev-db/mysql-5.7.36-r1

If you are on a glibc-based build then you didn't need to create the patched ebuild and you can just emerge MySQL 5.7 normally, it will automatically pull in mysql-connector-c.

PHP 5.6 and Apache 2.4

First let's grab PHP 5.6. MP-WP won't work with PHP versions > 5.6 (the minor version doesn't seem to matter) and the upstream Gentoo repo no longer includes any ebuilds for PHP 5.6 so you'll have to manually add one to your local overlay as we did in the MySQL step. If you look inside /var/db/repos/gentoo/dev-lang/php/ you'll see ebuilds for all the available versions. If a 5.6 version isn't among these then you'll have to add your own to /usr/local/portage. You can either go look for one buried in the packages commit history or use my copy: php-5.6.40-r7-ebuild.tgz.

Extract the tarball to /usr/local/portage/dev-lang/,4 then make the ebuild available to portage:


# from inside /usr/local/portage/dev-lang/php/
sudo ebuild php-5.6.40-r7.ebuild digest

Before installing you'll also have to enable the USE flags for apache2 and mysql so that PHP is built with support for these. I added mine to the global list in /etc/portage/make.conf.

You can now run:


sudo emerge -av =dev-lang/php-5.6.40-r7

It will likely complain about a missing required USE flag, gd. If this is the case simply add this to /etc/portage/package.use5:


# Either inside `/etc/portage/package.use` if you have it as a file or inside `/etc/portage/package.use/somefile` if you have it as a directory.
dev-lang/php gd

You can now emerge PHP again with the same command. This time it should build without any issues. If you set the apache2 USE flag as mentioned above then emerging PHP will also pull in Apache as a dependency, so after this step you should have all the dependencies you need to start configuring MP-WP.

Configuring Apache and MySQL

First a few basic knobs to turn in order to get the dependencies working properly with each other. Edit the file /etc/conf.d/apache2 and add "-D PHP" to the variable APACHE2_OPTS. Now Apache will load the PHP module when it starts. Next, configure MySQL by running the following command.6


sudo emerge -av --config =dev-db/mysql-5.7.36-r1

This step will create the root MySQL user and ask you to choose a password. Save the password because you'll need it to connect to MySQL for the first time and create your other user accounts.7 Before starting MySQL you'll likely have to set the SQL mode for compatibility with MP-WP.8 Edit /etc/mysql/my.cnf and add the following to the bottom of the file:


[mysqld]
sql-mode="REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE"

Start mysql:


rc-service mysql start

Log in to MySQL as root with the password you set in the emerge --config step.


mysql -u root -p

Verify that the sql_mode was set correctly


SELECT @@GLOBAL.sql_mode;

The output should match what you entered in /etc/mysql/my.cnf. If everything looks good you can create the MySQL user and database you will use for MP-WP:


-- change the placeholder values to your own, obviously
CREATE USER 'someusername'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE theblogdbname;
GRANT ALL ON theblogdbname.* TO 'someusername'@'localhost';

Edit mp-wp/wp-config.php and set the DB_NAME, DB_USER, and DB_PASSWORD variables to match your configuration. Also set the $table_prefix variable to whatever you like, e.g. "mpwp_". The tables autogenerated by MP-WP will now all be prefixed with this string, e.g. "mpwp_posts", "mpwp_users", etc.

Now that everything is configured the last step is just to point Apache to your new MP-WP direcory. Edit /etc/apache2/vhosts.d/default_vhost.include and change the lines DocumentRoot "/default/path" and <Directory "/default/path"> to point to wherever you have your blog code.

You can now start apache:


sudo apache2ctl start

Visit localhost in your browser, if everything is configured and working properly you should see the new blog setup screen. From here simply follow the instructions to create your admin account and start using MP-WP. If you encounter any errors double-check the steps above and make sure you have everything configured properly. If you're still stuck, leave a comment describing your issue in detail and perhaps I'll be able to help.

  1. A future guide will walk through all of the steps involved in this but here I will assume you have a working vtron and know how to press vpatches. []
  2. If you're on a glibc rather than musl-based system you can skip ahead to emerging MySQL normally, it should work fine with the package in upstream. []
  3. Overlays are a concept in Gentoo's Portage. They allow you to "overlay" the main repository with additional repositories in order to make available additional packages—and versions of packages—that are not included in the default upstream repo. I have my local overlay at /usr/local/portage. The directory structure inside there matches the standard Portage repository structure, such as can be seen in /var/db/repos/gentoo. Packages are separated into category folders, within those are package folders, and within those are ebuilds and related files for available versions.

    To create your own local overlay, simply create the new directory (e.g. mkdir /usr/local/portage) and designate it as your overlay in /etc/portage/make.conf. To do so, add this line inside make.conf: PORTDIR_OVERLAY="/usr/local/portage" and save the file. []

  4. Or wherever you have your local overlay. []
  5. In this case I didn't want the flag to be global, so I added it to package.use. This can be either a file or a directory. Read more in the wiki. []
  6. Note that the exact version of MySQL you installed may be different, just be consistent with what's on your machine. You can check which package you have installed by running eix -I mysql. []
  7. I like to use pass for these sorts of things. []
  8. If you're using MySQL 5.6 or earlier it's possible this step is unnecessary. In any case you'll know soon enough when you try to run MP-WP. If you see any MySQL errors in the setup flow it's likely due to some incompatibility with the SQL mode. []
« Building TRB on a 2022 Vintage Musl Gentoo
Straightening a Bent 1U Server Chassis »

2 Comments

  1. Jacob Welsh says:

    A report of possible interest regarding the "feature" of persistent form inputs, and I wonder if you'll recall the convo I was looking for: http://jfxpt.com/2023/jwrd-logs-for-Sep-2023/#9230

  2. billymg says:

    The conversation does sound vaguely familiar, but I don't think it was with me (possibly with Diana). I tried searching through old logs and comments on this blog but nothing turned up. If I end up finding a reference to it later I'll ping you on your blog. Cheers

Leave a Reply

*
*

You can use the following HTML tags in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>