Friday, August 24, 2018

point subdomain to a directory on the same server

I want to point a subdomain to a directory on my vps Apache/2.4.10 (Debian). I created a subdomain, added A record and ip of my server. Right now when I open it in a browser this subdomain points to main domain.

Main domain is at /var/www/wordpress. Subdomain needs to be at /var/www/subdomain.example.com.

So at /etc/apache2/sites-available I created subdomain.example.com.conf



    ServerAdmin webmaster@localhost
    ServerName subdomain.example.com
    DocumentRoot /var/www/subdomain.example.com

    
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


Then I did a2ensite subdomain.example.com.conf and service apache2 reload. After that both main domain and subdomain return HTTP ERROR 500. I'm lost.

apache2ctl -S before a2ensite subdomain.example.com.conf

[Sat Feb 18 13:15:55.649294 2017] [alias:warn] [pid 4524] AH00671: The Alias directive in /etc/phpmyadmin/apache.conf at line 3 will     probably never match because it overlaps an earlier Alias.
VirtualHost configuration:
*:443                  examplevps.com (/etc/apache2/sites-enabled/default-ssl.conf:2)
*:80                   examplevps.com  (/etc/apache2/sites-enabled/wordpress.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

apache2ctl -S after a2ensite subdomain.example.com.conf

[Sat Feb 18 13:39:42.263129 2017] [alias:warn] [pid 4917] AH00671: The Alias dir                                                                   ective in /etc/phpmyadmin/apache.conf at line 3 will probably never match becaus                                                                   e it overlaps an earlier Alias.
VirtualHost configuration:
*:443                  examplevps.com (/etc/apache2/sites-enabled/default-ssl                                                                   .conf:2)
*:80                   is a NameVirtualHost
         default server subdomain.example.com (/etc/apache2/sites-enabled/subdomain.example.com.conf:1)
         port 80 namevhost subdomain.example.com (/etc/apache2/sites-enabled/                                                                   subdomain.example.com.conf:1)
                 alias subdomain.example.com
         port 80 namevhost examplevps.com (/etc/apache2/sites-enabled/wordpress.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

Solved

Looks like you are missing quotes. Try this:


    ServerName subdomain.example.com
    ServerAlias subdomain.example.com

    # DocumentRoot 
    DocumentRoot "/var/www/subdomain.example.com"

    
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    

    # Logging
    ErrorLog "${APACHE_LOG_DIR}/error.log"
    CustomLog "${APACHE_LOG_DIR}/access.log" combined


Monday, August 20, 2018

How to export data from Cassandra to mongodb?

I am using Apache (Kafka-Storm-Cassandra) for real time processing.The problem I am facing is that I can't use aggregation queries on Cassandra directly(Datastax can be used but it is a paid service).Moreover, I also considered using mongodb but It is not good for more and frequent writes. So, I am thinking to do all my calculation in storm and store it into Cassandra and move it on hourly basis or so to mongodb to perform my further analytics.

Is this the right approach or are there any better options to achieve this ?

Also, How can I export data directly from Cassandra to mongodb prefebly using JAVA?

Thanks In Advance !!

Solved

Without knowing your full requirement, amount of inserts/updates one cannot predict is it a good or bad approach. Mongo is less preferable for heavy writes but it can support quite a good no. of inserts. So important thing is how many writes you have per unit time and based on that you can take the decision.

I have seen Mongo taking upto 1000-2000 writes per sec with avg of 4-5ms on server class machines. Of course Cassandra beats it by margin but if you need to perform any aggregation then Mongo has better framework and capabilities.

For export and import, flat csv can be used. Cassandra can export data to csv and MongoDB can import data from csv with export/import options.

Check MongoImport and for exporting from cassandra, example could be,

copy employee (emp_id, dept, designation, emp_name, salary)
 to 'employee.csv';

Sunday, August 19, 2018

How to send HTML-formatted email? [duplicate]

This question already has an answer here:

I could be able to let the web application sends automatic emails using Windows Task Scheduler. Now I want to send HTML-Formatted email using the following method that I wrote for sending emails.

My code-behind:

protected void Page_Load(object sender, EventArgs e)
    {
        SmtpClient sc = new SmtpClient("mail address");
        MailMessage msg = null;

        try
        {
            msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "This email sent by the PSSP system");

             sc.Send(msg);
        }

        catch (Exception ex)
        {
            throw ex;
        }

        finally
        {
            if (msg != null)
            {
                msg.Dispose();
            }
        }
    }

How to do that? I just want to put some bold text with one link and maybe one image in the email.

Solved

Setting isBodyHtml to true allows you to use HTML tags in the message body:

msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "This email sent by the PSSP system
" + "this is bold text!"); msg.IsBodyHtml = true;

Best way to send html formatted Email

This code will be in "Customer.htm"

    
Dealer's Company Name : #DealerCompanyName#

Read HTML file Using System.IO.File.ReadAllText. get all HTML code in string variable.

string Body = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("EmailTemplates/Customer.htm"));

Replace Particular string to your custom value.

Body = Body.Replace("#DealerCompanyName#", _lstGetDealerRoleAndContactInfoByCompanyIDResult[0].CompanyName);

call SendEmail(string Body) Function and do procedure to send email.

 public static void SendEmail(string Body)
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(Session["Email"].Tostring());
            message.To.Add(ConfigurationSettings.AppSettings["RequesEmail"].ToString());
            message.Subject = "Request from " + SessionFactory.CurrentCompany.CompanyName + " to add a new supplier";
            message.IsBodyHtml = true;
            message.Body = Body;

            SmtpClient smtpClient = new SmtpClient();
            smtpClient.UseDefaultCredentials = true;

            smtpClient.Host = ConfigurationSettings.AppSettings["SMTP"].ToString();
            smtpClient.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["PORT"].ToString());
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new System.Net.NetworkCredential(ConfigurationSettings.AppSettings["USERNAME"].ToString(), ConfigurationSettings.AppSettings["PASSWORD"].ToString());
            smtpClient.Send(message);
        }

This works for me

msg.BodyFormat = MailFormat.Html;

and then you can use html in your body

msg.Body = "It's great to use HTML in mail!!"

Saturday, August 18, 2018

MATLAB Warning while saving an object

While saving a Matlab object (which is not a handle or a subclass of Copyable), I get the following warning:

Warning: While saving an object of class 'PGP': Undefined function 'copy' for input arguments of type 'PGP'.

What does this warning mean?

I am using MATLAB2017b.