In this guide, I show you how to install LAMP stack on Raspberry Pi 3 or Raspberry Pi 0. We do this for the purpose of creating a web server with WordPress-hosting capabilities!
Difficulty Level: Beginner to Intermediate
Time to Complete: 45 mins to 1 hour
Kodi Security warning: Hide your location (Ashburn, VA) and IP address (22.214.171.124) now.
What is a LAMP Stack?
Since a LAMP stack is essentially just the components of a powerful web server, we can host a WordPress site (or any other website) right from our Raspberry Pi.
I think so – especially because it means I can use a Raspberry Pi as a dedicated WordPress site development area (or “WordPress sandbox“).
What is This “Sandbox Web Server” Business All About Anyway?
In this tutorial, I use the free “Raspbian with PIXEL” operating system to quickly and easily set up a robust (WordPress-capable!) web server. This means you can create a WordPress site and host it right on your Raspberry Pi.
Can I Use This to Host a LIVE Website That’s Open to the World?
Hosting the site on your Raspberry Pi for the world isn’t very realistic. It’s definitely possible – just not very practical for most people.
But what is realistic is the fact that you can use the LAMP stack on Raspberry Pi as a WordPress “sandbox”.
What is a WordPress Sandbox?
Basically a WordPress sandbox is a “dummy” WordPress site in which you can tinker and play around with WordPress, or use as what web designers call a “development site”, or “dev site”.
Or if you’re serious (like me), you can build an entire WordPress site on your Raspberry Pi – then export it using a free WordPress “Clone” Plugin to easily “migrate” the WordPress site to a live, public web host.
How to Install LAMP Stack on Raspberry Pi (Raspbian)
- Install Raspbian using NOOBS and boot up the Raspberry Pi 3 into Raspbian.
- Open a Terminal window (Press Ctrl+Alt+T on your USB keyboard)
- Enter “sudo apt-get update -y“. Then wait until it’s done. This step fetches the list of software updates available for Raspbian on Raspberry Pi 3.
- Now enter “sudo apt-get upgrade -y“. Wait until it’s all done. In this step, Raspbian actually upgrades all the programs on your Raspbian operating system. This process takes my Raspberry Pi 3 around 30 minutes, so you need to be patient and let it finish.
- Then, we install Apache by entering this command: “sudo apt-get install apache2 -y“. Wait for Apache web server Raspberry Pi edition to install.
- When Apache is done installing, launch the web browser on your Raspberry Pi. Installing Apache in Raspbian took my RPi 3 about three minutes.
- Then enter http://localhost/ into the web browser’s address bar. This should display a page called “Apache2 Debian Default Page”.
- Now go back to the Terminal window (or re-open it using Ctrl+Alt+T).
- From the Terminal, install PHP on Raspberry Pi quickly by entering “sudo apt-get install php5 libapache2-mod-php5 -y” into the Terminal window. Wait for PHP to install – it took my RPi 3 about two minutes.
- Now in the Terminal, enter “cd /var/www/html“. This command takes us into the folder where our website lives. Any files you put in this folder will be “public” and served by your web server.
- Then in the Terminal, enter “sudo idle index.php“. This opens the “IDLE” GUI-based text editor app and creates a file which we use (“index.php”) in the next step to test the PHP installation we just installed.
- After IDLE launches, enter this: “<?php echo ‘hello world’; ?>“. Then Save the File and Close the IDLE text editor. You should now be back at the Terminal.
- In the Terminal, finally enter “sudo rm index.html” to make sure the PHP test file you created shows up, instead of the default (HTML) file.
- Now launch your browser and enter http://localhost/ into the address bar. You should see “hello world”! If you do, this means PHP is installed properly, you’re doing great, and you’re almost done installing LAMP stack on Raspberry Pi!
- Go back to the Terminal. It’s time to install MySQL. Enter “sudo apt-get install mysql-server php5-mysql -y” to install MySQL on Raspberry Pi. As MySQL installs, it will bring up a (blue) screen that asks for a “root” password. Enter a password that you’re sure you can remember and hit Enter. Or just use the default Raspberry Pi password, which is “raspberry” (as long as you don’t plan to make this a public-facing web server). The MySQL installer will then ask you to re-enter your newly-chosen MySQL password. Then MySQL will continue installing. It took about 5 minutes after asking for my root password to finish the installation.
- After MySQL is installed, restart Apache web server by entering “sudo service apache2 restart” into the Terminal. You’re done with the install LAMP stack on Raspberry Pi process! Keep reading to install WordPress on your new LAMP stack web server.
After you follow the steps above to install LAMP stack on Raspberry Pi, use the steps below to install WordPress on your new, full-fledged, mighty little Raspberry Pi web server!
Google trackers are lurking on 75% of websites. Cover your tracks to protect yourself.
How to Install WordPress after you install LAMP Stack on Raspberry Pi
- From the Terminal, enter “cd /var/www/html/“. Then enter “sudo rm *“. These two commands take us into the “public-facing” folder in our webserver and deletes all files in that location.
- Now enter “sudo wget http://wordpress.org/latest.tar.gz“. This command downloads WordPress!
- In the Terminal, enter this command to extract the WordPress “zip” file you just downloaded: “sudo tar xzf latest.tar.gz”
- Then enter this command to move the extracted folder into the right place: “sudo mv wordpress/* .“
- Finally, enter “sudo rm -rf wordpress latest.tar.gz” to remove the zip file (now that we’re done with it).
- To test the WordPress installation, launch your browser and enter “http://localhost” in the address bar. You should now see the “Welcome to WordPress” screen.
- Now enter the two commands “sudo chown -R www-data:www-data /var/www/html/” and “sudo chmod -R 755 /var/www/html/” to give WordPress proper access to the files it needs. Without this step, you won’t be able to install WordPress Plugins!
- Then, from the Terminal enter “mysql -u root -p“. Then enter your password. The default password for Raspbian is “raspberry”.
- Now that you’re in the “MySQL shell”, enter “CREATE DATABASE wp_myblog;“. Then enter “GRANT ALL PRIVILEGES ON wp_myblog.* TO ‘myusername‘@’localhost’ IDENTIFIED BY ‘mypassword‘;“. Finally, enter “FLUSH PRIVILEGES;” and then “EXIT;”.
- Now that you’re back at the Terminal, enter “sudo mv wp-config-sample.php wp-config.php“.
- Then enter “sudo idle wp-config.php“. This opens the Text Editor.
- Using the text editor, change the “password_here”, “username_here”, and “database_name_here” fields to “mypassword“, “myusername“, and “wp_myblog” (respectively). Then Save the File and exit the IDLE text editor.
- Now launch your web browser and enter “http://localhost/” into the browser address bar.
- The Wordrpess website setup screen appears! Enter a site title, enter a username and a password and email address, and click Install WordPress.
- After WordPress finishes installing, you will see the word “Success!” on your screen. Then click “Log In” to log in to your new WordPress site!
- Finally, enter the username and password you chose at the WordPress setup screen and click “Log In” to reach the WordPress dashboard.
Apache Web Server Raspberry Pi Notes
- The LAMP stack runs 67% of the entire world’s web servers. So, LAMP is the most popular web server platform in the world. Why? It has a combination of performance and scalability that is matched by no other webserver platform.
- There is a big difference between WordPress.com and WordPress.org:
- WordPress.com is a site that severely restricts your capabilities as a WordPress administrator. In exchange, they host your WordPress site for you on their servers (so you don’t have to buy your own web hosting account).
- On the other hand, a WordPress.org website is a website that uses the WordPress.org Content Management System. This system is way better than the WordPress.com Content Management System (or “CMS”). Why? Because WordPress.org does not limit your WordPress administrator capabilities at all. You can do anything: install plugins, install WordPress themes, etc.
- Use this command to Restart Apache Web server on Raspberry Pi: “sudo service apache2 restart”
- To see info about the PHP version you have installed, put this into the “index.php” file we created in the steps at the top of this page: “<?php phpinfo(); ?>“
- For a full install LAMP on Ubuntu 16.04 guide, check out this awesome tutorial.
- Adafruit has a great tutorial on how to autostart Raspbian VNC server on Raspberry Pi boot-up, so you can remote control your Pi from just about any other device with a VNC viewer!
60% off VPN Coupon
Take 60% off the same VPN I use.
- Simple Internet security
- Set it up with my tutorial videos
- Unblock & hide Kodi streams
(No-Risk 7-Day Money Back Guarantee)
Or see my video that shows you how a VPN stops hackers .
Notice: Hackers create fake WiFi hotspots to steal your passwords when you log in to Starbucks WiFi. Secure your data.