Install LAMP stack on Ubuntu server with all the necessary settings

Login to digital ocean using password or ssh that is created at time of droplet created

ss root@ip_address_of_droplet

Create new user for server

adduser username
 

Switch to new user account

sudo su username
 

Switch to root user

sudo su root
 

add admin previliges to new user

usermod -aG admin username
 
initially new user will not have any .ssh account that store ssh keys
 

create new folder .ssh

mkdir .ssh
 

switch to .ssh folder

cd .ssh
 

Create new ssh keys(can be create in local system)

ssh-keygen -t rsa -b 4096 -C "capscom"
 
you will get this key at C:/users/admin/.ssh
 

Open id_rsa.pub 

 
cat ~/.ssh/id_rsa.pub
 
Now paste the keys at authorized_keys file
 

edit authorized_keys file

vim authorized_keys
 
Note: for login keep ssh keys within a file authorized_keys
 

login using ssh

ssh -i ~/.ssh/id_server username@ip_address_of_server
 

Now restrict root login and login with password

 
sudo vim /etc/ssh/sshd_config
 
  1. set "no" to PermitRootLogin
  2. set "no" to PasswordAuthentication
 
 

As ssh file changed then restart the ssh service

sudo service ssh restart
 

Now install LAMP on server

 

first update the package manager apt-get

sudo apt-get update
 

Now check the latest php version to be install

sudo apt-cache search php
 

Now install the php cli

sudo apt-get install php8.1-cli
 

You can also add repository for php

sudo add-apt-repository ppa:ondrej/php
 

Now also update package manager

sudo apt-get update
 

Now install all the php extension

sudo apt-get install -y php8.1-cli php8.1-fpm php8.1-mbstring php8.1-mysql php8.1-curl php8.1-mcrypt php8.1-xml
 

Now install the mysql server

sudo apt-get install mysql-server
 

Now install nginx

sudo apt-get install nginx
 

Check nginx installed or not

ll /etc
 

Now install the git

sudo apt-get install git
 

Now install zip and unzip extension

sudo apt-get install zip unzip
 

Now login with the user

  1. and create new ssh key with id id_rsa
  2. and copy the key and place it at the git configuration deploy keys
 

Now check connection between server and git using ssh keys 

ssh -T git@github.com
 

Now clone the git repo at server's html folder or any

git clone repo_address

and as we can see our project not at /var/www/html folder
it is at the root html folder
 

first visit to cd /var/www

and remove the html folder by

	sudo rm -rf html
 

then visit to the root folder by cd

now move the html folder at /var/www by

sudo mv html /var/www/

Now install the composer and update the composer with all the necessary packages.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
 

Check composer installed or not

composer
Note: you will see message composer(formatted)
 

Now composer will install the packages

composer install --no-dev
 

Now create .env file using the .env.example file

cp .env.example .env

Now create project key

php artisan key:generate
 

Now configure the nginx

 
cd /etc/nginx/sites-available
 
sudo vim default
 

change 

root /var/www/html; 
to
root /var/www/html/public;
 

change

index index.html index.htm index.nginx-deb;
to
index index.html index.htm index.php;
 

change

try_Files $uri $uri/ =404;
to
try_Files $uri $uri/ /index.php?is_args$args;
 

uncomment

  1. location ~ \.php${
  2. include snippets/fastcgi-php.conf;

uncomment and change the line

  1. fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    to
  2. fastcgi_pass unix:/run/php/php8.1-fpm.sock;(Latest or installed php version)
 

uncomment closing line        }

 

Now restart and reload the nginx after new configuration

  • sudo service nginx restart
  • sudo service nginx reload
 
 

Now change the mode of folder storage 

Note: run this command by visiting cd /var/www/html folder
sudo chmod -R 777 storage
 

Now create database from the mysql and user

CREATE DATABASE database_name;
 

Now create the user and password for the database.

CREATE USER IF NOT EXISTS username@localhost identified by 'password';
 

Now grant all the privileges to the user for a database.

grant all privileges on database_name.* to username@localhost;
 

Now check the privileges for the selected user

show grants for username@localhost;
Note: if you see message like  grant all privileges on.
 

Now change the .env file

  • change database
  • change username
  • change password
© 2016 - 2022, All Rights are Reserved.