How to install laravel project on ubuntu?
To install a Laravel project on Ubuntu, follow these steps:
1. Update and Upgrade the System
Open a terminal and run:
bash
sudo apt update
sudo apt upgrade
2. Install Required Packages
Ensure you have the following installed:
PHP (Laravel requires PHP 7.3 or higher)
Composer (Dependency manager)
Apache/Nginx (Web server)
MySQL/PostgreSQL (Database)
Install them using:
bash
sudo apt install php php-cli php-mbstring php-xml php-curl php-zip unzip curl apache2 libapache2-mod-php mysql-server
3. Install Composer
Composer is essential for managing Laravel dependencies.
Download and install Composer globally:
bash
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Verify the installation:
bash
composer -v
4. Clone or Create a Laravel Project
If you have an existing Laravel project, clone it from your repository:
bash
git clone https://github.com/your-repo/your-laravel-project.git
If you're creating a new project, run:
bash
composer create-project --prefer-dist laravel/laravel your-project-name
5. Configure Environment
Navigate to your project folder:
bash
cd your-project-name
Create a .env file if it doesn’t exist:
bash
cp .env.example .env
Update the .env file with your database credentials:
bash
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
6. Install Project Dependencies
Run Composer to install all the project dependencies:
bash
composer install
7. Generate Application Key
Laravel needs an application key, so run:
bash
php artisan key:generate
8. Set Permissions
Make sure your storage and bootstrap/cache directories are writable by the web server:
bash
sudo chown -R www-data:www-data storage
sudo chown -R www-data:www-data bootstrap/cache
9. Configure Apache (or Nginx)
For Apache:
Create a virtual host configuration file:
bash
sudo nano /etc/apache2/sites-available/your-project.conf
Add the following configuration:
apache
ServerName your-domain.com
DocumentRoot /var/www/your-project-name/public
AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Enable the site and the mod_rewrite module:
bash
sudo a2ensite your-project.conf
sudo a2enmod rewrite
Restart Apache:
bash
sudo systemctl restart apache2
10. Migrate the Database
Run migrations to set up your database:
bash
php artisan migrate
11. Access the Laravel Project
If you set up a domain, visit: http://your-domain.com
If using localhost, visit: http://localhost/your-project-name/public
Your Laravel project should now be up and running on Ubuntu.
Comments
Post a Comment