PHP API for my Bookshop Webstore
This is the API for my Bookshop Webstore. It is written in PHP and uses MySQL as the database. It is used to fetch data from the database and send it to the webstore. It also handles the payment process via Stripe.
I recommend using XAMPP to setup the database and the API. It comes with Apache, MariaDB, PHP and phpMyAdmin. But you can also use any other server and database that supports PHP and MySQL.
- Start XAMPP and start Apache and MariaDB.
- Open phpMyAdmin and create a new database called
bookshop
using the SQL command:
CREATE DATABASE bookshop;
- Import the
bookshop.sql
file from thedb
folder into the database.
In bookshop.sql
are the necessary SQL statements to create the database and the tables so you don't have to do it manually. This step is necessary and the API won't work without it, because it needs to make queries to the database, in order for the webstore to work.
- Copy the
api
folder into thehtdocs
folder of XAMPP. This folder contains all the PHP files that make up the API. - Copy the
admin
folder into thehtdocs
folder of XAMPP. This folder containsconfig.php
which contains the database credentials and the stripe secret key. You need change the stripe secret key and database credentials to your own. - Copy the
conf
folder into thehtdocs
folder of XAMPP. This folder .htpassword which contains the credentials for the admin page. You need to change the credentials to your own. I recommend saving only a hashed password in the file. You can use this tool to generate a hashed password. - The API is set to allow CORS requests from
http://localhost:3000
by default. If you want to change this, you can do so inadmin/config.php
by changing theAccess-Control-Allow-Origin
header. You can also search for all occurrences ofhttp://localhost:3000
in theapi
folder and change them to your own domain. The URL is used inconfig.php
,success.php
andcancel.php
and.htaccess
in theapi
folder. Visual Studio Code has a handy feature to search for all occurrences of a string in the project.
TLDR:
- Copy everything to
htdocs
inside XAMPP folder. - Change the stripe secret key, database credentials and admin credentials in config.php
- Change BASE_URL from http://localhost:3000 to your own domain.
Congrats! The API is now setup and ready to use.
WARNING Never expose your stripe secret key or sensitive credentials to the public. Use gitignore to hide them from git. If you are using a public repository, make sure to remove the credentials from the commit history.
- Check
docs/imgs.md
for instructions on how to upload and display images in the database.