How To Install Laravel 11 on CentOS: A Step-by-Step Guide
Welcome back to the Greenhost.cloud blog! If you’re looking to set up a powerful web application framework, Laravel is one of the best choices available today. With the recent release of Laravel 11, developers have a host of new features and enhancements at their fingertips. In this post, we’ll walk you through the steps to install Laravel 11 on a CentOS server. Whether you’re a seasoned developer or a beginner, this guide aims to make the installation process straightforward and enjoyable.
Prerequisites
Before we dive into the installation process, ensure you have the following prerequisites:
- A CentOS Server: This guide is applicable for CentOS 7 and 8 versions.
- Root or Sudo Access: You need root or sudo privileges to install packages and configure the server.
- PHP Installed: Laravel 11 requires PHP 8.1 or higher, so make sure it’s installed on your system.
- Composer: Laravel uses Composer for dependency management, so you’ll need it installed on your server.
Step 1: Update Your System
Start by updating your CentOS system to ensure that all packages are up-to-date. Open your terminal and run the following command:
sudo yum update -y
Step 2: Install Required PHP Extensions
Next, you need to install the necessary PHP extensions required by Laravel. Run the following command:
sudo yum install php php-cli php-fpm php-json php-mbstring php-xml php-mysqlnd php-zip php-curl php-xmlrpc -y
Step 3: Install Composer
Composer is essential for managing Laravel’s dependencies. You can install Composer globally by following these commands:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
To verify that Composer is installed correctly, run:
composer --version
Step 4: Install Laravel 11
Now that you have Composer installed, you can easily create a new Laravel project. Navigate to the directory where you want to install Laravel and run:
composer create-project laravel/laravel my-laravel-app "11.*"
Replace my-laravel-app
with your desired directory name. This command will download the latest Laravel 11 version and set up a new application in the specified directory.
Step 5: Configure Environment Variables
Navigate to your Laravel application directory:
cd my-laravel-app
Copy the example environment file to create your own .env
file:
cp .env.example .env
Now, you need to configure your database connection and other settings in the .env
file. Open it with your favorite text editor, for example:
nano .env
Make sure to update the DB_DATABASE
, DB_USERNAME
, and DB_PASSWORD
fields with your database information.
Step 6: Generate Application Key
Laravel requires an application key, which can be generated using the following command:
php artisan key:generate
Step 7: Set Permissions
Set the appropriate permissions for the storage and bootstrap/cache directories to ensure Laravel can write to these locations:
sudo chown -R $USER:$USER storage bootstrap/cache
Step 8: Start the Development Server
You can start the built-in PHP development server to test your Laravel application:
php artisan serve
By default, the application will be available at http://localhost:8000
. Open your web browser and navigate to this URL to see your new Laravel 11 application in action!
Conclusion
Congratulations! You have successfully installed Laravel 11 on your CentOS server. From here, you can start building your application using the powerful features Laravel has to offer. Feel free to explore the Laravel documentation for more details on routing, middleware, and other functionalities.
If you encounter any issues along the way or have any questions, don’t hesitate to reach out to the Greenhost.cloud community.
We hope you found this guide helpful! For more tips, tutorials, and updates on web development, be sure to follow our blog at Greenhost.cloud.