Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
reanim8ed / sample.md
Last active August 24, 2021 14:57
[Create a read-only user in PostgreSQL] #postgres

Connect to psql:

  su - postgres database_name
  psql
  1. To create a new user in PostgreSQL:

CREATE USER username WITH PASSWORD 'your_password';

@reanim8ed
reanim8ed / sample.md
Created April 6, 2021 18:19
[Messenger supervisor config] #symfony

sudo apt-get install supervisor

Supervisor configuration files typically live in a /etc/supervisor/conf.d directory. For example, you can create a new messenger-worker.conf file there to make sure that 2 instances of messenger:consume are running at all times:

;/etc/supervisor/conf.d/messenger-worker.conf
[program:messenger-consume]
command=php /path/to/your/app/bin/console messenger:consume async --time-limit=3600
user=ubuntu
numprocs=2
startsecs=0
@reanim8ed
reanim8ed / sample.md
Created January 8, 2021 14:02
[Copy directory via ssh to PC] #linux #ssh
  • If you want to copy a directory from machine a to b while logged into a: scp -r /path/to/directory user@ipaddress:/path/to/destination

  • If you want to copy a directory from machine a to b while logged into b: scp -r user@ipaddress:/path/to/directory /path/to/destination

@reanim8ed
reanim8ed / sample.md
Last active January 4, 2021 21:04
[Enable SFTP Without Shell Access on CentOS 7] #centos #sftp #webserver

https://devanswers.co/configure-sftp-web-server-document-root/

SFTP stands for SSH File Transfer Protocol. As its name suggests, it’s a secure way of transferring files to a server using an encrypted SSH connection. Despite the name, it’s a completely different protocol than FTP (File Transfer Protocol), though it’s widely supported by modern FTP clients. SFTP is available by default with no additional configuration on all servers that have SSH access enabled. It’s secure and easy to use, but comes with a disadvantage: in a standard configuration, the SSH server grants file transfer access and terminal shell access to all users with an account on the system. In some cases, you might want only certain users to be allowed file transfers and no SSH access. In this tutorial, we’ll set up the SSH daemon to limit SFTP access to one directory with no SSH access allowed on per user basis.

Create a New User

  • First, create a new user who will be granted only file transfer access to the server. Here, we’re using t
@reanim8ed
reanim8ed / sample.md
Last active January 8, 2021 14:03
[Initial Server Setup with CentOS 7] #centos #webserver #ssh

When you first create a new server, there are a few configuration steps that you should take early on as part of the basic setup. This will increase the security and usability of your server and will give you a solid foundation for subsequent actions.

Create a New User

  • Once you are logged in as root, we’re prepared to add the new user account that we will use to log in from now on.
  • This example creates a new user called “demo”, but you should replace it with a user name that you like: adduser demo
  • Next, assign a password to the new user (again, substitute “demo” with the user that you just created): passwd demo

Root Privileges

Now, we have a new user account with regular account privileges. However, we may sometimes need to do administrative tasks. To avoid having to log out of our normal user and log back in as the root account, we can set up what is known as “super user” or root privileges for our normal account. This will allow our normal user to run commands with administrative privilege

@reanim8ed
reanim8ed / sample.md
Last active January 4, 2021 20:30
[Postgres on CentOS 7/8] #centos #linux #webserver #postgres

Always update

  • yum update

Add PostgreSQL Yum Repository

The PostgreSQL Yum Repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

CentOS 8:

sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
@reanim8ed
reanim8ed / sample.md
Created December 14, 2020 21:49
[Serve frontend and backend on same domain with nginx] #nginx
# Nginx configuration
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name ${NGINX_HOST};

    root /var/www/html/backend/public;

 access_log /var/log/nginx/access_log.log;
@reanim8ed
reanim8ed / sample.md
Last active December 14, 2020 22:14
[LEMP on CentOS] #linux #server #nginx #centos

NGINX

  • To add the CentOS 7 EPEL repository, run the following command: sudo yum install epel-release
  • Install Nginx using the following yum command: sudo yum install nginx
  • Start the Nginx service with: sudo systemctl start nginx
  • You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address. You will see the default CentOS Nginx web page
  • To enable Nginx to start on boot, run the following command: sudo systemctl enable nginx
  • Installing Nginx into Cent OS doesn’t create the /etc/nginx/sites-available and /etc/nginx/sites-enabled directories. If you want to use the directory rather than cond.d, you have to make them manually. Typically, the sites-enabled folder is used for virtual host definitions, while conf.d is used for global server configuration. Also, don’t forget to include the “enabled” directry to the root configuration. In other words, you’ll need the following line in the “http” block in “/etc/nginx/nginx.conf”: `in
@reanim8ed
reanim8ed / sample.md
Created November 27, 2020 08:18
[reCAPTCHA v3 validation] #php #recaptcha #validation #curl

Header:

  • Insert token to all .recaptcha_response elements on page ant refresh them every 2min
<script src="https://www.google.com/recaptcha/api.js?render=YOUR_RECAPTCHA_SITE_KEY"></script>
<script>
$(document).ready(function () {
    var elements = document.getElementsByClassName('recaptcha_response');
    if (elements) {
        grecaptcha.ready(function () {
            grecaptcha_execute(elements);
@reanim8ed
reanim8ed / sample.md
Last active November 19, 2020 20:54
[Vesta nginx template location] #nginx #vesta

/usr/local/vesta/data/templates/web/