Installing WordPress on a UMIN server

Contents
  1. Connect via SSH
  2. Create .htaccess and .my.cnf
  3. Create .htaccess
  4. Create .my.cnf
  5. Set up datadir
  6. Prepare boost
  7. Install MySQL from source
  8. Initialize MySQL
  9. Start the MySQL server
  10. Create the database
  11. Set up WordPress
  12. Configuring .htaccess
  13. Setting permissions
  14. Configuring Crontab
  15. Setting up a redirect
  16. (Added 2022.06.06) Configuring phpMyAdmin

A few years ago, I wrote a post about installing MySQL on a UMIN server, but after tinkering with various settings, it stopped working and I left it alone for a while.

I have installed WordPress on UMIN servers several times now, and besides this site, I currently run three other WordPress sites there. Building on what I have learned so far, I am recording the steps here as a memo. If you use this article as a reference, please do so at your own risk.

Connect via SSH

On a Mac, connect via SSH using Terminal. On Windows, use TeraTerm((Impress Corporation. Mado no Mori. Mado no Mori. Accessed February 21, 2021. https://forest.watch.impress.co.jp/library/software/utf8teraterm/)) or Windows Terminal((Complete guide to the features and usage of the finally finished "Windows Terminal". @IT. Accessed February 21, 2021. https://www.atmarkit.co.jp/ait/articles/2005/28/news018.html)). For basic Linux commands, this video series((dotinstall. [Old Version] Introduction to UNIX Commands [General User Edition] (24 lessons in total). Dotinstall. Accessed February 21, 2021. https://dotinstall.com/lessons/basic_unix_v2)) provides a thorough explanation.

ssh {account}@plaza.umin.ac.jp

Replace {account} with your own account ID.

{account}@plaza.umin.ac.jp's password:

When prompted with the above, enter the password listed on your account registration notice.

Last login: Wed Oct 14 04:16:26 2020 from 114.171.105.111Code language: CSS (css)

This logs you in.

Create .htaccess and .my.cnf

Create a .htaccess file directly under /home/{account}/. You can create .htaccess locally in a text editor and upload it, but here I will use vim throughout. For instructions on using vim, this video series((dotinstall. Introduction to vim (18 lessons in total). Dotinstall. Accessed February 21, 2021. https://dotinstall.com/lessons/basic_vim)) is thorough and easy to follow.

Alternatively, in the terminal,

vimtutor

try entering the command above.

Create .htaccess

cd /home/{account}/
touch .htaccess
vim .htaccess

Press i to enter insert mode, then enter the following.

# .htaccess

php_value mysql.default_port {port}
php_value mysql.default_socket /home/{account}/tmp/mysql.sockCode language: PHP (php)

For {port}, refer to the information below((Homepage Service Related FAQ | UMIN FAQ. Accessed February 21, 2021. https://www.umin.ac.jp/faq/hp/)) and enter an unused port number of 1025 or higher.

(Added 2022/06/01) Specify a port number between 1025 and 65535.

When you finish typing, press Esc to exit insert mode, and type :wq to save and quit.

On the PLAZA server, users can install and use their own databases. However, because you cannot use installation methods that require administrator privileges (such as RPM), you must compile the database from source files. In addition, standard ports (for example, port 3306 for MySQL) are reserved by UMIN, so please assign and use an available port number from 1025 upward.

【コマンド】 netstat -nat | grep LISTEN | awk '{print $4}'Code language: JavaScript (javascript)

You can check which port numbers are currently in use.

https://www.umin.ac.jp/faq/hp/

Create .my.cnf

Create a .my.cnf file directly under /home/{account}/.

# /home/{account}/ 

touch .my.cnf
vim .my.cnfCode language: PHP (php)
# .my.cnf

[client]
port={port}
socket= /home/{account}/tmp/mysql.sock
[mysqld]
explicit_defaults_for_timestamp = 1
port={port}
socket= /home/{account}/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
pid-file=/home/{account}/tmp/mysql.pid
socket = /home/{account}/tmp/mysql.sock
datadir= /home/{account}/tmp/mysql_data/
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
[mysqldump]
quick
[mysqld_safe]
log-error=/home/{account}/tmp/mysql_data/log/mysqld.log
pid-file=/home/{account}/tmp/mysql_data/mysqld/mysqld.pidCode language: PHP (php)

In MySQL 5.7 and later, it seems best to include explicit_defaults_for_timestamp = 1 under [mysqld] (leaving it out causes an error during --initialize-insecure).

Set up datadir

Create the /home/{account}/tmp/mysql_data/ folder specified here.

# /home/{account}/ 

mkdir tmp
mkdir tmp/mysql_dataCode language: PHP (php)

Make sure to leave /home/{account}/tmp/mysql_data/ completely empty.

Prepare boost

Because boost is required when installing MySQL, we will set it up next.

Here, we will create a folder at /home/{account}/public_html/usr/local/src and place boost inside it.

# /home/{account}/

cd public_html
mkdir usr
mkdir usr/local
mkdir usr/local/src
cd usr/local/srcCode language: PHP (php)

Extract boost in /home/{account}/public_html/usr/local/src (boost 1.50.0)

(Added 2022/02/19) Using a boost version earlier than 1.59.0 now produces an error. Also, extracting the archive is no longer necessary.

# /home/{account}/public_html/usr/local/src 

wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gzCode language: PHP (php)

Install MySQL from source

The latest version of MySQL complains that it requires cmake3, so we will use MySQL 5.7 here.

(Added 2022/02/19) I slightly modified the cmake command.

# /home/{account}/public_html/usr/local/src 

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz
tar xvfz mysql-5.7.26.tar.gz
cd mysql-5.7.26
mkdir build
cd build
cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/{account}/public_html/usr/local/src/boost_1_59_0.tar.gz -DCMAKE_INSTALL_PREFIX=/home/{account}/public_html/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make installCode language: PHP (php)

Both make and make install take between 30 minutes and just under an hour each.

Initialize MySQL

Starting with MySQL 5.7, initialization appears to be done using --initialize-insecure.

/home/{account}/public_html/usr/local/mysql/bin/mysqld --initialize-insecure

At this point, if

[Warning]TIMESTAMP with implicit DEFAULT value is deprecated.Please use --explicit_defaults_for_timestamp server option(see documentation for more details).Code language: CSS (css)

an error like the one above appears, check that [mysqld] explicit_defaults_for_timestamp = 1 is included in .my.cnf((How to resolve TIMESTAMP Warning errors in MAMP MySQL | Terakoya.work. Published January 1, 2019. Accessed February 21, 2021. https://www.terakoya.work/mamp-mysql-timestamp-warning/)).

[ERROR] --initialize specified but the data directory has files in it. Aborting.Code language: CSS (css)

If an error like the one above appears,

make sure that /home/{account}/tmp/mysql_data/ is empty.

(Added: 2022/06/01)

[Warning] option 'port': unsigned value {port} adjusted to 65535Code language: JavaScript (javascript)

If the message above appears, the port number is not set up properly. Specify a port number between 1025 and 65535. Update the port number in both .htaccess and .my.cnf before proceeding to the next step (creating the log folder and mysqld.log file, then starting MySQL).

If there are no issues, you will see output like the following.

2020-10-13T08:52:01.376346Z 0
[Warning] Changed limits: max_open_files: 1024 (requested 5000)
2020-10-13T08:52:01.376437Z 0
[Warning] Changed limits: table_open_cache: 431 (requested 2000)
2020-10-13T08:52:01.572774Z 0
[Warning] InnoDB: New log files created, LSN=45790
2020-10-13T08:52:01.598074Z 0
[Warning] InnoDB: Creating foreign key constraint system tables.
2020-10-13T08:52:01.651137Z 0
[Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5c35a8ff-0d31-11eb-8873-f48e38c521d8.
2020-10-13T08:52:01.651484Z 0
[Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2020-10-13T08:52:01.657115Z 1
[Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. Code language: JavaScript (javascript)

Start the MySQL server

(Added 2022/02/19) At this point, create a log folder and a mysqld.log file inside /home/{account}/tmp/mysql_data/。

mkdir /home/{account}/tmp/mysql_data/log/
touch /home/{account}/tmp/mysql_data/log/mysqld.log

When running mysql.server start, you may get the error "/home/{account}/tmp/mysql_data/log/mysqld.log: No such file or directory".

/home/{account}/public_html/usr/local/mysql/support-files/mysql.server start

Enter the command above, and if

Starting MySQL. SUCCESS!

is displayed, the server has started.

/home/{account}/public_html/usr/local/mysql/bin/mysql -u root -p

You will be prompted for a password, but if initialization succeeded, you can simply press Enter to proceed. Because a password will be required from the next login onward, set one now.

set password='{password}';Code language: JavaScript (javascript)

Replace {password} with a password of your choice. Note that MySQL may return an error if the password does not contain letters, numbers, and symbols.

Type quit to exit MySQL, and then run the initial configuration.

/home/{account}/public_html/usr/local/mysql/bin/mysql_secure_installation

See the article on Kiso Igaku Kyōiku Kenkyūkai Note((Launching a homepage with WordPress on UMIN (3) Initial MySQL configuration. Kiso Igaku Kyōiku Kenkyūkai Note. Accessed February 21, 2021. https://plaza.umin.ac.jp/kikkenlab/note/umin-wordpress-03/)).

  • VALIDATE PASSWORD plugin? → yes

(Added 2023/5/25) "There are three levels of password validation policy" asks about password complexity. Personally, I think level 1 or 2 is fine.

  • Change the password for root ? → no
  • Remove anonymous users? → yes
  • Disallow root login remotely? → yes
  • Remove test database and access to it? → yes
  • Reload privilege tables now? → yes
Success.

All done!

Create the database

Start MySQL again.

/home/{account}/public_html/usr/local/mysql/bin/mysql -u root -p

Enter the password you just set. If you forget the password, empty /home/{account}/tmp/mysql_data/ again and repeat the process from the initialization step.

# mysql>

create database {database_name};
create user '{user_name}'@'localhost' identified by '{password_2}';Code language: PHP (php)

Replace {database_name}, {user_name}, and {password_2} with values of your choice. Then grant privileges to {user_name}.

grant all privileges on  {database_name}.* to '{user_name}'@'localhost';Code language: JavaScript (javascript)

Set up WordPress

Move to /home/{account}/public_html/ and install WordPress.

(Added 2022/06/01) After extracting the archive, delete the original compressed file with `rm latest.tar.gz`.

cd /home/{account}/public_html/
wget http://wordpress.org/latest.tar.gz
tar zxvf latest.tar.gz
rm latest.tar.gzCode language: JavaScript (javascript)

Check your hostname and write it down (referred to below as {hostname}).

hostname -f

At this stage, if you want the actual site URL to be

https://plaza.umin.ac.jp/{account}/wordpress/

rather than

https://plaza.umin.ac.jp/{account}/wp/

or something similar,

# /home/{account}/public_html/

mv wordpress wpCode language: PHP (php)

rename the directory as shown above.

https://plaza.umin.ac.jp/{account}/

If you want it to be

# /home/{account}/public_html/

mv wordpress/* ./Code language: PHP (php)

run the commands above to move all the contents of the folder directly under https://plaza.umin.ac.jp/{account}/. (If you simply want WordPress to appear when someone accesses https://plaza.umin.ac.jp/{account}/, setting up a redirect may also suffice.)

Below, I explain the steps using `/home/{account}/public_html/wordpress`. Create `wp-config.php`.

# /home/{account}/public_html/wordpress

cp ./wp-config-sample.php ./wp-config.php
vim wp-config.phpCode language: PHP (php)

Press `i` to enter insert mode. For what to write in `wp-config.php`, the article on the Kiso Igaku Kyōiku Kenkyūkai Note blog is also helpful((UMIN に wordpress でホームページを立ち上げる(5)wordpress のインストール. 基礎医学教育研究会ノート. Accessed February 21, 2021. https://plaza.umin.ac.jp/kikkenlab/note/umin-wordpress-05/)).

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '{database_name}');

/** MySQL database username */
define('DB_USER', '{user_name}');

/** MySQL database password */
define('DB_PASSWORD', '{password_2}');

/** MySQL hostname */
define('DB_HOST', '[hostname]:[port]');Code language: PHP (php)

Enter the lines above. Adding the lines below will make later configuration easier, though you can leave them out.

define('FTP_HOST', 'plaza.umin.ac.jp');
define('FTP_USER', '{account}');
define('WPLANG','ja');Code language: JavaScript (javascript)

Near the bottom of the file, you will see the section for entering security keys. Visit https://api.wordpress.org/secret-key/1.1/salt/ and overwrite that section with the output generated there((wp-config.php の編集. サポートフォーラム. Published November 2, 2018. Accessed February 21, 2021. https://ja.wordpress.org/support/article/editing-wp-config-php/)).

Once you have finished entering the text, press `Esc` to exit insert mode. Save and exit with `:wq`.

At this point, open your browser and go to:

https://plaza.umin.ac.jp/{account}/wordpress/

The setup screen will open. Fill in the required fields and launch WordPress.

(Added 2022/06/01)

If you get an "Error Establishing a Database Connection" message at this stage, check the following:

  1. Whether `{database_name}`, `{user_name}`, `{password_2}`, and `[hostname]:[port]` in `wp-config.php` are correct
  2. Whether you ran `grant all privileges on {database_name}.* to ‘{user_name}’@’localhost’;` properly in MySQL

Check these and any other relevant settings.

Configuring .htaccess

Create a new `.htaccess` file in `/home/{account}/public_html/wordpress`.

# /home/{account}/public_html/wordpress

touch .htaccess
vim .htaccess Code language: PHP (php)
# .htaccess

php_value mysql.default_port {port}
php_value mysql.default_socket /home/{account}/tmp/my_mysql.sock

# BEGIN WordPress
RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] 
# END WordPressCode language: PHP (php)

Setting permissions

Many articles cover WordPress permission settings, so I will skip the details((WordPressの理想的なパーミッション設定は?権限を見直してセキュリティ強化しよう. WeberNote[ウェバーノート]. Accessed February 21, 2021. https://www.webernote.net/wordpress/wp-permission.html)). Note, however, that setting `wp-config.php` to `400` or `600` may prevent posts from displaying. Here, we will set permissions to allow uploading photos to storage.

# /home/{account}/public_html/wordpress

chmod -R 707 wp-contentCode language: PHP (php)

(Added 2022/06/01)

If updating WordPress fails, set the permissions below as well.

# /home/{account}/public_html/wordpress

chmod -R 707 wp-login.php wp-cron.php wp-cron.php wp-load.php wp-trackback.php wp-config-sample.php wp-settings.php wp-mail.php wp-settings.php wp-signup.php wp-links-opml.php
Code language: PHP (php)

Configuring Crontab

MySQL sometimes fails to restart after UMIN server maintenance. To handle this, create `cron.txt` in `/home/{account}/etc/` and register it with `crontab`.

mkdir /home/{account}/etc/
cd /home/{account}/etc/
touch cron.txt
vim cron.txt
# cron.txt

@reboot /home/{account}/public_html/usr/local/mysql/support-files/mysql.server start
@reboot /home/{account}/public_html/usr/local/mysql/bin/mysqld_safe &

Code language: PHP (php)

Register it with `crontab`.

crontab /home/{account}/etc/cron.txt

(Added 2022/02/19) Add a newline at the end of `cron.txt`. Without it, you will get an error here.

"Be careful: if you don't put a newline at the end of cron.txt, you'll get the following error!
"cron.txt":2: premature EOF
errors in crontab file, can't install."https://t.co/SAx3kFNIDp

— Shoei (@shoei05) August 11, 2021

The WordPress sites I manage have been running fine with this setup so far. If you still see an error like "Error establishing a database connection" after UMIN server maintenance, manually run:

/home/{account}/public_html/usr/local/mysql/support-files/mysql.server start

or

/home/{account}/public_html/usr/local/mysql/bin/mysqld_safe &

Give either of those a try.

Setting up a redirect

Skip this section if you installed WordPress directly under `https://plaza.umin.ac.jp/{account}/`. This applies if you installed WordPress under `https://plaza.umin.ac.jp/{account}/wordpress/`.

We will set up a PHP redirect so that visitors to `https://plaza.umin.ac.jp/{account}/` are automatically sent to `https://plaza.umin.ac.jp/{account}/wordpress/`.

# /home/{account}/public_html/

touch index.php
vim index.phpCode language: PHP (php)

Press `i` to enter insert mode. Configure `index.php` as follows:

# index.php

<?php

header('Location:https://plaza.umin.ac.jp/{account}/wordpress/');

exit;
?>Code language: PHP (php)

Press `Esc` to exit insert mode. Save and exit Vim with `:wq`.

Now, visiting `https://plaza.umin.ac.jp/{account}/` will automatically load `https://plaza.umin.ac.jp/{account}/index.php`, which then redirects to `https://plaza.umin.ac.jp/{account}/wordpress/`.

(Added 2022.06.06) Configuring phpMyAdmin

When connecting to MySQL via phpMyAdmin on a UMIN server, if you get the error `mysqli_real_connect(): (28000/1045)`, set:$cfg['Servers'][$i]['host'] = 'https://t.co/HfbSEwVds6';$cfg['Servers'][$i]['port'] = '[your specified port number]';
and it will work.
Related:https://t.co/blpwIZmRGp

— Shoei (@shoei05) June 4, 2022

I plan to write up the details for this later.

Some parts of this guide may be brief, but I hope you find it useful. Please use the information in this article at your own risk.

English translation of the Japanese article.