Laravel Project Initialization Script

This script automates the process of creating a new Laravel project, setting up Git, and providing instructions for further setup. It streamlines the initial setup process and helps you get started quickly with a fresh Laravel installation.

Prerequisites

  • Python: This script requires Python to be installed on your system.
  • Composer: The script uses Composer to create the Laravel project.
  • Git: Git is needed for initializing the repository.

Creating a Convenient Shortcut for the Script

By adding the script to the /usr/bin directory, you can execute it from anywhere in the terminal by simply typing laravel-new. Here’s how you can set it up:

  1. Save the file with the name laravel-new or any other name you prefer.
  2. Open a terminal and navigate to the directory where you saved the laravel-new file.
  3. Make the script executable by running the following command:
   chmod +x laravel-new
  1. Move the script to the /usr/bin directory using the following command:
   sudo mv laravel-new.py /usr/bin/laravel-new

You will be prompted to enter your password to complete the move operation.

  1. Verify that the script has been successfully moved by running:
   ls -l /usr/bin/laravel-new

You should see the script listed.

  1. Now, you can run the script from anywhere in the terminal by simply typing:
   laravel-new

The script will be executed, and the Laravel project setup process will begin.

Note: Make sure that the /usr/bin directory is in your system’s PATH variable for the laravel-new command to be recognized. If it’s not in the PATH, you can either add it or use an alternative directory that is already in the PATH.

Using the laravel-new Command

With the laravel-new command set up, you can now create a new Laravel project by following these steps:

  1. Open a terminal.
  2. Navigate to the desired directory where you want to create your Laravel project.
  3. Run the following command:
   laravel-new

The script will be executed, and the Laravel project setup process will begin.

  1. Follow the prompts and instructions provided by the script to complete the project setup.
  • Composer will create the Laravel project.
  • Git will be initialized and an initial commit will be made.
  • The script will display a message indicating that Laravel is ready for further configuration.
  • The script will remove itself from the system.

Now you can easily create new Laravel projects by simply running the laravel-new command from any directory in the terminal.

Note: Remember to ensure that your system has the necessary prerequisites (Python, Composer, and Git) installed and properly configured for the script to execute successfully.

Manual Usage

  1. Make sure you have met the prerequisites mentioned above.
  2. Open a terminal or command prompt.
  3. Run the script using the following command:
   python create_laravel_project.py
  1. The script will execute the necessary commands to create a new Laravel project, set up Git, and provide instructions for further configuration.

Script Explanation

The script performs the following actions:

  1. Creates a new Laravel project using Composer:
   os.system('composer create-project --prefer-dist laravel/laravel')
  1. Moves the contents of the newly created laravel directory to the current directory:
   os.system('mv  laravel/*.* .')
   os.system('mv  laravel/* .')
   os.system('mv  laravel/.* .')
  1. Lists the files in the current directory to verify the successful move:
   os.system('ls -l')
  1. Removes the empty laravel directory:
   os.system('rm -r laravel')
  1. Initializes a Git repository and makes an initial commit:
   os.system('git init')
   os.system('git add .')
   os.system('git commit -m "Initial commit" ')
  1. Displays a message indicating that Laravel is ready for further setup:
   print(' +-----------------------------------------------------+')
   print(' | >>> Awesome Laravel is Ready                        |')
   print(' +-----------------------------------------------------+')
   print(' | >>> Change the Database Credentials in .env         |')
   print(' | >>> Ready to build |')
   print(' +-----------------------------------------------------+')
  1. Removes the script itself:
   os.system('rm laravel-new')

Disclaimer

This script assumes that the necessary dependencies (Composer, Git) are properly installed and configured on your system. It’s always a good practice to double-check and ensure that your environment is set up correctly before running any automation scripts.

https://github.com/devuri/python-laravel-new

#!/usr/bin/env python

import os
print('Creating New Laravel Project')

# run composer to create the project
os.system('composer create-project --prefer-dist laravel/laravel')
os.system('mv  laravel/*.* .')
os.system('mv  laravel/* .')
os.system('mv  laravel/.* .')
os.system('ls -l')
os.system('rm -r laravel')

# setup git
print('Lets add to git')
os.system('git init')
os.system('git add .')
os.system('git commit -m "Initial commit" ')

# laravel is ready
os.system('php artisan')
print(' +-----------------------------------------------------+')
print(' | >>> Awesome Laravel is Ready                        |')
print(' +-----------------------------------------------------+')
print(' | >>> Change the Database Credentials in .env         |')
print(' | >>> Ready to build |')
print(' +-----------------------------------------------------+')
os.system('rm laravel-new')