How to Install WordPress on a Raspberry Pi: Step-by-Step Guide
TL;DR: Install Raspberry Pi OS and Apache, MySQL, and PHP to create a LAMP stack. Then, download WordPress, configure the database, and run the installation wizard to launch your site.
Preparation and System Setup
Begin by flashing the latest version of Raspberry Pi OS Lite onto your micro SD card. Boot up your Raspberry Pi and connect to it via SSH. Once connected, open a terminal and update your system packages to ensure everything is current. Run the command sudo apt update && sudo apt upgrade and press ‘y’ to confirm. This step is crucial for security and compatibility with newer software packages.
If you want to dig deeper, check out our guide on Why the Sony A7 IV Is the Best All-Around Mirrorless Camera.
Installing the LAMP Stack
Next, you need to install the Apache web server, MySQL database, and PHP. You can do this in one go using the sudo apt install apache2 mysql-server php libapache2-mod-php command. During the MySQL installation, you will be prompted to set a root password. Choose a strong, secure password and remember it, as you will need it later. After the installation completes, start the services using sudo systemctl start apache2 mysql php. Verify that Apache is running by opening a browser and typing your Raspberry Pi’s IP address. If you see the “It works!” page, your web server is configured correctly.
Configuring the Database
Log in to the MySQL command line interface by typing sudo mysql. Create a new database and user specifically for WordPress. Execute the following commands: CREATE DATABASE wordpress_db; and CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'StrongPassword123';. Replace ‘StrongPassword123’ with your own secure password. Finally, grant privileges with GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost'; and flush privileges with FLUSH PRIVILEGES;. Exit the MySQL shell by typing EXIT.
Downloading and Configuring WordPress
Download the latest WordPress release from the official website. Extract the files and move the contents of the wordpress folder to the Apache document root directory, usually located at /var/www/html. Use the command sudo rsync -av wordpress/* /var/www/html/ to copy the files. Afterward, create a configuration file for WordPress by copying the sample config file: sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php. Open this file in a text editor like nano. Update the database name, username, and password to match the credentials you created earlier.
Finalizing the Installation
Set the correct permissions for the WordPress directory to ensure the web server can write to it. Run sudo chown -R www-data:www-data /var/www/html. Finally, navigate to your Raspberry Pi’s IP address in your web browser. You should see the WordPress installation wizard. Follow the on-screen prompts to set your site title, admin username, and password. Once completed, you will be redirected to your new WordPress dashboard. Congratulations, your local WordPress site is now live on the Raspberry Pi!
Tip: Always keep your system and plugins updated to prevent security vulnerabilities. Consider using a firewall like UFW to restrict access to your server if you plan to expose it to the internet.
FAQ
Q: Why is my site not loading after installation?
A: Check if Apache is running using sudo systemctl status apache2 and ensure the file permissions in /var/www/html are correctly set to www-data.
Q: Can I run WordPress on a Raspberry Pi 3?
A: Yes
Leave a Reply