iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤖

WordPress on Termux

に公開

This is a detailed follow-up to the article mentioned above.

Now that MariaDB and PHP are operational, I will install WordPress. This method uses wp-cli.

Installing wp-cli

First, obtain the wp-cli phar file.

~ $ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
~ $ php wp-cli.phar --info
OS:	Linux 4.19.113-perf-gfe0bf86775e1 #1 SMP PREEMPT Wed Aug 31 00:10:19 CST 2022 aarch64
Shell:	/data/data/com.termux/files/usr/bin/bash
PHP binary:	/data/data/com.termux/files/usr/bin/php
PHP version:	8.4.2
php.ini used:	
MySQL binary:	/data/data/com.termux/files/usr/bin/mariadb
MySQL version:	/data/data/com.termux/files/usr/bin/mariadb from 11.8.0-MariaDB, client 15.2 for Android (aarch64) using  EditLine wrapper
...
~ $

Since everything looks correct, I will install it as the wp command in $PREFIX/local/bin.

~ $ chmod u+x wp-cli.phar
~ $ mkdir -p $PREFIX/local/bin
~ $ mv wp-cli.phar $PREFIX/local/bin/wp

Unfortunately, the path is not set yet, so the wp command cannot be used from any location. I will configure the path.

$HOME/.bashrc
if [[ ":$PATH:" != *":$PREFIX/local/bin:"* ]]; then
    PATH+=":$PREFIX/local/bin"
fi

After placing the wp command in /usr/local/bin and updating $HOME/.bashrc to add /usr/local/bin to the PATH environment variable, please exit Termux once and start a new terminal before proceeding with the following steps.

~ $ wp --info
(Confirm that the output is the same as before)

Installing WordPress

Downloading the WordPress archive.

~ $ mkdir -p wordpress
~ $ cd wordpress
~/wordpress $ php -d memory_limit=512M "$(which wp)" core download --locale=ja

Running it normally would exceed the memory limit, so I am temporarily increasing that limit to 512MB for execution.

Next, MariaDB must be running. I will create a user named 'wordpress' on MariaDB and grant all privileges to the 'wordpress' database. At this point, the 'wordpress' database does not yet exist.

~/wordpress $ mariadb -u root mysql
...
MariaDB [mysql]> create user 'wordpress'@'localhost' identified by 'wppass';
Query OK, 0 rows affected (0.008 sec)

MariaDB [mysql]> grant all privileges on wordpress.* to 'wordpress'@'localhost';
Query OK, 0 rows affected (0.014 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.006 sec)

MariaDB [mysql]> exit
Bye

I will now create the WordPress configuration file using the created user, have it create the database, and configure the information necessary for WordPress to run.

~/wordpress $ wp config create --dbhost=localhost:/data/data/com.termux/files/usr/var/run/mysqld.sock --dbname=wordpress --dbuser=wordpress --dbpass=wppass
Success: Generated 'wp-config.php' file.
~/wordpress $ wp db create
Success: Database created.
~/wordpress $ wp core install --url=localhost:8080 --title="Test WordPress" --admin_user=wpcli --admin_password=wpcli --admin_email=username@valid-domain.com
Success: WordPress installed successfully.

With this, the files required to run the Japanese version of WordPress are now in the current directory, and the database is prepared (however, since localhost is used as the URL, it cannot be accessed from other hosts. Since this is on a mobile device, I've decided to compromise on this point. It is possible to configure access by using a hosts file and setting that name as a virtual host). All that remains is to change the nginx root setting.

$PREFIX/etc/nginx/nginx.conf
        root         /data/data/com.termux/files/usr/share/nginx/html;

Change this as follows:

$PREFIX/etc/nginx/nginx.conf
        #root         /data/data/com.termux/files/usr/share/nginx/html;
        root /data/data/com.termux/files/home/wordpress;

If nginx/php-fpm is already running, simply restart nginx.

~/wordpress $ pkill nginx
~/wordpress $ nginx

Try opening "localhost:8080" in your smartphone's browser. The WordPress screen should appear. Once it does, log in via "localhost:8080/wp-login.php" using wpcli/wpcli to access the admin dashboard. The screen below shows a dummy post I wrote for display.

WordPress confirmation screen

GitHubで編集を提案

Discussion