Creating a LAMP Server for WordPress
I want to host a web server at home. Why? Why not! This will be a fun project. Ultimately, I want a website for my family — a single location on the Internet where you can come and learn about the Helmers family. To do this, I'm going to install a LAMP (Linux, Apache, MySQL, PHP) stack onto a Raspberry Pi.
I'm choosing Apache as the web server because it is so widely supported. There's a ton of knowledge out there about it, and it's a bit more user-friendly than Nginx in my experience. Alright, let's get to it!
Steps to Follow
- Set up Raspberry Pi
- Install needed applications
- Set up MySQL
- Install WordPress
- Configure Apache
- Configure WordPress
1. Set Up Raspberry Pi
Along with the standard Raspbian Lite install, I also suggest installing ddclient for Dynamic DNS. These are explained further in their own respective posts.
2. Install Needed Applications
sudo apt-get install apache2 php7.0 php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-xmlrpc libapache2-mod-php7.0 mysql-server -y
While installing MySQL, you will be prompted to create a password.
3. Set Up MySQL
Now we'll create a database where WordPress will store its data. Log in to MySQL as root:
sudo mysql -uroot -p
Enter the password you created during installation. Once inside MySQL, create the database:
CREATE DATABASE WordPress;
Create a dedicated user for the database:
GRANT ALL PRIVILEGES ON WordPress.* TO 'root'@'localhost' IDENTIFIED BY 'password';
Exit MySQL:
exit
4. Install WordPress
sudo mkdir /var/www/html/wordpress
cd /var/www/html/wordpress
sudo rm *
sudo wget https://wordpress.org/latest.tar.gz
Extract the contents:
sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
This extracts WordPress into the current directory and cleans up the installation files.
5. Configure Apache
Give Apache ownership of the WordPress files:
sudo chown -R www-data /var/www/html/wordpress
Enable Apache's rewrite module:
sudo a2enmod rewrite
Edit the Apache virtual host configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Make sure the top of the file includes the following:
<VirtualHost *:80>
<Directory "/var/www/html/wordpress">
AllowOverride All
</Directory>
Restart Apache:
sudo service apache2 restart
6. Configure WordPress
Navigate to your Raspberry Pi's IP address in a browser and walk through the WordPress install steps — it's pretty self-explanatory. When asked for database information, use the WordPress database created earlier and the root user with the password you set.
Once the install is complete:
- Click "Run Install" and fill out the site info as prompted
- Go to Settings → Permalinks, select "Post name", and click "Save Changes" — this makes your URLs more readable
- Update your DNS settings with your domain registrar
- Go to Settings and update both "WordPress Address" and "Site Address" to reflect your domain name
Takeaways and Future Thoughts
Unexpected problems:
After running sudo service apache2 restart in step 5, I received this error:
Job for apache2.service failed because the control process exited with error code.
See 'systemctl status apache2.service' and 'journalctl -xe' for details.
The issue was that this Raspberry Pi was already running Pi-hole, which uses a Lighttpd server on Port 80. I used the following command to confirm what ports Apache was listening on:
grep -ri listen /etc/apache2
Sure enough, Port 80 was the conflict. I went into the Apache config files and changed them all to listen on Port 8080 instead. When the time comes, I'll configure my router to forward external Port 80 requests to Port 8080 on the Pi. In the meantime, I spun up a second Pi to run WordPress on.
I also struggled with SSL — my original plan was to have the site encrypted, but configuring SSL took more digging than expected.
Future concerns:
My ISP could theoretically get annoyed that I'm hosting a web server, but I'm not too worried — I'll cross that bridge when I come to it. My other concern is that the Raspberry Pi may be too underpowered to handle the site well. Time will tell.
Future enhancements:
- Add SSL encryption
- Set up a subdomain for Nextcloud