Build a WordPress blog site on the Raspberry Pi [Intranet Penetration]

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

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.

Raspberry Pi, (English: Raspberry Pi, abbreviated as RPi, aliased as RasPi / RPI) [1] is designed for learning computer programming education, only a credit card-sized microcomputer, and its system is based on Linux. With the release of Windows 10 IoT, users can use Raspberry Pi running Windows.

Since its inception, the Raspberry Pi has been sought after by many computer enthusiasts and creators, and it was once hard to find a "Pie". Regardless of its "petite" appearance, the inner "core" is very powerful, and it has all functions such as video and audio. It can be said that "although the sparrow is small, it has all internal organs."

The Raspberry Pi is developed by the "Raspberry Pi Charitable Foundation" registered in the UK, with Eben Upton as the project leader. In March 2012, Eben Upton of the University of Cambridge officially launched the world's smallest desktop computer, also known as a card computer, which is only the size of a credit card but has all the basic functions of a computer. This is the Raspberry Pi computer board. The Chinese translation is "Raspberry Pi". The foundation's mission is to improve education in computer science and related subjects in schools, and to make computers fun. The Foundation expects that more applications of this computer will be continuously developed and applied to more fields, whether it is in developing countries or developed countries. In 2006, the early concept of Raspberry Pi was based on Atmel's ATmega644 single-chip microcomputer. The first batch of 10,000 "units" of Raspberry Pi "boards" were manufactured by manufacturers in Taiwan and mainland China.

It is a microcomputer motherboard based on ARM, with SD/MicroSD card as the memory hard drive, there are 1/2/4 USB ports and a 10/100 Ethernet port around the card board (Type A has no network port), which can be connected to Keyboard, mouse and network cable, as well as a TV output interface for video analog signals and an HDMI high-definition video output interface, all the above components are integrated on a motherboard that is only slightly larger than a credit card, with all the basic functions of a PC, only need to connect to the TV And keyboard, you can perform functions such as spreadsheets, word processing, play games, play high-definition video, and many other functions. The Raspberry Pi B type only provides the computer board, without memory, power supply, keyboard, case or connection.

There are also developers trying to install Windows 10 ARM version and Windows 11 ARM version on Raspberry Pi.

The Raspberry Pi is just like any other desktop or laptop computer running Linux, and you can do a lot with the Raspberry Pi. Of course, it is inevitable that there will be a little difference. Ordinary computer motherboards rely on hard disks to store data, but for Raspberry Pi, SD cards are used as "hard disks", and you can also connect external USB hard disks. Use the Raspberry Pi to edit Office documents, browse the web, and play games—such as Quake.

The Raspberry Pi's low price means it's even more versatile, making it a great multimedia center. Play videos with the Raspberry Pi, and even power it through the TV's USB port.

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 at this time and then repeat the password, 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 enter your own password IDENTIFIED BYafter .
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORD';

**IMPORTANT NOTE:** YOURPASSWORDChange to 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 <VirtualHost *:80>in , 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.

Guess you like

Origin blog.csdn.net/weixin_74957752/article/details/130591851