Hosting & Ubuntu

I have written some guides & tips related to Hosting & Ubuntu server.

1). Redirect all old URLs to new URLs with specific URLs

This is a guide for redirect by htaccess.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^oldwebsite.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.oldwebsite.com [NC]
    RewriteRule ^(.*)$ http://newwebsite.com/$1 [L,R=301,NC]


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ https://newsite.com/ [L,R=301,NC]
</IfModule>

2). Change PHP.ini

PHP5 Path

$ /etc/php5/apache2/php.ini

PHP7 Path

$ /etc/php/7.0/apache2/php.ini

Restart Apache 2

# /etc/init.d/apache2 restart
$ sudo /etc/init.d/apache2 restart
$ sudo /etc/init.d/apache2 restart
# /etc/init.d/apache2 stop
$ sudo /etc/init.d/apache2 stop
$ sudo service apache2 stop
# /etc/init.d/apache2 start
$ sudo /etc/init.d/apache2 start
$ sudo service apache2 start

3). Force or redirect to SSL in nginx

return 301 https://$server_name$request_uri;

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    error_log  /var/log/apache2/domains/example.com.error.log error;

    location / {
        proxy_pass      http://45.76.61.243:8080;
        return 301 https://$server_name$request_uri;
        ...
        ...
    }
}

3). Upload file vai SSH in Ubuntu server

scp <file> <username>@<IP address or hostname>:<Destination>

For example: my file "example.zip"

scp example.zip admin@124.76.61.243:/home/admin/web/example.com/public_html/