Setting Up LAMP on Raspberry Pi Ubuntu: Apache, MySQL (MariaDB), and PHP
Ohidur Rahman Bappy
MAR 22, 2025
Setting Up LAMP on Raspberry Pi Ubuntu
Introduction
In this guide, we'll walk through the process of setting up a LAMP server on your Raspberry Pi running Ubuntu. LAMP stands for Linux, Apache, MySQL (MariaDB), and PHP. This setup is ideal for running a WordPress site.
Install Apache
Update Packages
Update the available packages by entering:
sudo apt update
Install Apache
Install the apache2
package:
sudo apt install apache2 -y
Test Apache
Access the default web page by browsing to http://localhost/
on the Pi or http://<your_pi_ip>
from another device.
Find Your IP Address
Find your Raspberry Pi's IP address with:
hostname -I
Change the Default Web Page
The default web page is located at /var/www/html/index.html
. Change its ownership to edit:
cd /var/www/html
sudo chown pi: index.html
Now, you can edit the file to customize your homepage.
Install PHP
To enable PHP processing, install PHP and its Apache module:
sudo apt install php libapache2-mod-php -y
Remove index.html
and create an index.php
:
sudo rm index.html
sudo nano index.php
Add some PHP content:
<?php echo "hello world"; ?>
Restart Apache
If PHP code is not executing properly, restart Apache:
sudo service apache2 restart
Install MariaDB
Install MariaDB along with PHP support:
sudo apt-get install mariadb-server php-mysql -y
Restart Apache once again:
sudo service apache2 restart
Download and Install WordPress
Download WordPress
Download the latest WordPress using wget
:
sudo wget http://wordpress.org/latest.tar.gz
Extract and Move Files
Extract and move WordPress files:
sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
Clean up unnecessary files:
sudo rm -rf wordpress latest.tar.gz
Change Ownership
Change file ownership to the Apache user:
sudo chown -R www-data: .
Set Up Your WordPress Database
Secure MySQL/MariaDB
Run the MySQL secure installation:
sudo mysql_secure_installation
Follow the prompts to enhance security.
Create the WordPress Database
- Start the MySQL prompt:
sudo mysql -uroot -p
- Create the database:
CREATE DATABASE wordpress;
- Grant privileges:
GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
- Flush privileges:
FLUSH PRIVILEGES;
- Exit the MariaDB prompt with <kbd>Ctrl</kbd> + <kbd>D</kbd>.
Restart Raspberry Pi
Finally, restart your Raspberry Pi to apply changes:
sudo reboot
Conclusion
Your LAMP server is now ready for WordPress! You can continue with the WordPress setup by navigating to your Raspberry Pi's IP address in a web browser.