Laravel is a popular PHP framework that allows developers to build web applications quickly and easily. In this tutorial, we will guide you through the process of installing and configuring Laravel with Apache on Ubuntu.
The first step is to install the Apache web server on your Ubuntu machine. You can do this by running the following command in the terminal:
Once the installation is complete, you can start the Apache service by running the command:
Laravel requires PHP to be installed on your machine. You can install PHP 8 and its dependencies by running the following command:
Laravel uses a database to store data, so you will need to install and configure MySQL. To install MySQL, run the following command:
Once the installation is complete, you can configure MySQL by running the command:
This command will prompt you to set the root password for your MySQL server, remove anonymous users, disable remote root login, and delete the test database.
Next, you can log in to the MySQL server using the root account by running the command:
You will be prompted to enter the password for the root user.
Once you are logged in, you can create a new database for your Laravel application by running the following command:
You can also create a new user and grant them access to the database by running the following commands:
You should replace your_database, your_username, and your_password with the desired values for your application.
You can then exit the MySQL prompt by running the command:
It is important to note that you should update the .env file with the correct database name, username, and password so that Laravel can connect to the database.
You have now successfully installed and configured MySQL for use with your Laravel application.
Composer is a dependency manager for PHP that is used to install Laravel. You can install Composer by running the following command:
Once you have installed Composer, you can use it to install Laravel by running the following command:
This will create a new directory called "your-project-name" that contains the Laravel files.
The final step is to configure Apache to work with Laravel. You can do this by creating a new virtual host file in the Apache configuration directory. To do this, run the following command:
Then, add the following contents to the file:
Save the file and then enable the new virtual host by running the following command:
Finally, restart the Apache service by running the command:
That's it! You have now successfully installed and configured Laravel with Apache on Ubuntu. You can now access your Laravel application by navigating to "your-project-name.com" in your web browser.
Please make sure to also check the permission and ownership of the files and folder in your project, and also check the mod_rewrite module is enabled
Additionally, you can also run the following command inside your project directory to give the correct permissions for storage and bootstrap/cache folders
You are now ready to start building your Laravel application!