
Laravel, a free and open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern is getting more popular in nowadays.
Ubuntu is also getting much attention from the developers because of its extreme configurability and open source nature.
Building powerful applications using Laravel in Ubuntu platform will be lovable to developers.
STEPS
1. INSTALL APACHE2
Laravel requires a web server to run. Apache2 is one of the most famous web server used today.
sudo apt-get install apache2
2. INSTALL MYSQL
When prompted, answer the questions below by following the guide.
Laravel also need a database server. Most using database with php is Mysql.
sudo apt-get install mysql-server mysql-client sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
Enter current password for root (enter for none): (Press Enter) Set root password? [Y/n]: Y New password: (Enter password for mysql DB) Re-enter new password: (Repeat password) Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
3. INSTALL PHP AND IT’S EXTENSIONS
sudo apt-get install php libapache2-mod-php php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt
3. INSTALL COMPOSER
sudo apt-get install composer
4.CHOOSING YOUR PROJECT DESTINATION
In your Ubuntu system, you can choose any destination to do your projects. But in my case, I will choose /var/www/html for doing all projects in Ubuntu. It is just the default root folder of the web server of your Ubuntu system.
cd /var/www/html
5.CREATING NEW APPLICATION
composer create-project laravel/laravel AwesomeProject --prefer-dist
If the above command is failing, use
sudo composer create-project laravel/laravel AwesomeProject --prefer-dist
6. SETTING PERMISSIONS FOR THE PROJECT DIRECTORY
You must set permissions for working with your project directory since as by default your system may only allow you to change the contents in your project directory as root.
On Terminal,
sudo chmod 777 -R /var/www/html/AwesomeProject
- If your project directory is not inside /var/www/html (If you skip 4th step) , then use your own directory url in the top command.
7. CHOOSING THE CODE EDITOR
You can choose your own favorite code editor for editing your project. But in my case, I choose Sublime Text.
From the above link, you can download Sublime Text compatible with Linux system.
An alternative way of installing Sublime Text on your Ubuntu system is
sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo apt-get install sublime-text-installer
8. DIRECTING TO YOUR PROJECT FOLDER AND EDITING
After installing Sublime Text, direct to your project folder.
On Terminal,
cd AwesomeProject
Open your project using Sublime Text by just typing the below command.
On Terminal,
subl .
9. CREATING DATABASE
You have to create a database on your Mysql server which is the DB of your Laravel application.
- Go to https://localhost/phpmyadmin and Enter username and password(As default, the username will be root and password will be your Mysql password).
- Click on the New tab
- Enter a database name
Press Create
10. EDIT .ENV
Edit the .env file on your project folder. If there is no .env file in your project, you have to create a file and paste all the contents from sampe.env to the file you created and save the file with .env filename.
DB_DATABASE=(The database name you created earlier) DB_USERNAME=(Your Mysql username. Usually root) BD_PASSWORD=(Your Mysql password)
11. MIGRATE DATABASE
You have to migrate the database from your Laravel application to your localhost.
On Terminal,
php artisan migrate
12. RUNNING YOUR APPLICATION
On Terminal,
php artisan serv
It will open a new tab on your browser with address http://localhost:8000 .
If you wanted to open the app in another port,
On Terminal,
php artisan serv --port=9000
It will open the app with adress http://localhost:9000 .