Build a WordPress blog website from scratch on Raspberry Pi and achieve public network access

prelude

This article is the second in the series of articles about " Building a Web Site on Raspberry Pi ". You can read the first article first . In the first article, we built a simple static tool site and published the intranet site to the public network.

Overview

In this article, we will make our site more practical and build a WordPress blog site. Isn’t it meaningful to start your blogging era and record every detail of your life? let's start!

1. Install PHP

  • Update to the latest warehouse
sudo apt-get update -y
  • Install apache2php
sudo apt-get install apache2 php  -y
  • Restart apache2 service
sudo service apache2 restart

2. Install MySQL database

sudo apt-get install mariadb-server php-mysql -y
sudo service apache2 restart

3. Install WordPress

cd /var/www/html/
  • Remove old static site content
sudo rm -rf *
  • Download the latest wordpresss compressed package
sudo wget http://wordpress.org/latest.tar.gz
  • Unzip
sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
  • Configure directory permissions
sudo chown -R www-data: .

4. Set up your WordPress database

Set up MySQL/MariaDB

sudo mysql_secure_installation
  • At this time the system will ask you: Enter current password for root (enter for none): , press the Enter key , because there is no password for the first login.
  • You will then be asked: Set root password? - Press Y to set the password for the root account
  • At this time, New password will be prompted . Enter your MySQL password here . Important : Please remember this password. After entering, press Enter. You will be prompted to re-enter new password. At this time, re-enter the password and press Enter.
  • Then, you will be asked to Remove anonymous users, press Y.
  • Then, you will be asked to Disallow root login remotely, press Y.
  • Then, you are asked to Remove test database and access to it, press Y.
  • Then, you are asked to Reload privilege tables now, press Y.
  • Finally, you will see the messages All done! and Thanks for using MariaDB!. Indicates that the setting has been completed.

Create WordPress database

sudo mysql -uroot -p
  • Enter the root password you created.
create database wordpress;
  • Now grant database permissions to root user. **Note:** You will need to IDENTIFIED BYenter your own password after .
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORD';

**IMPORTANT:** YOURPASSWORDChange the above to your password.

  • In order for the changes to take effect, you need to refresh the database permissions:
FLUSH PRIVILEGES;
  • Exit MariaDB:
exit

Restart the Raspberry Pi

sudo reboot

5. WordPress configuration

  • Open a web browser on your Pi and go to http://localhost, you should see a WordPress page asking to select your language.
  • img

You will see the WordPress welcome screen

img

  • Click 现在就开始!the button.
  • Now fill in the basic information of the website as follows:
Database Name:      wordpress
User Name:          root
Password:           <YOUR PASSWORD>
Database Host:      localhost
Table Prefix:       wp_
  • Click 提交Continue.
  • Click 运行安装程序the button.

Now you are getting closer!

img

Fill in the information: Name your site, create a username and password, and enter your email address. Click 安装 WordPressthe button and log in with the account you just created.

Now that you are logged in and have your site set up, you can view the website by visiting http://localhost/wp-admin.

Log in to the management background:

img

6. Publish your WordPress site to the public network

If you have not installed cpolar, please refer to the first article to install and configure cpolar.

Before we use cpolar to publish WordPress to the public network, we usually need to do two things:

Install relative URL plugin

You have to make sure WordPress publishes as relative URLs. You can do this by installing one of the following plugins

In this example, we install Relative URLthe plugin:

  • Login to WordPress 仪表盘–> 插件–>安装插件

img

  • Enter in the keyword search bar and press Relative URLEnter

img

  • After finding the plug-in, click 现在安装the button
  • When the installation is successful, click 启用the button to activate the plug-in.

Modify config.php configuration

You have to make sure WordPress understands that it is meant to be served through the tunnel hostname. You can configure WordPress by modifying wp-config.php to include the following line:

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
  • Modify wp-config.php file
sudo nano /var/www/html/wp-config.php

After configuration, it looks like this:

img

Now, our blog site can be accessed normally by the public network! Let's see the effect:

img

7. Support friend link style

It is recommended that you change your permalink settings to make your URLs more user-friendly.

To do this, log into WordPress and go to 仪表盘.

Go to 设置, then go to 固定链接.

Select 文章名an option and click 保存更改.

img

You need to enable Apache's rewrite module:

sudo a2enmod rewrite

You also need to tell the web host serving the site to allow override requests.

  • Edit the virtual host's Apache configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
  • Add the following lines after line 1.
<Directory "/var/www/html">
    AllowOverride All
</Directory>
  • Make sure it is in as shown below:
<VirtualHost *:80>
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
    ...
  • Save the file and exit.
  • Restart Apache.
sudo service apache2 restart

8. Customized themes

WordPress is very customizable. By clicking on your site name in the WordPress banner at the top of the page (when you are logged in) you will be taken to the dashboard. From there, you can change themes, add pages and posts, edit menus, add plugins, and more. This is just a taster for setting up some fun stuff on the Raspberry Pi's web server.

Next, let’s try changing a theme.

  • WordPress Dashboard–>Appearance–>Theme

img

  • Click Popular, choose a theme you like, and click 安装the button

img

  • After the theme is installed successfully, click 启用the button.
  • Let's reopen the site and see the effect:

img

Now that your site has been built, you can further experience more themes and explore slowly.

Reprinted from cpolar pole cloud article: Build a WordPress blog website on the Raspberry Pi, and publish it to the public network through the intranet

Guess you like

Origin blog.csdn.net/qq_43289447/article/details/132812898