How to build a WordPress blog site on the Raspberry Pi and publish it to the public network


insert image description here

overview

In this tutorial, we will build a Wordpress blog site on the Raspberry Pi, start the era of blogging, and record life. At the same time, do intranet penetration to publish the blog online, so that Internet users can access it, no need for public network IP, and no need to purchase cloud servers, which is simple and fast.

Install PHP

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

Install the MySQL database

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

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
  • decompress
sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
  • Configure directory permissions
sudo chown -R www-data: .

Set up your WordPress database

Setup 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.

  • Then you will be asked: Set root password? —— Press Y to set the password of the root account

  • At this time, it will prompt New password , enter your MySQL password here , important : please keep this password in mind, press Enter after input, it will prompt re-enter new password, then repeat the password at this time, and press Enter.

  • Then, when asked to Remove anonymous users, press Y.

  • Then, ask you Disallow root login remotely, press Y.

  • Then, ask you Remove test database and access to it, press Y.

  • Then, ask you Reload privilege tables now, press Y.

  • Finally, you'll see the messages All done! and Thanks for using MariaDB! . Indicates that the setting has been completed.

Create a WordPress database

sudo mysql -uroot -p
  • Enter the root password you created.
create database wordpress;
  • Now grant database privileges to the 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 NOTE:** Change the above YOURPASSWORDto your password.

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

Reboot the Raspberry Pi

sudo reboot

WordPress configuration

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

20221117162456

  • Select your language and click Continuethe button.

You will see the WordPress welcome screen

20221117162503

  • 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 提交to continue.

  • Click 运行安装程序the button.

Now you are getting closer!

20221117162526

Fill out 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're logged in and have your site set up, you can view it by visiting http://localhost/wp-admin.

Log in to the management background:

20221117162534

Publish the WordPress site to the public network

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 that WordPress publishes as relative URLs.
You can do this by installing one of the following plugins

  • https://github.com/optimizamx/odt-relative-urls
  • http://wordpress.org/plugins/relative-url/
  • http://wordpress.org/plugins/root-relative-urls/

In this example, we install Relative URLthe plugin:

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

20221117162545

  • Enter in the keyword search bar Relative URLEnter

20221117162554

  • 现在安装Click the button after finding the plugin
  • When the installation is successful, click 启用the button to activate the plugin.

Modify config.php configuration

You have to make sure Wordpress understands that it is meant to be served over the tunneled 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 the wp-config.php file
sudo nano /var/www/html/wp-config.php

After configuration, as shown in the figure:

20221117162603

Then we can publish the modified blog website online, penetrate through the cpolar intranet, create a secure tunnel to map the local port, so that public network users can also normally access the blog website we built on the local Raspberry Pi.

cpolar official website: https://www.cpolar.com/

For details, please refer to this article tutorial: Building a Web site on the Raspberry Pi

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

20221117162611

Support friend link style

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

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

Go 设置, and go 固定链接.

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

20221117162618

You need to enable Apache's rewrite module:

sudo a2enmod rewrite

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

  • Edit the Apache configuration file for the virtual host:
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's in <VirtualHost *:80>, like so:
<VirtualHost *:80>
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
    ...
  • Save the file and exit.

  • Restart Apache.

sudo service apache2 restart

custom theme

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 the theme, add pages and posts, edit menus, add plugins, and more. This was just a taster of setting up some fun stuff on the Raspberry Pi's web server.

Next, let's try changing a theme.

  • WordPress Dashboard –> Appearance –> Themes

20221117162631

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

20221117162639

  • After the theme is installed successfully, click 启用the button.

  • Let's reopen the site and see the effect:

20221117162648

Now that your site has been built, you can further experience more themes and explore slowly.
A taster set on something interesting.

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

Guess you like

Origin blog.csdn.net/weixin_74937672/article/details/132414834