折腾Raspberry Pi:Migrating WordPress to Raspberry Pi

Preparation

Take full backup of existing system

Copy files to USB drive (extFat format)

 

On Raspberry Pi:

Update system

sudo apt-get update
sudo apt-get upgrade

Mount USB Drive

sudo apt install exfat-fuse exfat-utils

Install Apache

sudo apt install apache2 -y

Install MariaDB

sudo apt-get install mariadb-server -y

Install PHP

sudo apt-get install php php-mysql -y

Install PHPMyAdmin

sudo apt install phpmyadmin
select "apache2" option by pressing SPACE and then ENTER
select "Yes" at the next prompt
Set a password for PHPMyAdmin

Create a new user to create and access data tables within PHPMyadmin

sudo mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password_set_in_previous_step' WITH GRANT OPTION;
exit out of MySQL cmd line by typing “quit” in the terminal

Configuring Apache for PHPMyAdmin

sudo nano /etc/apache2/apache2.conf
Add the following line to the bottom of the file:
Include /etc/phpmyadmin/apache.conf
Save and exit by pressint CTRL + X and then pressing Y then ENTER.

Restart Apache service

sudo service apache2 restart

Accessing PHPMyAdmin

Type http://localhost/phpmyadmin in browser
User Name and Password are the ones set in previous step.

Install GEdit

sudo apt install gedit -y

Increase import file size of PHPMyAdmin

sudo gedit /etc/php/7.3/apache2/php.ini
update the following values:
memory_limit: 256M (default = 128)
post_max_size: 64M
upload_max_filesize: 40M
Save and exit.
Restart apache
sudo /etc/init.d/apache2 restart

Import Database

Create new database (match the database name in the backup sql file)
Go to Import tab (ignore errors), select backup sql file and import

“Install” WordPress

Copy from USB drive (files and folders under public_html folder/) to /var/www/html/ folder

Edit “wp-config.php”

Open “wp-config.php” with Text Editor.
Update the following values:
DB_USER
DB_PASSWORD
Also, add the following values:
define(‘WP_SITEURL’, ‘http://www.hi-alex.com/’);
define(‘WP_HOME’, ‘http://www.hi-alex.com/’);

Done

 

Fixing phpmyadmin “phpmyadmin – count(): Parameter must be an array or an object that implements Countable” error:

sudo nano +613 /usr/share/phpmyadmin/libraries/sql.lib.php
replace code

((empty($analyzed_sql_results['select_expr']))
    || (count($analyzed_sql_results['select_expr'] == 1)
        && ($analyzed_sql_results['select_expr'][0] == '*')))

with

((empty($analyzed_sql_results['select_expr']))
    || (count($analyzed_sql_results['select_expr']) == 1)
        && ($analyzed_sql_results['select_expr'][0] == '*'))

Ctrl + O
Enter
Ctrl + X
sudo service apache2 restart
sudo nano +613 /usr/share/phpmyadmin/libraries/sql.lib.php
replace code

if ($options != null && count($options) > 0) {

with

if ($options != null && count((array)$options) > 0) {

Ctrl + O
Enter
Ctrl + X
sudo service apache2 restart
 

Securing phpmyadmin, block access from internet

Open it in a text editor (sudo nano /etc/phpmyadmin/apache.conf) and find the block that looks like:

<Directory /usr/share/phpmyadmin>
...
</Directory>

Inside the block, add the following lines:

Order Deny,Allow
Deny from all
Allow from localhost
Allow from 127.0.0.1
Allow from 192.168.68.0/24

Ctrl + O
Enter
Ctrl + X
sudo service apache2 restart
 

Map www.hi-alex.com to a sub folder under /var/www/html/

sudo nano /etc/apache2/sites-enabled/000-default.conf
Add the following lines:
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/blog
ServerName www.hi-alex.com
Ctrl + O
Enter
Ctrl + X
 

References:

How to Install WordPress on Raspberry Pi
How to Install phpmyadmin on Raspberry Pi
Increase phpmyadmin import file size
Mount ExFat disk on Raspberry Pi
Copy or Move WordPress to Another Server
Fix phpmyadmin error
Fix phpmyadmin error on Import tab

Leave a Reply

Your email address will not be published. Required fields are marked *