Skip to content

ArneAmeye/laravel-stagevinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Instructions on using this app as a developer:

Table of Contents

  1. Starting up laravel

  2. Database

    1. How to have a look into the DB
    2. Migrate (make) tables
    3. Refresh (update) tables
    4. Seeders
    5. Update after search pull
  3. Front-end

  4. Planning

    1. Legend
    2. To Do
  5. Server and laravel

    1. MySQL
    2. Login into mysql
    3. Database settings
    4. Debugging
    5. Check if everything worked correctly
    6. SSH tunnel
      1. HeidiSQL and Putty
  6. Deployement of git repo and database

    1. SSH public key permissions
    2. Have Linode and Apache ready for your webapp deployment
    3. Start generating the SSH deploy keys
    4. Actually deploy the git project
  7. Deployment

    1. Git repository
    2. Installing packages
    3. Composer
    4. Launching site
    5. HTTPS and SSL
  8. Envoy

  9. Docker

  10. Dusk (tests)

Starting up Laravel

vagrant up Then go to URL: homestead.test

Database

How to have a look into the DB

Make use of an external tool like:

-SequelPro (Mac OS)

-Alternatives for Windows include: HeidiSQL, ...

In this tool use the variables from the ".env" file to connect to the database.

Migrate (make) tables

First we need to go inside the virtual machine: vagrant ssh

Then we need to go into the "code" folder: cd code

This is the right folder to make use of Artisan that interacts with our DB manipulations.

Migrate (make) tables that are defined in "laravel-app > database > migrations": php artisan migrate

That's it, you should now be able to use the external tool (see previous title) to look into the DB and confirm if all is ok.

Refresh (update) tables

#f03c15 Added rows to table 'students' on 08/10/2019
#f03c15 Added email and password rows to table 'users' for login on 14/10/2019
#f03c15 Added rows to table 'companies' on 14/10/2019
#f03c15 Added rows and updated seeders with fillable content to tables 'companies' and 'students' on 15/10/2019
#f03c15 Added Thomas More user and company for API testing to tables 'companies' and 'students' on 17/10/2019
#f03c15 Added new seeder for standerd background/profile picture on 21/10/2019
#f03c15 Added rows to 'table 'internships' on 24/10/2019
#f03c15 Added Dribble columns to 'table 'students' on 04/11/2019
#f03c15 Fixed Intracto bug in database on 22/11/2019
#f03c15 Added table students_internships for many to many on 02/12/2019
#f03c15 Changes on seeders (and removed factories) for user testing on 05/12/2019
#f03c15 Added a students_companies table to save the distance in database on 12/12/2019
#f03c15 Added a tags column to internships and students tables in database on 13/12/2019

Refreshing tables when changes were made php artisan migrate:refresh

Refreshing tables and simultaniously add seeders php artisan migrate:refresh --seed

Update after search pull

  • Add credentials
  • composer update
  • If you want to try with own Algolia API, you can change the credentials but you need to perform following commands to bring all the information of you database into the api. php artisan scout:import "App\User"
    php artisan scout:import "App\Student"
    php artisan scout:import "App\Company"
    php artisan scout:import "App\Internship"
    php artisan scout:import "App\ReviewInternship"
    php artisan scout:import "App\ReviewCompany"
  • If something went wrong, please say it in the fb group ^^

Seeders

To add dummy data to the tables: php artisan db:seed

If a new seeder is added or in case of an error try the following commands: composer dump-autoload

If the problem is still there: composer update and composer dump-autoload

Front end

To convert SASS & ES6 to CSS & plain Javascript for a visual view in your browser: npm run watch (Updates live in browser)

Planning

Legend

Legende Betekenis
πŸ‘‘ Nieuwe to do
#0AD500 Arne
#FFA200 Bram
#FF00B9 Irene
#C100FF Lars

To Do

Geheime feedback van Joris na de eerste demo: https://docs.google.com/document/d/1EONhy5d7Q7JDloX7UC3OkLKlEE4s2yvwaC_pqeFDuRs/edit#heading=h.qjhtyun2njki (doorstreep als iets klaar is)

Function
Person Status
#0AD500 Validatievoorwaarden wachtwoord op voorhand vermelden + er na (/register)
Arne DONE
#0AD500 Knop Apply duidelijker (student, internship)
Arne DONE
#0AD500 $request->flash gebruiken bij het invoeren van gegevens (login, registratie, profiel company & student), internship)
Arne Doing
#0AD500 Validaties op profiel duidelijker of weglaten (student & company), requires front-end duidelijk aanduiden!
Arne DONE
#FF00B9 Informatie over Kingtrainnee mist (/index)
Irene DONE
πŸ‘‘ Informatie over Kingtrainnee op login is eventueel niet nodig doordat je niet auto surft naar login (/login)
Person Status
πŸ‘‘ Zoekparameters missen (vb. afstand thuis - stage, design - development)
Irene DONE (?)
#FF00B9 Witruimte recht van grid - flex van weergave stageplaats als applicaties weglaten (vooral index)
Irene DONE
#C100FF Na registratie het bericht (Welcome back) wijzigen
Lars DONE
#0AD500 Tekst onder de breadcrumb home is onduidelijk (Denk na over wat de gebruiker nu moet doen.)
Arne DONE
#FF00B9 Bij geen internships > toon empty state of bericht vb. zoek naar een internship (vooral index, misschien ook company)
Irene Done
#FF00B9 Wat doe je als je 100 of juist 1000 applications of internships hebt? (vooral index, ook company)
Irene Doing
πŸ‘‘ Recente internships misschien eerst plaatsen bij weergave? (vooral index, misschien ook bij company)
Person Status
#0AD500 Afbeeldingen van company bedrijven fixen (nu uitgestrekt)
Arne DONE
#0AD500 Lege velden bij een profielpagina weglaten (niet interessant voor gebruiker)
Arne DONE
#0AD500 Ingelogd > klik home icoon (breadcrumb) op index.php wordt je opeens ingelogd (op homestead.test per ongeluk getest)
Arne DONE
#0AD500 Bijwerken van afbeelding van een internship lukt niet - verwijderen (company, op homestead.test per ongeluk getest)
Arne DONE
#0AD500 Preview van uploaden afbeelding bij internship
Arne DONE
#0AD500 Upload preview in zelfde container, geen scroll nodig => minder verwarrend (UX)
Arne DONE
#FF00B9 Als je uitgelogd bent en je klikt op een internship, beter UX/UI (index)
Irene DONE
#FF00B9 Slechts eenmalig e-mail vragen bij registratie
Irene DONE
#FF00B9 Foute zinsverwoording: notificatie (requist > request) en bij breadcrumbs (home)
Irene DONE
#FF00B9 Eerst registreren als student en daarna pas als bedrijf (/register)
Irene DONE
πŸ‘‘ Een beoordeling geven aan een internship (review)
Person Status
πŸ‘‘ Een student kan op zijn profiel zien op welke hij/zij geapplied heeft.
Person Status
πŸ‘‘ Een notification wordt ook verstuurd via mail.
Person Status
πŸ‘‘ Als een notificatie geaccepteerd heeft, kan een student (en company?) zijn/haar notificatie verwijderen.
Person Status
πŸ‘‘ Tutorial (UX/UI)
Person Status
#C100FF Een bedrijf kan een student evalueren vooraleer ik die accepteer.
Lars TBA
πŸ‘‘ 'Oog' icoon om de zichtbaarheid van e-mail en/of gsm veld te tonen of niet (voor student)
Person Status

Server and laravel

MySQL

Normally everybody should have mysql on their server. To check it run: mysql --version

Login into mysql

mysql -u username -p
Enter password:

Database settings

MariaDB [(none)]> CREATE DATABASE databasename;
#f03c15 IMPORTANT ip is that of the person who uses your database MariaDB [(none)]> create user 'name'@'ip' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON databasename.* TO 'name'@'ip';

Debugging

MariaDB [(none)]> SHOW DATABASES;
MariaDB [(none)]> select * from mysql.user;
MariaDB [(none)]> show grants for 'name'@'ip';

Check if everything worked correctly

mysql -h ip -u username -p
Enter password:
MariaDB [(none)]> show databases;

SSH tunnel

Use following link to generate a keyname.pkk file to access the database server: https://linuxize.com/post/mysql-ssh-tunnel/

HeidiSQL and Putty

HeidiSQL > Settings
Network Type: MySQL (SSH tunnel)
IP: enter ip of database server
User: user of database
Password: password of user
Port: 3306

HeidiSQL > SSH-tunnel
Plink.exe location: select file
SSH host + port: ip database server 22
username: username of database server
password: (keep empty)
plink.exe time-out: 15
private key file: (select file you generated in putty)
local port: 3307

Deployement of git repo and database

SSH public key permissions

This section is added by request for SSH access to server ;)

user = your name

cd /home
ls -al
drwx------. user user

cd /home/user
ls -al
drwx------. 4 user user 4096 Oct 20 15:23 .
drwxr-xr-x. 5 root root 4096 Oct 23 18:51 ..
-rw-------. 1 user user 1305 Oct 23 19:57 .bash_history
-rw-r--r--. 1 user user 18 Oct 30 2018 .bash_logout
-rw-r--r--. 1 user user 193 Oct 30 2018 .bash_profile
-rw-r--r--. 1 user user 231 Oct 30 2018 .bashrc
drwx------ 2 user user 4096 Sep 27 12:28 MyNotes
-rw------- 1 user user 16 Oct 20 15:23 .mysql_history
drwx------ 2 user user 4096 Oct 20 09:32 .ssh

cd /home/user/.ssh
drwx------ 2 user user 4096 Oct 20 09:32 .
drwx------. 4 user user 4096 Oct 20 15:23 ..
-rw-r--r-- 1 user user 410 Oct 20 09:32 authorized_keys

Still problems with ssh public key access? Check this link

Have Linode and Apache ready for your webapp deployment

Make sure you have a user folder in your /home folder where the webapp will run from, something like:
/home/username (it's good to name this after your webapp).

we create that by making a new user:
NOTE: username in these commands is always the name of your webapp!
adduser username
passwd username

get root su - and cd into /home/username
make 2 log files and 2 folders:
touch access.log
touch error.log
mkdir username This is actually again the name of your webapp/username, in here will go all project files.
mkdir .ssh

change permissions on the whole webapp folder so apache can read and execute as a group:
cd /home chmod -R 750 username
chgrp -R apache username

make sure your sites-available file is changed to correspond with the new directory for serving the webapp
nano /etc/httpd/sites-available/appYOURNAME.thecreativitygym.be.conf
Change 4 things here:
-> 1st line: Directory "/home/username/username/github_projectname/public"
->inside the VirtualHost:
=> DocumentRoot /home/username/username/github_projectname/public
=> ErrorLog /home/username/error.log
=> CustomLog /home/username/access.log combined

Save and exit this file

Change the httpd.conf file's DocumentRoot
nano /etc/httpd/conf/httpd.conf
-> search for DocumentRoot and change the path to "/home/username/username/github_projectname"

restart apache systemctl restart httpd

Start generating the SSH deploy keys

Create the SSH key for Github
ssh-keygen -t rsa -b 4096 -C "[email protected]" User your Github email address!

It will ask for a place to save the file
/home/username/.ssh/id_rsa
Enter a passphrase if you want to, it will ask this later if you try to access the SSH key.

Add your SSH key to the SSH agent:
eval "$(ssh-agent -s)"
ssh-add /home/username/.ssh/id_rsa

Finally:
cat /home/username/.ssh/id_rsa.pub copy this output from "ssh-rsa" until your email address from the terminal window.
#f03c15 Only for owner repository Go online to the Github repo -> settings -> Deploy keys -> add deploy key -> give it a name and paste in the public key.

Deployment

Git repository

#f03c15 For all users expect owner of repository Make sure the owner of the repository has your key :)

First clone the project to your server:
git clone CLONE_HTTPS_URL

Check if all permissions in .ssh are owned by USERNAME, grouped by USERNAME and nothing for world.
This can be done by using following commands:
chown OWNERNAME FILE_NAME
chgrp GROUPNAME FILE_NAME
chmod PERMISSION_NUMBER FILE_NAME

Test your SSH connection to Github:
su - USERNAME
ssh -T [email protected]
Enter passphrase for key 'path':
Hi REPO_NAME! You've succesfully autheniticated, but GitHub does not provide shell access.

Git pull through SSH (deploy)
cd /home/USERNAME/USERNAME/laravel-stagevinder
git pull ssh://[email protected]/ArneAmeye/laravel-stagevinder.git

We don't have the .env file yet (it's excluded from the git repo).
paste your local .env data here and save: nano .env
Make sure you link up the DB credentials right!
You need to change the following variables:
APP_URL=YOUR SITENAME
DB_HOST
DB_DATABASE
DB_USERNAME
DB_PASSWORD

By now we added a whole new git repo in the server and a .env file, all of them need permissions for the apache group. As our site is located in the folder 'USERNAME', we change these permissions.
su -
Enter password:
cd /home/USERNAME/USERNAME
chmod -R 750 USERNAME
chgrp -R apache USERNAME

NOTE: Laravel needs write access for logs but also in the public/images folder to save our profile and banner pictures. Only these folders should have write access too! CD into the laravel project folder. chmod -R 770 storage
chmod -R 770 public/images

Installing packages

Installing following stuff for use of a laravel 6 project:
yum install php72w-mbstring
yum install php72w-dom
yum install php72w-pdo_mysql

Composer

Installing composer:
cd ~
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Installing composer in laravel projects (this adds the vendor folder):
cd /home/USERNAME/USERNAME/laravel-stagevinder
composer install --no-dev
Change the permissions on vendor directory: chmod -R 770 vendor
Change owner in vendor directory: chown -R USERNAME vendor
Change the group in vendor directory: chgrp -R apache vendor

If everything went well: php artisan migrate
If access denied, check .env file in laravel-stagevinder directory

Launching site

Normally by following the tutorial above, your site should appear in appYOURNAME.thecreativitygym.be

If not, check appYOURNAME.thecreativitygym.be/index.php
If it shows, check following step:
nano /etc/httpd/sites-available/appYOURNAME.thecreativitygym.be.conf
Change line AllowOverride None to AllowOverride All
systemctl restart httpd or even better apachectl graceful

If the above didn't work:
Check errors on reload of your site: tail -f /home/USERNAME/error.log
Check if the path cd /home/USERNAME has permissions for owner USERNAME and group apache by using following command ls -al and later on chmod -R 770 USERNAME
Check if the index is correctly set: nano /etc/httpd/conf/httpd.conf, make sure DirectoryIndex index.html is set to DirectoryIndex index.html index.php
And of course systemctl restart httpd or even better apachectl graceful

HTTPS/SSL

We are now going to add a https certificate to our site! This we need to use the Sociallite function :D
ssh name@ip
su -
yum install epel-release
now we are at it, make sure you are running the latest versions ;) : yum update
yum install wget
now you can follow this tutorial starting with step 3
Check the result!

nano /etc/httpd/sites-available/appYOURNAM.thecreativitygym.be.conf
add following lines to the section VirtualHost:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
apachectl graceful
Check if it works :D

Done! Feel free to ask questions, might have missed some stuff πŸ™ƒ

Envoy

Envoy needs to be configured LOCALLY!
Install Envoy: composer global require laravel/envoy
Make sure you have 2 environments: production and staging folders in Linode, a separate DB for each of them and working URL's.

Create an Envoy file in the root of the Laravel project called 'Envoy.blade.php'.
It looks like this: (Replace your deploy username, IP adresss and foldernames!)

#f03c15 The people who don't have a beta server, remove all parts with staging.

@servers(['production' => ['[email protected] -p22'], 'staging' => ['[email protected] -p22']])

@task('deploy-production', ['on' => 'production'])
    cd /home/FOLDERNAME/FOLDERNAME/laravel-stagevinder
    php artisan down
    git reset --hard HEAD
    git pull ssh://[email protected]/ArneAmeye/laravel-stagevinder.git
    php artisan migrate --force
    php artisan up
@endtask

@task('deploy-staging', ['on' => 'staging'])
    cd /home/FOLDERNAME-beta/FOLDERNAME-beta/laravel-stagevinder
    php artisan down
    git reset --hard HEAD
    git pull ssh://[email protected]/ArneAmeye/laravel-stagevinder.git
    php artisan migrate --force
    php artisan up
@endtask

Now run the deployment (in vagrant) with: envoy run deploy-staging or envoy run deploy-production

ISSUES?

  • SSH key for the deploy user must be setup!
    If you have done this but it tries to load it from "C/users/yourname/.ssh/id_rsa" then we need to tell Windows where this Linode host can find our Private Key:
    Go to "C:/User/Yourname/.ssh" and create a config file if it doesn't exist yet.
    Paste this and adapt to your configuration:
Host 139.XXX.XXX.XXX
 HostName 139.XXX.XXX.XXX
 User deployUsername
 IdentityFile ~/.ssh/YourPrivateKeyFileName

NOTE: Recommended to place your Private SSH key or a copy of it inside this .ssh folder so the last line of this file can find it easily (or adapt the whole path...).

@setup
    require __DIR__.'/vendor/autoload.php';

    $dotenv = Dotenv\Dotenv::create(__DIR__);

    try {
        $dotenv->load();
        $dotenv->required(['DEPLOY_USER', 'DEPLOY_SERVER', 'DEPLOY_BASE_DIR', 'DEPLOY_REPO'])->notEmpty();
    } catch ( Exception $e )  {
        echo $e->getMessage();
    }

    $gitUrl = env('GIT_URL');
@endsetup

@task('deploy-production', ['on' => 'production'])
    ...
    git pull {{ $gitUrl }}
    ...
@endtask
  • Error on bootstrap folder? chmod -R 775 bootstrap/cache and systemctl restart httpd
  • Error on storage folder with permissions denied? chmod -R 775 storage and chgrp -R apache storage
  • Errors about a package not found? Then add composer install after the git pull line in your Envoy.blade.php
  • Still errors? Then ask in chat πŸ˜‰

Docker

  • First, make an new directory with a new laravel project (composer create-project --prefer-dist laravel/laravel nameOfProject).
  • Follow the tutorial on this website.
  • Tips when following the turorial:
    • I recommend spliting following command in docker-compose up -d --build database && docker-compose up -d --build app && docker-compose up -d --build web into docker-compose up -d --build database, docker-compose up -d --build app and docker-compose up -d --build web ;)
    • Did you get an error after running the command docker-compose up -d --build app? It is about the php artisan optimize command? Then delete that line in the development > app.dockerfile.

Dusk (tests)

Install & Dusk setup

Add Dusk with composer: composer require --dev laravel/dusk
Install Dusk:

  • vagrant ssh
  • cd code
  • php artisan dusk:install

Make sure our .env file has the right URL (http://homestead.test) for "APP_URL".
Within the .env also change the DB HOST (ip) to the IP found in Homestead.yaml
Add [email protected] and DUSK_PASSWORD=yourpassword to the .env file, this is needed for a login test that i've written!

You can make a ".env.dusk.local" file filled with a copy of the ".env" file in case you want Dusk to use other settings of your .env file, however right now this is not needed.

All Dusk tests can be found in (folders): "tests->Browser"

We can run a test with: php artisan dusk
Note: do this in your local terminal, not inside the vagrant ssh terminal!

Problem running dusk?

Maybe try set the permissions right: chmod -R 0755 vendor/laravel/dusk/bin/

Error: Failed to connect to localhost port 9515: Connection refused
sudo apt-get update
sudo apt-get -y install libnss3 chromium-browser
Error: session not created: Chrome version must be between 70 and 73
Exit the Virtual Box and run composer require --dev staudenmeir/dusk-updater. Go back in your Virtual Box. Here you run php artisan dusk:update. Test it again: php artisan dusk.

Add dusk tests

You can make a new Dusk test with: php artisan dusk:make TestName => replace with a name for your test!

To Do

Arne ==> Login & home page
Lars ==> Regsiter for Companies/Students & Checking if you can visit the student page without Auth.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •