Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ EXPOSE 80

# Start Supervisor (which will manage nginx, php-fpm, and queue workers)
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

2 changes: 1 addition & 1 deletion app/Services/Messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getAllDirectChats()
{
return Chat::query()->whereHas('users', fn($q) => $q->where('users.id', auth()->id()))
->withCount('users')
->having('users_count', 2)
->where('users_count', 2)
->get();
}

Expand Down
42 changes: 42 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
server {
listen 80;
listen [::]:80;
server_name smile.thathsara.lk;
root /srv/smile/public;

proxy_force_ranges on;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

index index.php;

charset utf-8;

client_max_body_size 5m;

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.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
}

location ~ /\.(?!well-known).* {
deny all;
}
}





98 changes: 98 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

# Prompt for user input
read -p "Enter the username (e.g., nonroot): " USERNAME
read -p "Enter the website name (e.g., insight): " WEBSITE_NAME
read -p "Enter the domain name (e.g., insight.thathsara.lk): " DOMAIN_NAME

# Update and upgrade system
sudo apt update
sudo apt upgrade -y

# Install PHP and required extensions
sudo apt install php8.3-fpm php8.3 php8.3-curl php8.3-mbstring php8.3-bcmath php8.3-sqlite3 php8.3-zip php8.3-xml -y

# Install additional tools
sudo apt install nginx -y

# Install Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

# Set up Git repository
mkdir -p /home/$USERNAME/repo/${WEBSITE_NAME}.git
cd /home/$USERNAME/repo/${WEBSITE_NAME}.git
git init --bare
git branch -m main

cd hooks

# Create post-receive hook
cat << EOF > post-receive
#!/bin/sh
sudo /sbin/deploy
sudo /sbin/post-deploy
EOF

sudo chmod +x post-receive

# Create deployment script
cat << EOF | sudo tee /sbin/deploy
#!/bin/sh
git --work-tree=/srv/$WEBSITE_NAME --git-dir=/home/$USERNAME/repo/${WEBSITE_NAME}.git checkout -f
EOF

sudo chmod +x /sbin/deploy

# Create post-deploy script
cat << EOF | sudo tee /sbin/post-deploy
#!/bin/sh
cd /srv/$WEBSITE_NAME
cp ./nginx.conf /etc/nginx/sites-available/$WEBSITE_NAME
sudo ln -sf /etc/nginx/sites-available/$WEBSITE_NAME /etc/nginx/sites-enabled/$WEBSITE_NAME
sudo certbot --nginx --reinstall -d $DOMAIN_NAME
sudo nginx -s reload
sudo chown -R :www-data /srv/$WEBSITE_NAME
sudo chmod -R 775 /srv/$WEBSITE_NAME/storage
sudo chmod -R 775 /srv/$WEBSITE_NAME/bootstrap/cache
sudo chmod -R 775 /srv/$WEBSITE_NAME/database
cp --update=none ./.env.example ./.env
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader
sudo npm i
sudo npm run build
EOF


sudo chmod +x /sbin/post-deploy

# Create application directory
sudo mkdir -p /srv/$WEBSITE_NAME

# Configure sudoers
echo "$USERNAME ALL=NOPASSWD: /sbin/deploy, /sbin/post-deploy" | sudo EDITOR='tee -a' visudo

# Set up Nginx
sudo rm -f /etc/nginx/sites-enabled/default

# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt-get install -y nodejs

# Set up Laravel environment
cd /srv/$WEBSITE_NAME
sudo php artisan key:generate
sudo php artisan migrate

# Install and configure Certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d $DOMAIN_NAME --email thathsaramadhhusha@gmail.com --agree-tos --eff-email

sudo certbot renew --dry-run

echo "Setup complete!"

28 changes: 28 additions & 0 deletions stage1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Prompt for user input
read -p "Enter the username (e.g., nonroot): " USERNAME
read -p "Enter the website name (e.g., insight): " WEBSITE_NAME
read -p "Enter the domain name (e.g., insight.thathsara.lk): " DOMAIN_NAME

# Update and upgrade system
sudo apt update
sudo apt upgrade -y

# Install nginx
sudo apt install nginx -y


# Install PHP and required extensions
sudo apt install php8.4-fpm php8.4-curl php8.4-mbstring php8.4-bcmath php8.4-sqlite3 php8.4-zip php8.4-xml -y

# Install Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer


bullshit

Loading