Prerequisites:
1) Create a Digital Ocean Account
2) ssh set up on your local computer
Steps:
1) Create a Droplet
- Using one click install LAMP .
- select standard → $5/month plan → enter ssh keys → enter host name → create droplet button
2) hit ip on the browser to see the site
-----------------------------------------------------------------------------------------------------------------------
To access the site from local machine:
-----------------------------------------------------------------------------------------------------------------------
1) In a new terminal login as the new user
$sshroot@IP_ADDRESS
2)Notemysql password from the locationmentioned during one click installation3) Generate ssh for the server using command
$ssh-keygen
To see the generated keyenter,
$cat .ssh/id_rsa.pub//to display the key
4)Add remote server ssh keyto github→settings→sshkey
-----------------------------------------------------------------------------------------------------------------------
To set up DB
-----------------------------------------------------------------------------------------------------------------------
$mysql -u root -p;$SELECT user,authentication_string,plugin,host FROM mysql.user;$ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY'password'; //passwort from ./root/digital ocean folder$FLUSH PRIVILEGES;to check:$SELECT user,authentication_string,plugin,host FROM mysql.user;$create databasenew_db$usenew_db$sourcepath/to/uploaded/sqlfile //to import the uploaded db to mysql$exit //mysql$sudo service mysql restart
-----------------------------------------------------------------------------------------------------------------------
To set up Project
-----------------------------------------------------------------------------------------------------------------------
1)git clone the folder tovar/wwwdirectory
2)
cd
/var/www
git clone https://github.com/ammezie/laravel-deploy-demo.git3)install composer4)runcomposer install5)set up all the missing extensions
sudo apt-get install -y php7.2-xml
sudo apt-get install -y php7.2-mbstring one by one like above or in one go as shown below:sudo apt install openssl php7.2-common php7.2-curl php7.2-json php7.2-mbstring php7.2-mysql php7.2-xml php7.2-zip
6)
cd laravel-deploy-demo
composer install7) For environment variablescp .env.example .env8) generate an app key usingphp artisan key:generate9) open .envnano.envMakethe followingchangesinto itSince weareon production, we set APP_DEBUG to false. Also, we set APP_URL to our domain name or server IP address (if no domain name has been set up). Remember to update YOUR_DATABASE_USERNAME and YOUR_DATABASE_PASSWORDAPP_NAME=laravel-deploy-demoAPP_ENV=productionAPP_DEBUG=falseAPP_URL=http://DOMAIN_NAME_OR_IP_ADDRESSDB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=laravel-deploy-demoDB_USERNAME=YOUR_DATABASE_USERNAMEDB_PASSWORD=YOUR_DATABASE_PASSWORD
$
sudo
chown -R www-data: storage
$
sudo
chmod -R 755 storage
-----------------------------------------------------------------------------------------------------------------------
To take the Project Live
-----------------------------------------------------------------------------------------------------------------------
17) Finally we need to point our server to the Laravel project public folder. We need to edit our Apache config
nano /etc/apache2/sites-enabled/000-default.conf
There are two lines in this config file that we need to updated
DocumentRoot
/var/www
<Directory /var/www>
We need to change them to point the public folder in our project public folder
DocumentRoot
/var/www/project/public
<Directory /var/www/project/public>
Also we need to add the following two lines inside of that same Directory tag
RewriteEngine
On
RewriteBase /var/www/project/public
Once that’s finished and saved enter
a2enmod rewrite
we
need to restart Apache
$ sudo service apache2 restart
In case of error:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
$sudo nano /etc/apache2/apache2.confadd to the end of fileServerName 64.xxx.xx.xxx
sudo systemctl restart apache2
References:
https://scotch.io/tutorials/deploying-laravel-to-digitalocean
----------------------------------------------------------------------------------------------------------------------
Additional things you may do:
------------------------------------------------------------------------------------------------------------------------
1)set up phpmyadmin
2) login to the server as non root user with admin prevelege for security.
from local computer enter the command to access server:
ssh root@IP_ADDRESS
then create a new user using command
addusernew_user
3) To give new user sabi admin preveleges
usermod
-aG sudo new_user
4)copy
public key to your new server
cat ~/.ssh/id_rsa.pub //run local to get public key5) In the server give the command assu -user6) we need to create a new directory called .ssh and restrict its permission:mkdir ~/.sshchmod 700 ~/.ssh7) Within the .ssh directory, create a new file called authorized_keys:touch ~/.ssh/authorized_keys8)open the file using cmdvim ~/.ssh/authorized_keys //paste ssh copied from local here9) esc shift :wq + enter10) restrict permissions of authorised file using the command:chmod 600 ~/.ssh/authorized_keys //restrict permissionexit //return to root10) hit ip address
No comments:
Post a Comment