What follows is a complete procedure to install WordPress on a Raspberry Pi, with a Multi-Sites configuration (Note: when Multi-Sites is activated, addition of Themes and Plugins must be done at the highest level (Network)).
References
How to host a WordPress Site on Raspberry Pi
How to install and set-up a WordPress Multi-Sites
Set-Up Apache2 Web Server
sudo apt-get install apache2 -y
Check the IP address of the Host
hostname -I
In a browser, enter the IP address returned by the above command. The browser should diaply the Apache2 default page, indicating that Apache2 is properly installed, and running.
Install PHP on Raspberry
sudo apt-get install php -y
Test that PHP is working. For this, go to /var/www/html and remove index.html:
cd /var/www/html
and
rm index.html
Create the file index.php with the following content:
sudo nano index.php
and paste the follwing:
<?php echo "hello world"; ?>
<?php echo date('Y-m-d H:i:s'); ?>
<?php phpinfo(); ?>
CTRL+x -y to close and save the file
Restart the Apache2 server
service apache2 restart
or
systemctl restart apache2.service
Refresh the browser page with the Host IP address.It should display the PHP information, proving that PHP has been properly installed and is running.
Install MySQL/MariaDb on Raspberry (Refer to the dedicated page in this blog). Or
sudo apt-get install mysql-server php-mysql -y
And restart Apache2 server
service apache2 restart
or
systemctl restart apache2.service
Install WordPress
First remove all files from /var/www/html
cd /var/www/html/
rm *.*
Download the latest version of WordPress
sudo wget http://wordpress.org/latest.tar.gz
Extract the content of the downloaded archive
sudo tar xzf latest.tar.gz
Move the extracted directory into /var/www/html
sudo mv wordpress/* .
then
ls # to check that all files are there
Delete the downloaded archive
sudo rm -rf wordpress latest.tar.gz
Set the Apache2 user (www-data) as the owner of the directory
sudo chown -R www-data: .
Configure MySQL
sudo mysql_secure_installation
Enter a root password (twice) then answer Y (Yes) to all following questions.
Create a database for WordPress
sudo mysql -uroot -p
(enter the password for root)
then
CREATE DATABASE wordpress;
then
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'PASSWORD';
then
FLUSH PRIVILEGES:
Install and Configure WordPress
Installing WordPress is simple; if you’ve already done it on an existing website, you should know what to do.
Open the website in your browser (as described above). You should see the WordPress Setup screen. Select your language, then Continue, and make a note of what is required: the database name, username, password, host, and the table prefix (this is for the database tables).
If you made it this far, you should have named the database “wordpress”, and have a note of the password. The Username is root, and the host localhost. The Table Prefix is wp_.
Click Submit, then Run the install, and input the Site Title, along with the Username, and Password for your administrator account. Click Install WordPress, and wait as WordPress is (quickly) set up.
To login to the WordPress installation, go to http://localhost/wp-admin.
Configure for Multi-Sites operations
Open /var/www/html/wp-config.php and insert the following block, just above the sentence “That’s all, stop editing! Happy publishing. “
define('WP_ALLOW_MULTISITE', true);
Refresh the Web browser page. There is be an item Network setup under the topic Tools
Select Network Setup. There choose “Address of Site in Your Network”
Select Sub directories
If the main website is example.com, the secondary website (secondary_name) will be accessible at example.com/secondary_name
Define a name for the Sites Network (example “My Sites”)
Click on Install.
Modify the file /var/www/html/wp-config.php by adding the following block just above the sentence “That’s all, stop editing! Happy publishing.” (do not forget to replace example.com by the actual website url.)
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/html/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
Modify the file .htaccess as follows:
RewriteEngine On
RewriteBase /html/
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Log into the Website admin
http://example.com/html/wp-admin.php
There should be a menu item called ‘My Sites” in the page Menu.
Start creating multiple sites. Note that addition of plugins can only be effected at the highest level of the network.