Sunday, September 6, 2020

Phpmyadmin localhost cant access issue solved

in apache2 config file 

$cfg['Servers'][$i]['auth_type'] = 'config';

$cfg['Servers'][$i]['username'] = 'root';
$cfg['Servers'][$i]['password'] = '';



virtual host setup for linux

 I have been doing Javascript programming for last 2 months, and haven’t worked on any Laravel application in that time. And when, on this weekend, I tried installing a laravel application, I forgot how to create the virtual host file for it. Because for every application, I like to use a domain, and NOT localhost:port. And I will tell you why we need to do make a domain for your applications.

Why do we need a domain?

As good as the php artisan serve command is, it is not going to be responsible for running your application in production mode.

If you have a virtual host setup for your application, let’s say test.site, it will tell your apache server in your machine to act as your server for your application, and you now don’t need to run the serve command and your application is still running.

And the serve command will try to run your application with it’s own settings, and when you move to a server, you will end up with many requirements that you need in order to host your application, and you wouldn’t know about that until you are actually installing your application on a real server.

So, having a real server on your side and running your application on it, gives you a heads up, on what would you need in order to run your application on a real server.

Let’s start with creating a virtual host file.

Virtual Host

It is just a symlink to your application which can be accessed via your link, in this case, test.site .

You can find these files inside your /etc/apache2/sites-available folder.

For example let’s create a virtual host file for a laravel application kept in /var/www/html/test

First go to, /etc/apache2/sites-available/ , copy 000-default.conf file or create a new file at that location with the name of the domain you want, i.e., test.site.conf .

Now, for the content of this file, I have created a ,

<VirtualHost *:80>
ServerAdmin admin@server.in
ServerName server.in
ServerAlias server.in
<Directory /var/www/html/project/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
DocumentRoot /var/www/html/project/public/
ErrorLog /var/www/html/project/error.log
CustomLog /var/www/html/project/access.log combined
</VirtualHost>

 from which you can copy the content and paste in the file. Now you can replace the things as you desire.

ServerAdmin — It can be any email, I keep admin@domain.com

ServerName and ServerAlias — It needs to be the url you want, i.e., test.site

You can replace the project with the name of the application i.e., test .

Now you can save the file.

Now you need to tell apache that this conf file ready to be served, so you need to run this command:

sudo a2ensite test.site.conf

sudo service apache2 restart

dont forget to host the domain in host file

sudo nano /var/etc/hosts

update 127.0.1.1 yournewdomain.test (server alice)

a2ensite generally comes with apache installation. But you can install it externally as well.

And also you need to check if rewrites are enabled on the server. This is not the default setting, so you need to enable it.

You can enable the setting by running below command:

sudo a2enmod rewrite

sudo service apache2 restart

This rewrite module will help run the links on your server. By that I mean, when you don’t run above command, other than the homepage, no other link in your application will work and you will get this error.

Image for post

When you enable the rewrite module, it checks the .htaccess file and run all the links.

Now, there is just one step remaining, you need to add an entry in /etc/hosts file like below

127.0.0.1 test.site

This will tell the server, if any request comes from test.site you need to find its settings in conf file(if you find any) and run the appropriate application.

That’s it, now you can create a virtual host file of your own and run your applications like the way any server would do it.

Conclusion

Making a virtual host for you laravel applications can be really good for you in the long run. You can easily install your application on any apache server.

You now don’t need to run php artisan serve . Your application will directly be running and now you have some magic to show to your colleagues.

Happy learning….

https://medium.com/@bvipul/creating-virtual-host-on-linux-machine-for-your-laravel-applications-the-mighty-guide-70e2c17c0ab7

Thursday, September 3, 2020

PHP vs. Node.js

 


PHP and Node.js are both used for the server side development and thus have become a competitor for each other. Below are some differences based on different parameters to understand the two and make decision between the two giants.


https://www.geeksforgeeks.org/php-vs-node-js/

Npm Vs Yarn

 Fetching packages

  • npm: npm fetches dependencies from the npm registry during every ‘npm install‘ command.
  • Yarn: yarn stores dependencies locally, and fetches from the disk during a ‘yarn add‘ command (assuming the dependency(with the specific version) is present locally).

Commands changed in yarn after npm

COMMANDNPMYARN
Install dependenciesnpm installyarn
Install packagenpm install package_name
npm install package_name@version_number
yarn add package_name
yarn add package_name@version_number
Uninstall packagenpm uninstall package_nameyarn remove package_name
Install dev packagenpm install package_name –save-devyarn add package_name –dev
Update dev packagenpm update package_name
npm update package_name@version_number
yarn upgrade package_name
yarn upgrade package_name@version_number
View packagenpm view package_nameyarn info package_name
Global install packagenpm install -g package_nameyarn global add package_name

Commands same for npm and yarn:

NPMYARN
npm inityarn init
npm run [script]yarn run [script]
npm listyarn list
npm testyarn test
npm linkyarn link
npm login or logoutyarn login or logout
npm publishyarn publish

Laravel boiler plate

 https://github.com/rappasoft/laravel-boilerplate?fbclid=IwAR1TvlPxfY5vRSaEO2g_6lUpaNvHzAYPWNJtRocBjnktz7AxaxtZnqOSzK4

Tuesday, September 1, 2020

Laravel course materials


INTRODUCTION

- Introduction to Laravel.

- Course Outline.

- Familiarise with real world web development.

OOP & DESIGN PATTERNS IN PHP

- Basic Object Oriented Programming Concepts

- Why we need design patterns

- The SOLID design principles

- Creational Design Patterns

- Design patterns (Factory, Abstract Factory, Builder Prototype, Singleton, Prototype, Facades)


SETTING UP LARAVEL ENVIRONMENT

The "Conventional" Way   - WAMP/XAMPP

- Composer

- Apache

- MYSQL

- Redis

Using Docker (Bonus)

- DOCKER

- NGINX

- MYSQL

- PHP

- Redis

- LINUX

Introduction to Version Controlling System

- Git

- Github  Introduction to AWS

- Free tier account in AWS

- AWS Basics (Regions, Availability Zones, IAM, EC2, ELB)

- SSH into your own EC2 instance


UNDERSTANDING LARAVEL ARCHITECTURE CONCEPTS

- Request Lifecycle

- Service Container

- Service Providers

- Facades

- Contracts


SIMPLE TODO APP USING BLADE & BOOTSTRAP

- Database schema design

- Create database tables using migrations

- Configuring Models & Relations

- Web Routing

- Middleware

- Controller

- Authentication

- CRUD with Eloquents & Query Builder

- Views

- Frontend development with blade and JS/JQuery & bootstrap

- Notifications

- Settings


BUILDING AN INSTAGRAM CLONE PART 1 (SYSTEM ANALYSIS)

- Requirements assessment

- Capacity estimations

- Highlevel system & Database design

- Component Design

- Reliability & Consistency

- Performance Optimization Evaluation


BUILDING AN INSTAGRAM CLONE PART 2 (DATABASE AND MODEL CONFIGURATION)

- Schema Design

- Creating migrations using schema definition

- Create and setting up models with relations


BUILDING AN INSTAGRAM CLONE PART 2 (API DEVELOPMENT)

API development in Laravel  API Authentication

- OAuth

- Passsport

- Access Tokens  Basic API Stuffs

- Routing - API validations & Error Responses  Users API

- Sign Up

- Login

- Email Verification (with AWS SES)

- Password Reset (AWS SES)

- Follow/Unfollow user

- User Profile  Posts API

- Creating posts - Uploading Images (with AWS S3)

- Optimisation 1: Queue Post Creation (with AWS SQS)

- Fetching posts

- Optimisation 2: Paginate posts

- Rank posts

- Optimisation 3: Schedule post ranking algorithm

- Optimisation 4: Query Caching with Redis

- Post Details  Reactions API - Reaction CRUD

- Count Reactions/Post in post list api (Like/Comments)

- Load Reactions in Posts (Dashboard)

- Load paginated comments in post details


BUILDING AN INSTAGRAM CLONE PART 3 (FRONTEND DEVELOPMENT)

- Typescript Basics

- Single Page Application (SPA) vs Server Side Rendering (SSR)

- Setting up SSR with express and nodejs

- Authentication & cookie management

- Express Routing

- Setting up Vue CLI & Vuetify

- Setting up CSS preprocessor (SCSS)

- Configuring API client

- Posting and fetching data with api client

- Component Design

- Data management with VUEX

- Front end Development

- Sing Up/Login Page

- Dashboard with infinite scroll pagination

- Profile Page

- Notifications

- Inbox

- Testing (Unit, E2E)

- Bundling (Webpack) & Production Build

- Continuous integration with CIRCLE CI


DEPLOYMENT AND PERFORMANCE OPTIMISATION

- Deploying in EC2 with manual configuration

- Load Balancing with AWS ELB


CONCLUSION

- Real life software development scenario

- Practical scenario of Agile based development

- Software development etiquettes & manners


Wednesday, August 26, 2020

Laravel linux server setup process steps

 "nano /etc/ssh/sshd_config" and "PermitRootLogin yes" for PUTTY access


passwd ----for password change


sudo adduser USERNAME ---for adding new user

usermod -aG sudo USERNAME ---for permission new user


sudo a2ensite your_domain.conf

sudo a2dissite 000-default.conf




https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04

https://www.cloudbooklet.com/upgrade-php-version-to-php-7-4-on-ubuntu/


sudo apt update


sudo apt install curl wget php-cli php-zip php-mbstring git unzip php-xml php7.2-gd


sudo service apache2 restart



php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"


HASH="$(wget -q -O - https://composer.github.io/installer.sig)"


php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"


sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer




sudo a2enmod rewrite


sudo chown -R www-data:www-data /var/www/html/sitedomain


sudo nano /etc/apache2/sites-available/000-default.conf 


then


DocumentRoot /var/www/html/sitedomain/public

ServerName sitedomain.com

CustomLog /var/log/apache2/sitedomain.com-access.log combined

ErrorLog /var/log/apache2/sitedomain.com-error.log

<Directory /var/www/html/sitedomain/public/>

Options +Indexes +Includes +FollowSymLinks +MultiViews

AllowOverride All

Require all granted

</Directory>


sudo service apache2 restart


https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/starting.html#using-a-different-port


MAIL_HOST=smtp.sendgrid.net

MAIL_PORT=587

MAIL_USERNAME=apikey

MAIL_PASSWORD=pass

MAIL_ENCRYPTION=null


truncate -s0 error.log //for truncate any file

rm storage/logs/laravel-*.log //delete all log file


vim /etc/mysql/mysql.conf.d/mysqld.cnf

systemctl restart mysql.service



[program:websockets]

command=/usr/bin/php /var/www/html/sitedomain/artisan websockets:serve --port=3030

numprocs=1

autostart=true

autorestart=true

user=root

stdout_logfile=/var/www/html/sitedomain/websockets.log


[program:websockets]

command=/usr/bin/php /var/www/sitedomainlive/artisan websockets:serve --port=3030

numprocs=1

autostart=true

autorestart=true

user=root

stdout_logfile=/var/www/sitedomainlive/websockets.log




[program:laravel-worker]

process_name=%(program_name)s_%(process_num)02d

command=php /var/www/html/sitedomain/artisan queue:work --sleep=3 --tries=3

autostart=true

autorestart=true

user=root

numprocs=8

redirect_stderr=true

stdout_logfile=/var/www/html/sitedomain/worker.log

stopwaitsecs=3600



https://stillat.com/blog/2016/12/07/laravel-task-scheduling-running-the-task-scheduler


crontab -e //adding cron entry to cron tab

sudo service cron restart



[program:laravel_corn]

command=* * * * * php /var/www/html/sitedomain/artisan schedule:run >> /dev/null 2>&1

process_name=%(program_name)s_%(process_num)02d

numprocs=1

autostart=true

autorestart=true

startsecs=0

user=www-data

redirect_stderr=true

stderr_logfile = /var/www/html/sitedomain/laravel_corn_err.log

stdout_logfile = /var/www/html/sitedomain/laravel_corn_stdout.log

stdout_logfile_maxbytes=10MB

stdout_logfile_backups=10



sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-worker:*

sudo supervisorctl start websockets


sudo ufw allow 3030/tcp



nano /etc/php/7.2/apache2/php.ini


max_execution_time = 120

max_input_vars = 2500

memory_limit = 128M

post_max_size = 32M

upload_max_filesize = 24M

max_file_uploads = 100


sudo service apache2 restart


ab -k -n 500 -c 50 http://sitedomain.com/ //apache branch mark testing for 500 request and 50 concurent user


sudo chown -R $USER:www-data storage

sudo chown -R $USER:www-data bootstrap/cache

chmod -R 775 storage

chmod -R 775 bootstrap/cache

ps aux | egrep '(apache|httpd)'


MAIL_DRIVER=smtp

MAIL_HOST=smtp.sendgrid.net

MAIL_PORT=587

MAIL_USERNAME=apikey

MAIL_PASSWORD=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

MAIL_ENCRYPTION=null



Include /etc/letsencrypt/options-ssl-apache.conf


sudo chown -R $USER:www-data /etc/letsencrypt/live/sitedomain.com

chmod -R 775 /etc/letsencrypt/live/sitedomain.com


//for ssl 

LARAVEL_WEBSOCKETS_HOST=sitedomain.com

LARAVEL_WEBSOCKETS_SCHEME=https

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/etc/letsencrypt/live/sitedomain.com/fullchain.pem

LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/etc/letsencrypt/live/sitedomain.com/privkey.pem

LARAVEL_WEBSOCKETS_ENCRYPTED=true

MIX_LARAVEL_WEBSOCKETS_ENCRYPTED="${LARAVEL_WEBSOCKETS_ENCRYPTED}"


//withour ssl

LARAVEL_WEBSOCKETS_HOST=

LARAVEL_WEBSOCKETS_SCHEME=

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=

LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=

LARAVEL_WEBSOCKETS_ENCRYPTED=false

MIX_LARAVEL_WEBSOCKETS_ENCRYPTED="${LARAVEL_WEBSOCKETS_ENCRYPTED}"