This guide will walk you through setting up and running the Stock Portfolio Tracker project on a DietPi system using a Raspberry Pi. We will clone the project from your GitHub repository, configure the necessary components, and get the application up and running.
Before you begin, ensure you have the following:
- A Raspberry Pi: Running DietPi. DietPi Download
- SSH Access: To your DietPi system.
- GitHub Repository: The project repository is available at GitHub.
-
Connect to your Raspberry Pi via SSH.
ssh user@your-raspberry-pi-ip
Replace
userwith your username andyour-raspberry-pi-ipwith your Pi's IP address. -
Update and upgrade your DietPi system.
sudo apt update && sudo apt upgrade -y
-
Install Apache, PHP, and MariaDB.
sudo apt install -y apache2 php libapache2-mod-php mariadb-server php-mysql
-
Start and Enable Apache and MariaDB Services.
sudo systemctl start apache2 sudo systemctl enable apache2 sudo systemctl start mariadb sudo systemctl enable mariadb
-
Secure MariaDB Installation.
sudo mysql_secure_installation
Follow the prompts to secure your MariaDB installation. You can set a root password and remove anonymous users and the test database.
-
Navigate to the web root directory.
cd /var/www/html -
Clone the GitHub repository.
sudo git clone https://github.com/juliobellano/first-repo.git stock-portfolio-tracker
-
Set the correct permissions.
sudo chown -R www-data:www-data stock-portfolio-tracker sudo chmod -R 755 stock-portfolio-tracker
-
Log in to the MariaDB console.
sudo mysql -u root -p
Enter the password you set during the secure installation process.
-
Create the Database.
CREATE DATABASE stock_portfolio;
-
Create a User and Grant Permissions.
CREATE USER 'portfolio_user'@'localhost' IDENTIFIED BY 'yourpassword'; GRANT ALL PRIVILEGES ON stock_portfolio.* TO 'portfolio_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
-
Import the Database Schema.
- Copy the SQL script (
schema.sql) from the cloned repository to your local machine. - Import the SQL script into the
stock_portfoliodatabase:sudo mysql -u portfolio_user -p stock_portfolio < /var/www/html/stock-portfolio-tracker/schema.sql
- Copy the SQL script (
-
Navigate to the Project Directory.
cd /var/www/html/stock-portfolio-tracker -
Edit the Database Connection File.
- Open
db_connect.phpusing a text editor likenanoorvi.sudo nano db_connect.php
- Ensure the database connection details are correct. Replace the contents with:
<?php $servername = "localhost"; $username = "portfolio_user"; $password = "yourpassword"; $dbname = "stock_portfolio"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?>
- Save and exit the editor (Ctrl + X, then Y, then Enter for nano).
- Open
-
Access the Application:
- Open your web browser and go to
http://your-raspberry-pi-ip/stock-portfolio-tracker. - Replace
your-raspberry-pi-ipwith your Pi's IP address.
- Open your web browser and go to
-
Using the Application:
- Use the "Search Stock" input to find and select stocks.
- Add stocks to your portfolio by entering the amount and clicking "Add Stock".
- View your portfolio and track the performance of your stocks.
-
Debugging: If you encounter issues, check the Apache error log for messages:
sudo tail -f /var/log/apache2/error.log
-
API Keys: If you hit API request limits, consider obtaining multiple API keys and rotating them as demonstrated in the code.
-
Updating the Project: Pull the latest changes from the repository using:
cd /var/www/html/stock-portfolio-tracker sudo git pull origin main
You have successfully set up and run the Stock Portfolio Tracker application on your DietPi system using a Raspberry Pi. Enjoy tracking your stock portfolio!