Tuesday, August 27, 2024

Step-by-step tutorial for beginners to set up a Django project on Ubuntu:

 Step 1: Install Python and Pip

 Update the package list:

sudo apt update 

Install Python 3 and pip:
sudo apt install python3 python3-pip -y

Verify the installation:
 python3 --version
pip3 --version

Step 2: Install Virtual Environment

Install venv (if not installed):

sudo apt install python3-venv -y
 

Create a virtual environment: Navigate to your project directory and create the environment:

mkdir my_django_project
cd my_django_project
python3 -m venv env
 

Activate the virtual environment:

source env/bin/activate
Your terminal prompt should now show (env).

 

Step 3: Install Django

Install Django:

pip install django
 

Verify the installation:

django-admin --version


Step 4: Start a Django Project 

Create a new project:

django-admin startproject mysite

Navigate to the project directory:

 cd mysite
To verify that everything is working, run the Django development server.

python3 manage.py runserver
Step 7: Create a View

Edit myapp/views.py:

from django.shortcuts import render

def home(request):
    return render(request, 'home.html')


Create a URL pattern: Edit mysite/urls.py to include your app’s view: 

from django.contrib import admin
from django.urls import path
from myapp import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home),
]

Run the server again:
python3 manage.py runserver

Step 8: Create a Template

mkdir -p myapp/templates
 

Create an HTML file myapp/templates/home.html:

<!DOCTYPE html>
<html>
<head>
    <title>Django App</title>
</head>
<body>
    <h1>Welcome to Django!</h1>
</body>
</html>

Modify the view to render the template: In myapp/views.py:
from django.shortcuts import render

def home(request):
    return render(request, 'home.html')
 

Run the server and refresh the browser. You should now see the HTML content rendered.

 

Friday, August 9, 2024

Steps to install Laravel 11 project

 

Ubuntu 22.04, Apache

  • PHP >= 8.2
  • MySQL or other database server
  • Composer
  • NodeJS
  •  sudo apt-get install php8.2-mysql
     sudo apt-get install php8.2-xml
  •  sudo apt-get install php8.2-mbstring  
  • sudo apt-get install php8.2-curl

How to Install

  1. Clone the project
  2. Go to the project root directory and run composer install and npm install
  3. Create .env file and copy content from .env.example
  4. Run php artisan key:generate from terminal
  5. Change database information in .env
  6. Run migrations by executing php artisan migrate , Then Run php artisan db:seed if you want use faker database records,
  7. Start the project by running php artisan serve
  8. Run in another commandline npm run dev
 REFERENCES:
 
  1. https://github.com/YasserElgammal/blog-cms

php artisan storage:link

Thursday, August 1, 2024

Steps to install Laravel Boiler Plate

1) Git clone https://github.com/rappasoft/laravel-boilerplate.git

2) cd /var/www/html/laravel-boilerplate , set up .env file

3) php artisan key:generate

4) composer install

5) npm install

6) php artisan session:table

7) php artisan migrate