πŸ’Ύ Setting up WordPress on the Raspberry Pi

By | Command Line, Linux

Presented 2021-01-03: by 8bitMiker

In this tech tutorial I will be showing you how to get a WordPress blog working on a Raspberry pi.

NOTE: Some of the steps contained within are not appropriate for a production environment. This tutorial assumes a hobbyist paradigm.

❓ WHAT IS WORDPRESS?

WordPress is a great blogging platform! WordPress powers over 38.8% of all the websites on the Internet. Yes – more than one in four websites that you visit are likely powered by WordPress.

❓ WHAT IS THE RASPBERRY PI?

The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing.

βœ… INSTALLATION STEPS

How to Update your Server

  • apt-get update updates the list of available packages and their versions, but it does not install or upgrade any packages.
  • apt-get upgrade actually installs newer versions of the packages you have. After updating the lists, the package manager knows about available updates for the software you have installed. This is why you first want to update.
# Update system
sudo apt update && sudo apt upgrade -y

Installation

UFW, or Uncomplicated Firewall, is a front-end to iptables. Its main goal is to make managing your firewall drop-dead simple and to provide an easy-to-use interface.

# Full commands.
sudo apt install ufw -y
sudo ufw default allow outgoing
sudo ufw default deny incoming
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
yes | sudo ufw enable
sudo ufw status verbose

# As a one liner.
sudo apt install ufw -y && sudo ufw default allow outgoing && sudo ufw default deny incoming && sudo ufw allow ssh && sudo ufw allow http && sudo ufw allow https && yes | sudo ufw enable && sudo ufw status verbose

Installation

Apache is the most widely used web server software.

  • a2enmod enables a specified module.
  • a2dissite disables a site.
  • a2ensite enables the specified site.
sudo apt install -y apache2
# visually appealing urls
sudo a2enmod rewrite
sudo a2dissite 000-default.conf
sudo touch /etc/apache2/sites-available/web.conf
sudo a2ensite web.conf
sudo service apache2 reload
sudo chown -R $(whoami):www-data /var/www
sudo chmod -R 775 /var/www
sudo service apache2 restart
sudo chown -R $(whoami):www-data /var/www

# or as a one-liner.
sudo apt install -y apache2 && sudo a2enmod rewrite && sudo a2dissite 000-default.conf && sudo touch /etc/apache2/sites-available/web.conf && sudo a2ensite web.conf && sudo service apache2 reload && sudo chown -R $(whoami):www-data /var/www && sudo chmod -R 775 /var/www && sudo service apache2 restart && sudo chown -R $(whoami):www-data /var/www

Edit Virtual Hosts

Dictates how the Apache web server will respond to various domain requests. Edit the file /etc/apache2/sites-available/web.conf

  • Options Indexes FollowSymLinks MultiViews
    • Indexes:
      • if you try to access a directory that doesn’t have a Directory Index, such as index.php, the content of the directory will be shown.
    • FollowSymLinks:
      • allows apache to use symbolic links. This is a entry in a file system that points to a directory or file.
    • AllowOverride All
      • Allow .htaccess files to override every configuration parameter set in apache2.conf
  • Order allow,deny
    • By default, access to a directory is forbidden.
  • Allow from all
    • Allow connections from any network.
<VirtualHost *:80>

    ServerAdmin my.email.address.com

    ServerName localhost:80

    DocumentRoot /var/www/web

    <Directory /var/www/web>

        Options Indexes FollowSymLinks

        AllowOverride All

        Order allow,deny

        allow from all

    </Directory>

    ErrorLog /var/log/web-error.log


</VirtualHost>

To apply changes restart apache server with the command: sudo service apache2 restart

Database Installation

MYSQL is a relational database. This is a type of database that stores and provides access to data points that are related to one another. Relational databases are based on the relational model, an intuitive, straightforward way of representing data in tables. In a relational database, each row in the table is a record with a unique ID called the key. The columns of the table hold attributes of the data, and each record usually has a value for each attribute, making it easy to establish the relationships among data points.

NOTE: For the Raspberry Pi we will be using MariaDB: a community-developed, commercially supported fork of the MySQL relational database management system.

# Install MySQL
sudo apt install -y mariadb-server

You can now run mysql_secure_installation to configure security for your MySQL server.

# Configure MySQL Security
sudo mysql_secure_installation
  • Enter current password for root (enter for none): (PRESS ENTER)
  • Set root password?
    • New password: PASSWORD
    • Re-enter new password: PASSWORD
  • Remove Anonymous Users
    • Remove anonymous users? YES
  • Disable Remote Root Login
    • Disallow root login remotely? YES
  • Remove Test Database
    • Remove test database and access to it? NO
  • Reload Privilege Tables
    • Reload privilege tables now? YES

Interface with the MySQL Server

# Next type: 
sudo mysql -u root -p

Setup Database

# Now type the following:
create database wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'pass101';
FLUSH PRIVILEGES;
  • FLUSH PRIVILEGES: Enabling the changes to take effect without reloading or restarting mysql service.

Setup

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

# Install PHP plus packages.
sudo apt install -y php php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip php-imap php-mysql

php.ini

Adjust php.ini configuration file to fine tune settings.

php --ini | perl -nle 'if (m~(?i)Configuration\ File:\s+(.*)~){ print qq~\x{27}$1\x{27}~; $_ = $1; s~cli(?=/php.ini)~apache2~; print qq~\x{27}${_}\x{27}~}' | xargs -n 1 -I {} sudo perl -i"*_$(date +%s)" -ple 's~(?<=memory_limit\s=\s)\-?\d+M?(?{$__ = q!128M!})|(?<=post_max_size\s=\s)\d+M(?{$__ = q!999M!})|(?<=upload_max_filesize\s=\s)\d+M(?{$__ = q!999M!})~$__~g;' {}

WordPress is a free, open-source website creation platform. On a more technical level, WordPress is a content management system (CMS) written in PHP that uses a MySQL database. In non-geek speak, WordPress is the easiest and most powerful blogging and website builder in existence today.

Download WP-CLI

# Setup wordpress cli
cd /tmp && curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
cd /tmp && php wp-cli.phar --info
cd /tmp && chmod +x wp-cli.phar
cd /tmp && sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

# As a one-liner
cd /tmp && curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && cd /tmp && php wp-cli.phar --info && cd /tmp && chmod +x wp-cli.phar && cd /tmp && sudo mv wp-cli.phar /usr/local/bin/wp && wp --info

Configure WordPress

# Configure wordpress via command line.
cd /var/www/
curl -sSL -O http://wordpress.org/latest.zip 
unzip latest.zip
mv wordpress web
cd web
wp config create --dbname=wordpress --dbuser=root --dbpass=pass101
wp core install --url='localhost' --title=Wordpress --admin_user=admin --admin_password='pass101' --admin_email='test@email.com'
sudo chown -R $(whoami):www-data .
sudo chmod -R 775 .
echo "define('FS_METHOD', 'direct');" | tee -a wp-config.php
wp cache flush

# As a one-liner
cd /var/www/ && curl -sSL -O http://wordpress.org/latest.zip  && unzip latest.zip && mv wordpress web && cd web && wp config create --dbname=wordpress --dbuser=root --dbpass=pass101 && wp core install --url='localhost' --title=Wordpress --admin_user=admin --admin_password='pass101' --admin_email='test@email.com' && sudo chown -R $(whoami):www-data . && sudo chmod -R 775 . && echo "define('FS_METHOD', 'direct');" | tee -a wp-config.php && wp cache flush 

Leave a Reply

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