A simple store for all of your cloud needs. Built using PHP, HTML, and Javascript with a MYSQL back end.
It is configured to auto-deploy to a server when you successfully pass all tests on Travis CI.
If you want to see a live version of the site, it can be seen at Welcome2The.cloud. The basic username is arnold
and the password is test
.
- Install mysql, php7.2, Apache2 on WSL
- Log into mysql as sudo
sudo mysql
- Create a new user for this database using
CREATE USER '<username>'@'localhost' IDENTIFIED BY '<password>';
- Create a database for this account
CREATE DATABASE <database>
- Allow the new user access to the database
GRANT ALL ON <database>.* TO '<username>'@'localhost';
- Create a user for testing using this exact string
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
- Create a test database
CREATE DATABASE testDatabase;
- Allow the test user access to the test database
GRANT ALL ON testDatabase.* TO 'username'@'localhost';
- Flush privileges to ensure that everything has been committed.
flush privileges;
Now you can leave MySQL and run the database creation script by running the following command:
sudo mysql --default-character-set=utf8 testDatabase < src/data/createDatabase.sql
sudo mysql --default-character-set=utf8 <database> < src/data/createDatabase.sql
- Download the files to a directory on your computer
- Soft link that directory to the apache serving folder
ln -s <FullPathToTheFolder> /var/www/html/<SomeFolderName>
- Open the apache conf file
sudo vi /etc/apache2/sites-available/000-default.conf
- Change the file so the line
DocumentRoot /var/www/html/
readsDocumentRoot /var/www/html/<SomeFolderName>/src
- Add the line
DirectoryIndex shop.html
below theDocumentRoot
line - Run
sudo service apache2 start
to start the server
At this point you should be able to connect to the server by typing in localhost in a browser
You need to fill out the src/include/db_credentials.php with the information for your database.
<?php
function getDBLogin(){
$username = "<username>";
$password = "<password>";
$database = "<database>";
$server = "localhost";
return array($username, $password, $database, $server);
}
?>
The push script has been configured to ignore these files, as every push to the master will overwrite the website login information.
First you need to make it so you can run the tests, I used composer which gets the dependencies for you using: composer update
If you want to run the tests you can use the following commands, it's kinda hacky for now. Once everything is running well I can update the structure to ensure that they run by just running phpunit.
vendor/bin/phpunit --bootstrap src/objects/Account.php tests/AccountTest.php
vendor/bin/phpunit --bootstrap src/objects/Admin.php tests/AdminTest.php
vendor/bin/phpunit --bootstrap src/objects/Category.php tests/CategoryTest.php
vendor/bin/phpunit --bootstrap src/objects/Login.php tests/LoginTest.php
vendor/bin/phpunit --bootstrap src/objects/Order.php tests/OrderTest.php
vendor/bin/phpunit --bootstrap src/objects/Product.php tests/ProductTest.php
vendor/bin/phpunit --bootstrap src/objects/ShoppingCart.php tests/ShoppingCartTest.php
Since I went through the trouble of figuring all of this out I may as well share the love. This is how to autoconfig Travis CI pushes to a VPS.
This file is here to run the git push script at the end of the successful testing. You simply need to change this so the pushes go to your own server, and that the ssh-keyscan line is updated with the information about your server, so you don't get errored out when Travis CI doesn't recognize your server identity.
This file specifies which files to ignore when syncing to the server. You can specify directories or files. Right now I have it set up so it ignores the login data (see Creating the environment above for why). You can specify any files that you do not want deployed to the server on every push.
This is produced before hand using the ssh-keygen -t rsa -b 4096 -C '[email protected]' -f deploy_rsa
command, which create a keypair for your server. You can then use travis encrypt-file deploy_rsa --add
command to encrypt this file so you can push it to git safely.
See section above, it is the same.
We also need to set up the server. You need MySQL and Apache/nginx installed, along with all of the required PHP modules (see the first section for some instructions). There is a lot of config that I am not including, assuming that you know how to set up a basic webserver.
- Create a new user, add the unencrypted SSH key to their account so they can remote in without a password.
- Create a folder in that users directory called Welcome2TheCloud
- Soft link that folder to the /var/www/http/... directory
- Configure apache to serve up that link and have it set the root of the website to be the src folder.
When I was using git pushes before you would have needed to git init...ect but with rsync this is no longer nessisary as it is not a clone of the repository, but rather a copy that is pushed.