{"id":4579,"date":"2021-12-31T09:37:30","date_gmt":"2021-12-31T09:37:30","guid":{"rendered":"https:\/\/puvox.software\/blog\/?p=4579"},"modified":"2025-12-25T13:53:33","modified_gmt":"2025-12-25T13:53:33","slug":"configure-lamp-on-vps-with-details","status":"publish","type":"post","link":"https:\/\/puvox.software\/blog\/configure-lamp-on-vps-with-details\/","title":{"rendered":"Configure VPS with details &#038; LAMP"},"content":{"rendered":"<div class=\"default-content-clss content_4579 type_post \">\n<ul>\n<li><strong>Essentials<\/strong>: <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/initial-server-setup-with-ubuntu-22-04\">setup new user &amp; ufw<\/a><\/li>\n<li><strong>Install LetsEncrypt Free SSL<\/strong>: \u00a0<a href=\"https:\/\/www.server-world.info\/en\/note?os=Ubuntu_24.04&amp;p=ssl&amp;f=2\">LE on ubuntu 24<\/a>\u00a0<br \/>&#8211; <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-22-04\">for apache<\/a> <br \/>&#8211; <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-let-s-encrypt-with-nginx-server-blocks-on-ubuntu-16-04\">for-nginx<\/a>\u00a0 <br \/>&#8211; (if different ports needed: <a href=\"https:\/\/serverfault.com\/questions\/1041509\/certbot-letsencrypt-on-custom-port-nginx-or-apache\">here<\/a>\u00a0or <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-acquire-a-let-s-encrypt-certificate-using-dns-validation-with-acme-dns-certbot-on-ubuntu-18-04\">here<\/a>)<\/li>\n<li><strong>Fail2ban<\/strong>:\u00a0<code>sudo apt-get install fail2ban<\/code><\/li>\n<li><span style=\"color: initial; font-size: revert;\"><strong>Disable journal logs<\/strong>:<br \/>Sometimes, if your VPS has problems, journal logs could occupy whole disk space (95%+).<\/span><br \/>&#8211; <code>journalctl --vacuum-size=100M<\/code><br \/>&#8211; <code>sudo sed -i 's\/#SystemMaxUse=\/SystemMaxUse=100M\/' \/etc\/systemd\/journald.conf<\/code><br \/>[ <em>To clear existing cache<\/em>: <code>(sudo find \/var\/log\/journal -name \"*.journal\" | xargs sudo rm) &amp;&amp; (sudo systemctl restart systemd-journald);<\/code> others: <a style=\"font-size: revert;\" href=\"https:\/\/unix.stackexchange.com\/questions\/139513\/how-to-clear-journalctl\">se.com\/how-to-clear-journalctl<\/a> ]<\/li>\n<li><strong>Change default SSH port:<br \/><\/strong>It&#8217;s not requirement, but good thing to change from default <code>22<\/code> to your desired, i.e. <code>12345<\/code>:<br \/>&#8211; desired_ssh_port=12345<br \/>&#8211; <code>sudo ufw allow $desired_ssh_port\/tcp<\/code><code><\/code><br \/>&#8211; <code>cp \/etc\/ssh\/sshd_config \/etc\/ssh\/sshd_config_backup<\/code><br \/>&#8211; <code>sed -i \"s\/#Port 22\/Port $desired_ssh_port\/\" \/etc\/ssh\/sshd_config<\/code><span style=\"color: #000000; font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif; font-size: medium;\"><span style=\"background-color: #ffffff;\"><br \/><\/span><\/span>&#8211; <code>sudo systemctl disable ssh.socket &amp;&amp; sudo systemctl stop ssh.socket &amp;&amp; sudo systemctl restart ssh &amp;&amp; sudo systemctl enable ssh.socket<\/code><br \/>&#8211; <code>sudo ufw reload<\/code>\u00a0\u00a0<br \/>( in rare cases, you might also need to amend: <code>\/etc\/apache\/sites-enabled &amp;&amp; \/etc\/apache2\/ports.conf<\/code> )<code><\/code><\/li>\n<li><strong>Docker<\/strong><em>: <br \/><\/em>&#8211; <a href=\"https:\/\/docs.vultr.com\/how-to-install-docker-on-ubuntu-24-04\">install docker<\/a><em> or <a href=\"https:\/\/www.cherryservers.com\/blog\/install-docker-ubuntu\">here<\/a> (only if you know docker and want to use it)<\/em><\/li>\n<li><strong>NodeJS<\/strong>:\n<pre>wget -q -O- https:\/\/raw.githubusercontent.com\/nvm-sh\/nvm\/master\/install.sh | bash<br \/>. ~\/.bashrc<br \/>nvm install node<\/pre>\n<\/li>\n<li>\n<div>\n<div>PM2: <code>npm install pm2 -g &amp;&amp; pm2 update<\/code><code><\/code><\/div>\n<\/div>\n<\/li>\n<li><strong>Misc<\/strong>:<br \/>&#8211; set start dir: <code>echo \"cd \/var\/www\/mydir\/\" &gt;&gt; ~\/.bashrc<em><br \/><\/em><\/code><em>&#8211; aliases: <\/em><code><em>echo \"alias dcd='docker compose down'\" &gt;&gt; ~\/.bash_aliases &amp;&amp; echo \"alias dcu='docker compose up'\" &gt;&gt; ~\/.bash_aliases &amp;&amp; source ~\/.bashrc<\/em><\/code><\/li>\n<li><strong>Firewall<\/strong>:<br \/>&#8211; <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04\">firewall-on-ubuntu<\/a><br \/>&#8211;<a href=\"https:\/\/github.com\/jrleszcz\/linux-server-setup\/blob\/master\/how-to\/configure-firewall-and-change-ssh-port.md\"> configure-firewall-and-change-ssh-port.md<\/a><br \/>&#8211; <a href=\"https:\/\/puvox.software\/blog\/using-firewalld-instead-of-ufw-for-docker\/\"><strong>firewalld<\/strong> instead of <strong>ufw<\/strong><\/a> (when you use docker!)<\/li>\n<li><strong>Simple Disk usage<\/strong>: <br \/>&#8211; <code>sudo apt install ncdu<\/code> and anytime just run <code>ncdu<\/code><\/li>\n<li><a href=\"https:\/\/puvox.software\/blog\/setup-correct-permissions-on-vps-ubuntu-linux-etc-for-multiple-users\/\">Set correct permissions for multiple users<\/a><br \/>&#8211; to rewrite privileges after uploading files automatically:\u00a0 <br \/><code>*\/10 * * * * sudo chown -R www-data:www-data \/var\/www<\/code><\/li>\n<li><strong>Increase timeout for SSH client<\/strong> (instead of default 10):<br \/>&#8211; <code>nano \/etc\/ssh\/sshd_config<\/code> &#8211;&gt;set\u00a0 <code>ClientAliveInterval 60<\/code>\u00a0 \u00a0and <code>ClientAliveCountMax 5<\/code><\/li>\n<li><code><\/code>Find file: <code>find . -type f -name \"*John*\"<\/code><code><\/code><\/li>\n<li><a href=\"https:\/\/puvox.software\/blog\/add-user-ssh-key-in-linux-ubuntu\/\">Add user through SSh<\/a><\/li>\n<li>Auto- Restart stopped-service : <a href=\"https:\/\/github.com\/sierracircle\/services-checker\">Github repo<\/a>\u00a0<\/li>\n<li>Restrict port to specific IP: <br \/><code>sudo iptables -A INPUT -p tcp -s YOURRRRRRR_IPPPPPPPPPPP -j ACCEPT<\/code><br \/><code>sudo ufw allow from 123.123.123.123 to any port 22 proto tcp<\/code><\/li>\n<li>Monitor files\/folders changes :\u00a0<br \/><code>inotify-hookable -w path_to_plugin -c \"COMMAND_TO_EXECUTE\" (i.e. \"docker container restart CONTAINER_NAME\")\u00a0<\/code><\/li>\n<li><code><\/code><code><\/code>Download &amp; unpack file:\u00a0<br \/><code>wget  --no-check-certificate --content-disposition https:\/\/codeload.github.com\/USER\/REPONAME\/zip\/refs\/heads\/master -O temp.zip<\/code><code> &amp;&amp; unzip -o temp.zip -d \/var\/www\/path\/folder<\/code><\/li>\n<\/ul>\n<p>\u00a0<\/p>\n<ul>\n<li>For LAMP, see <a href=\"https:\/\/puvox.software\/blog\/configure-lamp-on-vps\/\">this article<\/a>\u00a0\n<pre>\u00a0<\/pre>\n<\/li>\n<\/ul>\n\n\n<\/div>","protected":false},"excerpt":{"rendered":"<div class=\"default-content-clss excerpt_4579 type_post \"><p>Essentials: setup new user &amp; ufw Install LetsEncrypt Free SSL: \u00a0LE on ubuntu 24\u00a0&#8211; for apache &#8211; for-nginx\u00a0 &#8211; (if different ports needed: here\u00a0or here) Fail2ban:\u00a0sudo apt-get install fail2ban Disable<a class=\"excerpt-read-more\" href=\"https:\/\/puvox.software\/blog\/configure-lamp-on-vps-with-details\/\">(Continue Reading)<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":4580,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[17,13],"tags":[],"class_list":["post-4579","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-website"],"_links":{"self":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/4579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/comments?post=4579"}],"version-history":[{"count":23,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/4579\/revisions"}],"predecessor-version":[{"id":5802,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/posts\/4579\/revisions\/5802"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/media\/4580"}],"wp:attachment":[{"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/media?parent=4579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/categories?post=4579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/puvox.software\/blog\/wp-json\/wp\/v2\/tags?post=4579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}