Commit 4af79f85 authored by s20marilena's avatar s20marilena
Browse files

Initial commit

parents
# container names
SERVER_CONTAINER_NAME=nginx-container
PHP_CONTAINER_NAME=php-container
DATABASE_CONTAINER_NAME=database-container
DB_ADMIN_CONTAINER_NAME=adminer-container
# web server params
HOSTNAME=localhost
APP_PORT=80
APP_ROOT=/var/www/project
DOCUMENT_ROOT=/var/www/project/public
# database params
DB_PATH=/var/lib/mysql
DB_NAME=database
DB_ROOT_PWD=root
DB_PORT=3306
# database admin params
DB_ADMIN_PORT=8080
mysql/
project/vendor/
project/node_modules
.vscode/
.idea/
.settings/
# Docker + Laravel
Docker + Laravel projekta sagatave.
(Nedaudz pielāgojot, var izmantot arī citiem PHP projektiem)
## Konfigurācija
Lai sāktu darbu ar šo projekta sagatavi, papildus konfigurēšana nav nepieciešama. Šādā gadījumā spēkā būs sekojoši konfigurācijas parametri:
- Vietnes adrese: [http://localhost/](http://localhost/)
- Datubāzes serveris: `mysql`
- Datubāzes ports: 3306
- Datubāzes nosaukums: `database`
- Datubāzes lietotājs: root/root
- Datubāzes administrācija: [http://localhost:8080/?server=database&username=root&db=database](http://localhost:8080/?server=database&username=root&db=database)
## Vides sagatavošana un Laravel instalēšana
1. Veiciet konfigurācijas darbus, ja vēlaties
2. Uzbūvējiet konteineru, projekta direktorijā izpildot komandu `docker-compose build`
3. Iedarbiniet konteineru, projekta direktorijā izpildot komandu `docker-compose up -d`
4. Pieslēdzieties konteineram, projekta direktorijā izpildot komandu `docker exec -it bash`.
NB! Ja `.env` failā ir mainīts `PHP_CONTAINER_NAME` nosaukums, tad konteinera pieslēgšanās komandā tas jāraksta `php-container` vietā!
5. Ar komandu `pwd` pārliecinieties, ka atrodaties direktorijā `/var/www/project`!
Ja ne, aizejiet uz to ar komandu `cd /var/www/project`
6. Instalējiet Laravel ar komandu `composer create-project laravel/laravel .`
NB! Neaizmirstiet komandas beigās norādīt punktu!
7. Veiciet Laravel konfigurāciju:
Failā `project/.env`:
`APP_NAME` - norādiet savas lietotnes nosaukumu
`DB_HOST=database`
`DB_PORT=3306`
`DB_DATABASE=database`
`DB_USERNAME=root`
`DB_PASSWORD=root`
Failā `project/config/app.php`
`'timezone' => 'Europe/Riga',`
`'locale' => 'lv',`
Tagad pārlūkā atverot [http://localhost/](http://localhost/) , Jums vajadzētu redzēt Laravel sākumlapu!
---
## Sagataves lietošana bez Laravel
Galvenais, kas jāmaina, ja vēlaties sagatavi izmantot projektiem bez Laravel, ir Web servera 'document root'. To varat nomainīt, `.env` failā nomainot `DOCUMENT_ROOT` vērtību. Vienkāršiem projektiem šī vērtība var būt `/var/www/project`
---
## Changelog
- 2021-04
- Pielāgota PHP 7.4 un Laravel 8
- Izmanto jaunākās MySQL un Adminer versijas
- Gandrīz pilnībā pārrakstīti konfigurācijas faili
- 2020-05
- Pirmā versija
---
## @todo:
```
8. Opcionāli- Ja projektā būs nepieciešama autorizācija, tad konteinerā jāizpilda sekojošās komandas:
1. `composer require laravel/ui --dev` - tā instalē `laravel/ui` pakotni
2. `php artisan ui bootstrap --auth` - tā ģenerē autorizācijas sistēmai nepieciešamos failus
9. Veiciet datubāzes migrācijas, konteinerā izpildot komandu `php artisan migrate`
## Node.js un npm instalēšana:
- aiziet uz Node.js lapu https://nodejs.org/en/
- piefiksēt LTS versijas numuru
- aiziet uz https://nodejs.org/en/download/ un atrast saiti `Installing Node.js via package manager`
- tajā atrast sadaļu, kas attiecas uz Debian
- 2020.05 jāiet uz `Node.js binary distributions are available from NodeSource.`
- https://github.com/nodesource/distributions/blob/master/README.md
- tur jāatrod instrukcijas, kas paredzētas LTS versijai Debian sistēmās
- `Node.js v12.x:`
- `# Using Debian, as root`
- `curl -sL https://deb.nodesource.com/setup_12.x | bash -`
- `apt-get install -y nodejs`
- iekopēt konkrētās instrukcijas PHP konteinera Dockerfailā `php/Dockerfile`:
```
# Install Node and npm
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \
&& apt-get install -y nodejs
```
## Node.js alternatīva - vecs un nepārbaudīts piemērs
```
# Composer install
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Node, npm, gulp
RUN apt-get -y --fix-missing install curl gnupg software-properties-common
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
```
```
version: '3'
services:
# web server
# https://hub.docker.com/_/nginx
web-server:
container_name: ${SERVER_CONTAINER_NAME}
image: nginx:latest
volumes:
- './nginx:/etc/nginx/templates'
- './project:${APP_ROOT}'
ports:
- '${APP_PORT}:80'
environment:
- PHP_CONTAINER_NAME=${PHP_CONTAINER_NAME}
- SERVER_PORT=${APP_PORT}
- SERVER_NAME=${HOSTNAME}
- DOCUMENT_ROOT=${DOCUMENT_ROOT}
networks:
- project-network
# php
# https://hub.docker.com/_/php
php-processor:
container_name: ${PHP_CONTAINER_NAME}
build: ./php
volumes:
- './project:${APP_ROOT}'
networks:
- project-network
# db
# https://hub.docker.com/_/mysql
database:
container_name: ${DATABASE_CONTAINER_NAME}
image: mysql
volumes:
- './mysql:${DB_PATH}'
ports:
- ${DB_PORT}:3306
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PWD}
networks:
- project-network
# db admin
# https://hub.docker.com/_/adminer
database-admin:
container_name: ${DB_ADMIN_CONTAINER_NAME}
image: adminer
ports:
- ${DB_ADMIN_PORT}:8080
networks:
- project-network
networks:
project-network:
server {
listen ${SERVER_PORT};
server_name ${SERVER_NAME};
root ${DOCUMENT_ROOT};
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass ${PHP_CONTAINER_NAME}:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
FROM php:8-fpm
# Install PHP modules
RUN apt-get update \
&& apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install bcmath pdo_mysql zip
# Install Composer from Composer official Docker image
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN sed -i -e 's/upload_max_filesize = 2M/upload_max_filesize = 8M/' "$PHP_INI_DIR/php.ini"
RUN sed -i -e 's/;date.timezone =/date.timezone = "Europe\/Riga"/' "$PHP_INI_DIR/php.ini"
RUN sed -i -e 's/;date.default_latitude = 31.7667/date.default_latitude = 56.9514/' "$PHP_INI_DIR/php.ini"
RUN sed -i -e 's/;date.default_longitude = 35.2333/date.default_longitude = 24.1131/' "$PHP_INI_DIR/php.ini"
# Expose port
EXPOSE 9000
# Set working directory
WORKDIR /var/www/project
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2
APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
* text=auto
*.css linguist-vendored
*.scss linguist-vendored
*.js linguist-vendored
CHANGELOG.md export-ignore
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
php:
preset: laravel
disabled:
- no_unused_imports
finder:
not-name:
- index.php
- server.php
js:
finder:
not-name:
- webpack.mix.js
css: true
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p>
<p align="center">
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>
## About Laravel
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
Laravel is accessible, powerful, and provides tools required for large, robust applications.
## Learning Laravel
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
## Laravel Sponsors
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
### Premium Partners
- **[Vehikl](https://vehikl.com/)**
- **[Tighten Co.](https://tighten.co)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Cubet Techno Labs](https://cubettech.com)**
- **[Cyber-Duck](https://cyber-duck.co.uk)**
- **[Many](https://www.many.co.uk)**
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
- **[DevSquad](https://devsquad.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
- **[OP.GG](https://op.gg)**
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Code of Conduct
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
$this->reportable(function (Throwable $e) {
//
});
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}