{"id":36,"date":"2024-09-18T18:00:43","date_gmt":"2024-09-18T09:00:43","guid":{"rendered":"https:\/\/www.pinkgold.space\/?p=36"},"modified":"2024-09-23T17:17:06","modified_gmt":"2024-09-23T08:17:06","slug":"how-to-deploy-kutt-on-rocky-linux-release-9-4-blue-onyx","status":"publish","type":"post","link":"https:\/\/www.pinkgold.space\/?p=36","title":{"rendered":"How to Deploy Kutt on Rocky Linux Release 9.4 (Blue Onyx)"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-39 aligncenter\" src=\"https:\/\/www.pinkgold.space\/wp-content\/uploads\/2024\/09\/howtodeploykutt-rocky-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.pinkgold.space\/wp-content\/uploads\/2024\/09\/howtodeploykutt-rocky-225x300.jpg 225w, https:\/\/www.pinkgold.space\/wp-content\/uploads\/2024\/09\/howtodeploykutt-rocky.jpg 576w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/p>\n<p>Deploying the Kutt URL shortener on Rocky Linux 9.4 (Blue Onyx) involves several steps, from setting up your server environment to configuring Docker and troubleshooting potential issues. This guide provides a comprehensive walkthrough based on personal experience to help you get Kutt up and running smoothly.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li><strong>A Rocky Linux 9.4 server:<\/strong> Ensure you have access to a server running Rocky Linux 9.4.<\/li>\n<li><strong>Root or sudo access:<\/strong> You need administrative privileges to install packages and configure the system.<\/li>\n<li><strong>Basic knowledge of Docker and Docker Compose:<\/strong> Familiarity with Docker is essential for this deployment.<\/li>\n<\/ul>\n<h2>Step 1: Update Your System<\/h2>\n<p>First, make sure your server is up to date.<\/p>\n<pre><code>sudo dnf update -y<\/code><\/pre>\n<h2>Step 2: Install Required Packages<\/h2>\n<p>Install Docker, Docker Compose, and other necessary packages.<\/p>\n<pre><code>sudo dnf install -y docker docker-compose git<\/code><\/pre>\n<p>Start and enable Docker service.<\/p>\n<pre><code>sudo systemctl start docker\nsudo systemctl enable docker<\/code><\/pre>\n<h2>Step 3: Clone the Kutt Repository<\/h2>\n<p>Clone the Kutt repository from GitHub.<\/p>\n<pre><code>git clone https:\/\/github.com\/thedevs-network\/kutt.git\ncd kutt<\/code><\/pre>\n<h2>Step 4: Configure Environment Variables<\/h2>\n<p>Create a <code>.env<\/code> file in the root of your cloned repository and add the following configuration. Replace placeholders with your actual values.<\/p>\n<pre><code># .env file\n\n# General settings\nPORT=3000\nNODE_ENV=production\nSITE_NAME=Kutt\nDEFAULT_DOMAIN=yourdomain.com\nJWT_SECRET=your_jwt_secret\n\n# PostgreSQL settings\nDB_HOST=postgres\nDB_NAME=kutt\nDB_USER=postgres\nDB_PASSWORD=your_postgres_password\n\n# Redis settings\nREDIS_HOST=redis\n\n# Gmail SMTP settings\nMAIL_HOST=smtp.gmail.com\nMAIL_PORT=587\nMAIL_SECURE=false\nMAIL_USER=your_gmail_address@gmail.com\nMAIL_PASSWORD=your_app_password\n\n# URL length\nLINK_LENGTH=6\n\n# Google Safe Browsing API (optional)\n# GOOGLE_SAFE_BROWSING_KEY=\n\n# Recaptcha (optional)\n# RECAPTCHA_SECRET_KEY=\n# RECAPTCHA_SITE_KEY=\n\n# Google Analytics (optional)\n# GA_TRACKING_ID=\n<\/code><\/pre>\n<h2>Step 5: Configure Docker Compose<\/h2>\n<p>Create or modify the <code>docker-compose.yml<\/code> file to include the necessary services.<\/p>\n<pre><code>version: \"3\"\n\nservices:\n  kutt:\n    image: kutt\/kutt\n    depends_on:\n      - postgres\n      - redis\n    command: [\".\/wait-for-it.sh\", \"postgres:5432\", \"--\", \"npm\", \"start\"]\n    ports:\n      - \"3000:3000\"\n    env_file:\n      - .env\n    networks:\n      - kutt_network\n\n  redis:\n    image: redis:6.0-alpine\n    volumes:\n      - redis_data:\/data\n    networks:\n      - kutt_network\n\n  postgres:\n    image: postgres:12-alpine\n    environment:\n      POSTGRES_USER: postgres\n      POSTGRES_PASSWORD: your_postgres_password\n      POSTGRES_DB: kutt\n    volumes:\n      - postgres_data:\/var\/lib\/postgresql\/data\n      - .\/init.sql:\/docker-entrypoint-initdb.d\/init.sql\n    networks:\n      - kutt_network\n\nvolumes:\n  redis_data:\n  postgres_data:\n\nnetworks:\n  kutt_network:\n    driver: bridge\n<\/code><\/pre>\n<h2>Step 6: Modify Kutt Source Files<\/h2>\n<p>You may need to add logging and troubleshooting code. For example, in <code>server.ts<\/code>, add logging for signup errors.<\/p>\n<pre><code>\/\/ server\/handlers\/auth.ts\n\nexport const signup: Handler = async (req, res) =&gt; {\n  console.log(`Signup request received: ${JSON.stringify(req.body)}`);\n  try {\n    const salt = await bcrypt.genSalt(12);\n    const password = await bcrypt.hash(req.body.password, salt);\n\n    const user = await query.user.add(\n      { email: req.body.email, password },\n      req.user\n    );\n\n    await mail.verification(user);\n\n    return res.status(201).send({ message: \"Verification email has been sent.\" });\n  } catch (error) {\n    console.error(`Error during signup: ${error.message}`);\n    return res.status(500).send({ message: \"Failed to signup. Please try again later.\" });\n  }\n};\n<\/code><\/pre>\n<h2>Step 7: Build and Start Docker Containers<\/h2>\n<p>Build and start your Docker containers.<\/p>\n<pre><code>sudo docker-compose build\nsudo docker-compose up -d<\/code><\/pre>\n<h2>Step 8: Configure Firewall<\/h2>\n<p>Ensure your firewall allows traffic on the necessary ports.<\/p>\n<pre><code>sudo firewall-cmd --permanent --add-port=3000\/tcp\nsudo firewall-cmd --permanent --add-port=5432\/tcp\nsudo firewall-cmd --permanent --add-port=6379\/tcp\nsudo firewall-cmd --permanent --add-port=587\/tcp\nsudo firewall-cmd --reload<\/code><\/pre>\n<h2>Step 9: Test the Deployment<\/h2>\n<ul>\n<li><strong>Access the Kutt web interface:<\/strong> Open your browser and navigate to <code>http:\/\/yourdomain.com:3000<\/code>.<\/li>\n<li><strong>Signup and verify:<\/strong> Register a new account and verify the email using the link sent to your email.<\/li>\n<\/ul>\n<h2>Troubleshooting<\/h2>\n<p><strong>SMTP Issues:<\/strong> If you encounter SMTP connection issues, ensure the firewall settings are correct and the SMTP credentials are accurate.<\/p>\n<p><strong>Database Connection:<\/strong> Verify PostgreSQL and Redis services are running and accessible from the Kutt container.<\/p>\n<p><strong>Logs:<\/strong> Check Docker logs for errors.<\/p>\n<pre><code>sudo docker logs st-kutt-1\nsudo docker logs st-postgres-1\nsudo docker logs st-redis-1<\/code><\/pre>\n<h2>Additional Changes<\/h2>\n<p>You might need to adjust some configurations in your <code>package.json<\/code> to ensure dependencies are installed correctly.<\/p>\n<pre><code>{\n  \"name\": \"kutt\",\n  \"version\": \"2.7.4\",\n  \"scripts\": {\n    \"start\": \"npm run migrate &amp;&amp; cross-env NODE_ENV=production node production-server\/server.js\",\n    \"migrate\": \"knex migrate:latest --env production\",\n    \"build\": \"rimraf production-server &amp;&amp; tsc --project tsconfig.json &amp;&amp; copyfiles -f 'server\/mail\/*.html' production-server\/mail &amp;&amp; next build client\/\"\n  },\n  \"dependencies\": {\n    \"bcryptjs\": \"^2.4.3\",\n    \"cross-env\": \"^7.0.3\",\n    \"express\": \"^4.17.1\",\n    \"knex\": \"^0.95.4\",\n    \"mail\": \"^1.0.0\",\n    \"next\": \"10.0.5\",\n    \"nodemailer\": \"^6.6.3\",\n    \"pg\": \"^8.5.1\",\n    \"rimraf\": \"^3.0.2\",\n    \"ts-node\": \"^9.1.1\",\n    \"typescript\": \"^4.1.3\"\n  }\n}\n<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>Deploying Kutt on Rocky Linux 9.4 involves several steps, but with the correct configurations and troubleshooting, you can get it up and running smoothly. This guide should help you navigate through the process and resolve common issues related to SMTP, Docker, and environment configurations. Happy URL shortening!<\/p>\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Deploying the Kutt URL shortener on Rocky Linux 9.4 (Blue Onyx) involves several steps, from setting up your s &#8230; <a title=\"How to Deploy Kutt on Rocky Linux Release 9.4 (Blue Onyx)\" class=\"read-more\" href=\"https:\/\/www.pinkgold.space\/?p=36\" aria-label=\"Read more about How to Deploy Kutt on Rocky Linux Release 9.4 (Blue Onyx)\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-howto"],"_links":{"self":[{"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=\/wp\/v2\/posts\/36"}],"collection":[{"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36"}],"version-history":[{"count":3,"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pinkgold.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}