Setup Laravel in Ubuntu
I am beginning with the assumption that you have installed Ubuntu in your VPS, if in case you do not have setup ubuntu in your VPS server then there are many more videos available on youtube, you just need is to move your finger over your keyboard and search whatever you would like to, see its too simple.
Let's begin,
First lets check whether there is Apache configured in the server or not using following Command in your terminal:
sudo systemctl status apache2
If the system could not found the apache related information then, next step is to install apache in our ubuntu server:
sudo apt install apache2
The system will do its job after some time you will see it installed successfully, now let's check it out once again using the above command.
To ensure it is working using browser, go to the web browser and then provide IP (127.0.0.1) or (localhost) in URL then you will see the apache default page in a browser.
Second Step
we need to install PHP in the ubuntu server for that here is the basic command you need to use:
apt-get update
then,
sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-bcmath php-tokenizer php-json php-pear
here, the above command will help you to install PHP along will commonly use packages of PHP that will be used by Laravel.
now let's check PHP information, for that
create a new file let's say, first.php in /var/www/html/
sudo nano /var/www/html/first.php
call to PHP info function from the file:
<?php
phpinfo();
?>
now in browser: localhost/first.php
this will give output will PHP information in detail.
Step Three
Now, we are going to setup database :
here we will be using MySQL.
Command to install MySQL is listed below :
sudo apt install mysql-server
After installation , to setup more,
sudo mysql_secure_installation
After this you will be asked some yes-no questions , and here is the answer:
Y,N,Y,Y
see, how simple it is, but wait, did you get the questions?
here they are :
Remove anonymous users? [Y/n] → y
Disallow root login remotely? [Y/n] → n
Remove test database and access to it? [Y/n] → y
Reload privilege tables now? [Y/n] →y
now its fine,
Now, we are ready to setup database and new user first:
log into MYSQL as root:
mysql -u rootGrant privileges. To a new user execute:
CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’; GRANT ALL PRIVILEGES ON *.* TO ‘newuser’@’localhost’; FLUSH PRIVILEGES;Grant Permissions to the user :
GRANT ALL PRIVILEGES ON `%`.* TO ‘newuser’@’localhost’;Bind to all addresses:
The easiest way is to comment out the line in your :/etc/mysql/mysql.conf.d/mysqld.cnf
then comment the line as shown below:
#bind-address = 127.0.0.1now,
exit mysql;
exit service mysql restart
Now, lets setup composer :
curl -sS https://getcomposer.org/installer | php
now, after complete installation, make the composer globally available:
sudo mv composer.phar /usr/local/bin/composersudo chmod +x /usr/local/bin/composer
We are ready to get started with our new project :
cd to the location where you want to create project:
then,
composer create-project --prefered-dist laravel/laravel newproject_name
now cd to the project and then :
php artisan serve
your setup is done , oh yeah ,
now go to your browser and check :
localhost:8000
now, how to connect to the database?
how to setup env file ?
how to deploy on server?
There are many points to be covered, If you really are interested to make me discuss those, please comment.
Thank you,