How to install ASP.NET with Mysql in Linux server (cPanel)

July 2, 2009 on 8:57 am | In ASP.NET, Apache, Cpanel | 2 Comments

You should enable mod_mono in easyapache to enable ASP.NET. However, for using Mysql database with ASP.NET, you need to download and install a connector from Mysql site.
The one you need is Windows Binaries, no installer (ZIP).

Installation

cd /usr/local/src/
mkdir asp-connector
cd asp-connector
wget Windows Binaries, no installer (ZIP)
/opt/mono/bin/gacutil -i  /usr/local/src/asp-connector/bin/MySql.Data.dll

Most of you forget the next step and the Mysql connector won’t work.

cd /opt/mono/lib/mono/gac/MySql.Data
cd 5.2.3.0__xxxxxxxxxx/
chmod 755 MySql.Data.dll

Restart Apache

/etc/rc.d/init.d/httpd restart

Now you should be able to connect to mysql using .aspx scripts

Here is a custom script to check the working.
First Create a mysql database first (using command line)

$ mysql -u root -p

mysql> CREATE DATABASE asptest;
Query OK, 1 row affected (0.10 sec)

mysql> USE asptest;
Database changed

mysql> CREATE TABLE testtable ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) );
Query OK, 0 rows affected (0.09 sec)

mysql> INSERT INTO testtable VALUES(null,'Fame');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO testtable VALUES(null,'Clean');
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM testtable;
+----+----------+
| id | name |
+----+----------+
| 1 | Fame |
| 2 | Clean |
+----+----------+
2 rows in set (0.00 sec)

mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON asptest.* TO asptest@localhost IDENTIFIED BY 'nogesspassword';
Query OK, 0 rows affected (0.12 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.13 sec)

Lets go to the script
Here is it. It will display the contents of the database.

First, create a file called test.aspx in your web directory
Add this code and save it.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="MySql.Data.MySqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>ASP test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <script runat="server">
    private void Page_Load(Object sender, EventArgs e)
    {
       string connectionString = "Server=localhost;Database=asptest;User ID=asptest;Password=nogesspassword;Pooling=false;";
       MySqlConnection dbcon = new MySqlConnection(connectionString);
       dbcon.Open();

       MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM testtable", dbcon);
       DataSet ds = new DataSet();
       adapter.Fill(ds, "result");

       dbcon.Close();
       dbcon = null;

       ArtistsControl.DataSource = ds.Tables["result"];
       ArtistsControl.DataBind();
    }
    </script>

  </head>

  <body>
    <h1>Artists</h1>
    <asp:DataGrid runat="server" id="ArtistsControl" />
  </body>

</html>

Finally, you need a web.config file, in the same web directory where test.aspx . It should contain the following to enable the MySQL libraries to be loaded:

Add the following to web.config

<configuration>
<system.web>
<compilation>
<assemblies>
<add assembly="MySql.Data"/>
</assemblies>
</compilation>
<customErrors mode="Off"/>
</system.web>
</configuration>

Now try accessing the file test.aspx using http://domainname.com/test.aspx

If you need any help, please let me know.

Install PHP-MemCache Module On CentOS 5.0 + RHEL

January 17, 2009 on 3:27 pm | In Apache, Installation, PHP | No Comments

Download

wget http://pecl.php.net/get/memcache-2.1.2.tgz
tar -zxf memcache-2.1.2.tgz
cd memcache-2.1.2

phpize &&
./configure –enable-memcache
make
make install

This should create memcache.so in your extenstion directory (/usr/lib/php/modules)

If it is not done copy the file memcache.so to the default module directory.
locate your php.ini file

php -i| grep php.ini

add the line

———————
extension=memcache.so
———————

Restart Apache

/etc/rc.d/init.d/httpd restart

check the module is working
php -i| grep memcache.

should show something like

=============
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user memcache
OLDPWD => /usr/local/src/ezsmsupport/memcache-2.1.2
=============

Also, you can find it in your phpinfo page.
Thats all.

/usr/java/jdkX.X.X_Xbin/java: not found + Install Java on Linux servers

October 19, 2008 on 8:20 pm | In Apache, Centos, Cpanel, Installation, Linux | No Comments

In some cases, the 3rd parts scripts in server requires java to be installed. It may not work properly if the binary of java installed in the server. You need to install JavaSDK

So we present here the installation of Java in Linux server.

Its as easy as you run upcp in a Cpanel server.

Download the installation binary from Sun’s Java site

J2SE for Linux http://java.sun.com/j2se/1.4.2/download.html.( Download J2SE SDK)

You may need to register at the site and then they will send you the download link. Download the non-rpm binary

cd /usr/local/src/

wget thebinary

mv j2sdk-1_4_2_18-linux-i586.bin /usr/local/

cd /usr/local/

chmod 755 j2sdk-1_4_2_18-linux-i586.bin

./j2sdk-1_4_2_18-linux-i586.bin

Now setup the environment variables.

JAVA_HOME=/usr/local/j2sdk1.4.2_18

export JAVA_HOME

Also, you need to add these in the file /etc/profile.

JAVA_HOME=/usr/local/j2sdk1.4.2_18

export JAVA_HOME

XCache Installation Linux Cpanel

April 24, 2008 on 9:07 am | In Apache, Cpanel, Installation, PHP | No Comments

1) Download

==============================
wget http://xcache.lighttpd.net/pub/Releases/1.2.1/xcache-1.2.1.tar.gz
phpize
./configure –enable-xcache
make
make install
==============================

Find the php.ini file.

php -i| grep php.ini

Edit the php.ini file

Add the line below.
==============================
Find other zend_extension lines. Add the line below.

zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20020429/xcache.so
==============================

Note the line proper path “/usr/local/lib/php/extensions/no-debug-non-zts-20020429/ ” is received at the end of make install. Replace with that path.

Go for Apache restart

Check your PHP info page

How to prevent DDos attacks

April 22, 2008 on 2:48 pm | In Apache, Cpanel, DDos | No Comments

Hello everyone…
Here I present some steps to prevent DDos attacks.

>>>>>>>>>Install/Configure APF firewall
>>>>>>>>>Install/Configure mod_evasive
>>>>>>>>>Install mod_security
>>>>>>>>>Blocking IPs maintaining more connections
>>>>>>>>>Optimizing the httpd.conf file

Install/Configure APF firewall

===========================
cd /usr/local/src/
wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz
tar -zxvf apf-current.tar.gz; cd apf-*

Step 2: Installation
Code:

sh ./install.sh
===========================

Install/Configure mod_evasive

===========================
Download the source

======================
wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
tar -xzvf mod_evasive_1.10.1.tar.gz
cd mod_evasive
======================

Compile in the mod_evasive apache module using apxs

======================
For Apache 2
/usr/local/apache/bin/apxs -i -a -c mod_evasive20.c

For Apache 1.3
/usr/local/apache/bin/apxs -i -a -c mod_evasive.c
======================

If the apxs path is not /usr/local/apache/bin/apxs replace it with the appropriate path

Edit your httpd.conf /usr/local/apache/conf/httpd.conf

Add the lines below.

======================
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSEmailNotify user@yourdomain.com
======================

/etc/init.d/httpd restart

You can try another values for the above and obtain the best setting.
In some cases mod_evasive also blocks legitimate user IPs.
===========================

Install mod_security

Install this module via WHM

WHM >> cPanel >> Addon Modules >> Select “modsecurity ” >>save

Blocking IPs maintaining more connections

===========================
You can check out the number of http requests coming to your server and the
ip’s from where it is coming by executing the command :

============================================
netstat -plan | grep :80 | awk ‘{print $5}’ | cut -d: -f 1 | sort | uniq -c | sort -n
============================================

If you feel like there are inordinate amount of requests from a single ip, you
can block it in your APF using this command :

=====
apf -d IP
=====

Using iptables, you can block the ip with :
====================
iptables -A INPUT -s -j DROP
====================

You can check out the ip to which maximum number of http requests are coming
with the following command :

==================
[root@server ~]# netstat -plan|grep :80|awk {‘print $4′}|cut -d: -f 1|sort|uniq -c|sort -n
==================
===========================

Optimizing the httpd.conf file

vi /usr/local/apache/conf/httpd.conf

Change the values as follows.

MaxKeepAliveRequests 50
KeepAliveTimeout 60

Also edit the following options.

Timeout
KeepAliv
MinSpareServers
MaxSpareServers
MaxClients

Reduce the timeout, Maxclients etc.

How to Install mod_evasive

April 22, 2008 on 2:35 pm | In Apache, DDos, Installation | No Comments

Download the source

======================
wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
tar -xzvf mod_evasive_1.10.1.tar.gz
cd mod_evasive
======================

Compile in the mod_evasive apache module using apxs

======================
For Apache 2
/usr/local/apache/bin/apxs -i -a -c mod_evasive20.c

For Apache 1.3
/usr/local/apache/bin/apxs -i -a -c mod_evasive.c
======================

If the apxs path is not /usr/local/apache/bin/apxs replace it with the appropriate path

Edit your httpd.conf /usr/local/apache/conf/httpd.conf

Add the lines below.

======================
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSEmailNotify user@yourdomain.com
======================

/etc/init.d/httpd restart

You can try another values for the above and obtain the best setting.
In some cases mod_evasive also blocks legitimate user IPs.

Install and enjoy….

Apache failed to start “Document config file error” Plesk server

April 19, 2008 on 3:51 pm | In Apache, Plesk | No Comments

When starting Apache the error is reported.

[~]/etc/init.d/httpd start
Starting httpd: httpd: could not open document config file /var/www/vhosts/domain.com/conf/httpd.include
[FAILED]

It is due to “httpd.include” file not found for the domain

To regenerate the “httpd.include” file using the command given below.

/usr/local/psa/admin/sbin/websrvmng –reconfigure-vhost –vhost-name=domain.com

Now you can start the Apache without any problem.

PHP mail error. Not able to send mail using script – Cpanel server.

April 15, 2008 on 4:44 pm | In Apache, Cpanel, PHP | No Comments

Follow the steps below to sort out the problem.

Check whether mail server is able to send mail.

Next is to
Check in WHM tweak setting whether nobody is allowed to send mail.

================
WHM > Tweak settings > Mail > Prevent “nobody” from sending out this mail.
disable it.
================

If it is disabled. Next is to repair Exim.

Backup the /etc/exim.conf and then repair exim

================
/scripts/eximup –force
================

Most probably the issue should be fixed by now.
If not, the next step of troubleshooting is

Check the php.ini file.

locate your php.ini file.

================
php -i | grep php.ini
================

you will get the location from above command.
Open the file and find the directive “disable_functions=”

Check whether mail() is included. if there, remove it and save. Then go for an Apache restart

However, if all the above are OK and still not working.

Check whether mod_security is installed.
If installed, disable it and then check.

All the above are OK.
Recompile PHP + Apache

If that too doesn’t work…………………….
Upgrade PHP and then downgrade it.

It should be fixed now.
Other wise you have to go for Cpanel support.