Some things you need :
- Laravel project
- VPS / Virtual Private Server
- Domain (if any)
-
Put your Laravel project into source code management (github/gitlab/others)
Here I will use my company-management reporsitory.
https://github.com/alfajrimutawadhi/company-management -
Create a personal access token
This token is used to clone your project to the server later. You can directly create a personal access token at https://github.com/settings/tokens/new
Write notes as you wish and check only the repo section, then immediately click generate at the very bottom.
After success, copy or save the token for later use
-
Setup server
You can login to the terminal server using ssh, to install the database and some required dependencies-
Install the database according to your Laravel database (here I use mysql)
sudo apt-get install mysql-server
*do not forget to create a database after installing this
-
Install PHP-FPM and some PHP extensions
sudo apt-get install software-properties-common sudo add-apt-repository -y ppa:ondrej/php sudo apt update
*according to the PHP version you need
sudo apt install php8.1-fpm php8.1-common php8.1-mysql php8.1-xml php8.1-ctype php8.1-curl php8.1-gd php8.1-dom php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-soap php8.1-zip php8.1-bcmath php8.1-fileinfo php8.1-pdo php8.1-tokenizer -y
-
Install NGINX
sudo apt install -y nginx
-
Install composer
sudo apt install -y composer
-
-
Clone Laravel application
-
Resetup Laravel application
-
Go to your application folder and change the .env.example file to .env
cd /srv/app mv .env.example .env
-
Reset .env file (here I use vim)
vim .env
*Change the APP_DEBUG value to false and fill in the APP_URL with your IP or domain
-
Added vendor, migration and optimization folders
composer update composer install --optimize-autoloader --no-dev php artisan migrate php artisan key:generate php artisan config:cache php artisan route:cache php artisan view:cache sudo chmod -R 775 public && sudo chmod -R 777 storage
-
-
Set NGINX configuration
vim /etc/nginx/sites-enabled/default
- Delete all contents of the file and please paste with the configuration below :
server { listen 80; listen [::]:80; server_name domain.com; #change with your domain root /srv/app/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff"; index index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; } location ~ /\.(?!well-known).* { deny all; } }
- restart NGINX
nginx -s reload
- Delete all contents of the file and please paste with the configuration below :
If you have a domain and you want your web application to be accessible using HTTPS, you can follow the method below:
-
Enter your Laravel folder
cd /srv/app
-
Add this code in folder
app/Providers/AppServiceProvider.php
(here I use vim)public function boot() { if(config('app.env') === 'production') { \URL::forceScheme('https'); } }
-
Modify the Laravel .env file and re-setup config
vim .env
change APP_URL to
https://domain.com
then reset configphp artisan config:cache
-
Install certbot
sudo apt install certbot python3-certbot-nginx
-
Create SSL certificate
certbot --nginx -d domain.com
-
Reload NGINX
nginx -s reload
@Bataino , you can implement several third parties or packages in Laravel, one of which is octane