Linux Web Hosting, DevOps, and Cloud Solutions

Empowering you with the knowledge to master Linux web hosting, DevOps and Cloud

 Linux Web Hosting, DevOps, and Cloud Solutions

Custom php.ini per domain in Plesk Windows server

There will always be the scenarios where we need to set some special php settings for a particular domain or for a particular directory. This can be easily done in a Linux server, but with Windows it is always issues. But we can done this windows servers also and tell you what i have verified this by myself.

Prerequisites:-

*Custom php,ini file only works with php handler as “cgi” and not with “fastcgi” nor with ISAPI extension. So you need to verify this before you proceed further.

Follow the below steps to set the correct php mode.

1. Log in to your Hosting Control Panel
2. Select your domain name
3. Under “Web Site” tab, click on “Web Hosting Settings”
4. Under “PHP Support”, select your desired “PHP Mode” settings(cgi mode)
5. Hit the “Ok” button to activate.

Assumptions:-

  • The default location of php.ini for PHP5 is the PleskPHP5 base directory %plesk_dir%AdditionalPleskPHP5 (Eg: c:Program FilesParallelsPleskAdditionalPleskPHP5). If you place an PHP info page, you can easily find out from where the current php settings is loaded.
  • The document root of the domain “maindomain.com” is “d:Inetpubvhostsmaindomain.comhttpdocs”. Please note that this may be different in your hosting environment.
  • The server I am working on is a x86 based server.
  • Plesk version is 10.3.1, but it should work with others also.

Turn off the register_globals

I will explain the procedures with an example to turn off the register globals . There are two ways to configure php values for a particular domain:-

1. By placing an customized php.ini page on the corresponding directory or in domain.
2. By creating a Windows registry value for the particular php settings.
Placing an customized php.ini page on the corresponding directory
You need to place the php.ini file in “maindomain.com/httpdocs” directory or if you want to apply the only to a addon domain or a directory, then use the directory “maindomain.com/httpdocs/addondomain.com”.

Follow the below steps:-

1. Copy the PHP version 5 (php.ini-recommended or php.ini) ini file from the PHP location %plesk_dir%\AdditionalPleskPHP5 to the location “maindomain.com/httpdocs”
2. Rename the copied file to the exact name as ‘php-cgi-fcgi.ini‘. This is the most important step and won’t work otherwise.
3. You can make the changes needed to the above ini file, say set the “register_globals = Off”.
3. Create a php info page the corresponding directory and verify it is loading the correct “php.ini” (check the loaded configuration file section). Also verify whether the value you have changed is now updated under the ‘PHP info’ page.

This should do the work. If this method doesn’t work for you, here is the second method.

Creating a Windows registry value

Even though this is a simple procedure, i do not recommend anyone to edit the Windows Registry because if you screw up anything with Registry, you will also screwed up 🙂

When running PHP on Windows, the configuration values can be modified on a per-directory basis using the Windows registry. The configuration values are stored in the registry key HKLMSOFTWAREPHP5Per Directory Values, in the sub-keys corresponding to the path names. For example, configuration values for the directory c:inetpubwwwroot would be stored in the key HKLMSOFTWAREPHP5Per Directory Valuescinetpubwwwroot. The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values under the key should have the name of the PHP configuration directive and the string value.

Simply, you can only add individual php configuration value inside of php.ini through the registry, which means that you have to set up keys to the file path ( where the client’s hosting folder located ) and then add a string value, string name will be the php.ini configuration name and value will be how you want it to be. So for setting register_globals to off for the maindomain.com, you have to setup keys to the path “HKEY_LOCAL_MACHINE > SOFTWARE > Wow6432Node > PHP > Per Directory Values > C > Inetpub > vhosts > maindomain.com > httpdocs” and then add a string value, string name will be “register_globals” and value will be 0 to put register_globals= off.
Note:

For 32 bit Windows registry path is ,  HKLMSOFTWAREPHP5Per Directory Values
For x64 based Windows registry path is,  HKEY_LOCAL_MACHINESOFTWAREWow6432NodePHP5Per Directory Values

Reference:-

http://forum.parallels.com

http://www.php.net

IPTABLES complete cheatlist

Please note that the iptables rules are stored in the /etc/sysconfig/iptables file. If you view this file, you’ll see all the default rules.

1. Delete Existing Rules

Before you start building new set of rules, you might want to clean-up all the default rules, and existing rules. Use the iptables flush command as shown below to do this.

iptables -F
(or)
iptables –flush
service iptables save

2. Set Default Chain Policies

The default chain policy is ACCEPT. Change this to DROP for all INPUT, FORWARD, and OUTPUT chains as shown below.

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

When you make both INPUT, and OUTPUT chain’s default policy as DROP, for every firewall rule requirement you have, you should define two rules. i.e one for incoming andone for outgoing.
Change default policy for INPUT/OUTPUT/FORWARD to ACCEPT. All inbound connections will be allowed

iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

3.Block an IP for inbound connection

iptables -A INPUT -s 192.168.1.5 -j DROP
iptables -A INPUT -i eth0 -p tcp -s “$BLOCK_THIS_IP” -j DROP
4.Allow an IP for inbound connection

iptables -A INPUT -s 192.168.1.5 -j ACCEPT

5.Block outbound IP address

iptables -A OUTPUT -d <IP> -j DROP

6.Block outbound PORT

iptables -A OUTPUT -p tcp –dport <PORT> -j DROP

7.Block outbound IP:PORT

iptables -A OUTPUT -p tcp -d <IP> –dport <PORT> -j DROP

8.Allow port 2222 for inbound tcp connections

iptables -A INPUT -p tcp –dport 2222 -j ACCEPT

9.White list an IP

iptables -A INPUT -i eth0 -s <IP> -j ACCEPT

10.Open port 5666

iptables -I INPUT -p tcp -m tcp –dport 5666 -j ACCEPT
11.Allow ALL Incoming SSH

The following rules allow ALL incoming ssh connections on eth0 interface.

iptables -A INPUT -i eth0 -p tcp –dport 22 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp –sport 22 -m state –state ESTABLISHED -j ACCEPT

12.Allow Incoming SSH only from a Sepcific Network

The following rules allow incoming ssh connections only from 192.168.100.X network.

iptables -A INPUT -i eth0 -p tcp -s 192.168.100.0/24 –dport 22 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp –sport 22 -m state –state ESTABLISHED -j ACCEPT

In the above example, instead of /24, you can also use the full subnet mask. i.e “192.168.100.0/255.255.255.0″.

13. Allow Incoming HTTP and HTTPS

The following rules allow all incoming web traffic. i.e HTTP traffic to port 80.

iptables -A INPUT -i eth0 -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp –sport 80 -m state –state ESTABLISHED -j ACCEPT

The following rules allow all incoming secure web traffic. i.e HTTPS traffic to port 443.

iptables -A INPUT -i eth0 -p tcp –dport 443 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp –sport 443 -m state –state ESTABLISHED -j ACCEPT

14.Combine Multiple Rules Together using MultiPorts

When you are allowing incoming connections from outside world to multiple ports, instead of writing individual rules for each and every port, you can combine them together using the multiport extension as shown below.

The following example allows all incoming SSH, HTTP and HTTPS traffic.

iptables -A INPUT -i eth0 -p tcp -m multiport –dports 22,80,443 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport –sports 22,80,443 -m state –state ESTABLISHED -j ACCEPT

15.Allow Outgoing SSH

The following rules allow outgoing ssh connection. i.e When you ssh from inside to an outside server.

iptables -A OUTPUT -o eth0 -p tcp –dport 22 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp –sport 22 -m state –state ESTABLISHED -j ACCEPT

Please note that this is slightly different than the incoming rule. i.e We allow both the NEW and ESTABLISHED state on the OUTPUT chain, and only ESTABLISHED state on  the INPUT chain. For the incoming rule, it is vice versa.

16.Allow Outgoing SSH only to a Specific Network

The following rules allow outgoing ssh connection only to a specific network. i.e You an ssh only to 192.168.100.0/24 network from the inside.

iptables -A OUTPUT -o eth0 -p tcp -d 192.168.100.0/24 –dport 22 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -i eth0 -p tcp –sport 22 -m state –state ESTABLISHED -j ACCEPT

17.Allow Ping from Outside to Inside

The following rules allow outside users to be able to ping your servers.
iptables -A OUTPUT -p icmp –icmp-type echo-request -j ACCEPT
iptables -A INPUT -p icmp –icmp-type echo-reply -j ACCEPT
19.Allow Loopback Access

You should allow full loopback access on your servers. i.e access using 127.0.0.1

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

20. Allow MySQL connection only from a specific network

iptables -A INPUT -i eth0 -p tcp -s 192.168.100.0/24 –dport 3306 -m state –state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp –sport 3306 -m state –state ESTABLISHED -j ACCEPT

21.Prevent DoS Attack

The following iptables rule will help you prevent the Denial of Service (DoS) attack on your webserver.

iptables -A INPUT -p tcp –dport 80 -m limit –limit 25/minute –limit-burst 1000 -j ACCEPT
In the above example:
-m limit: This uses the limit iptables extension

–limit 25/minute: This limits only maximum of 25 connection per minute. Change this value based on your specific requirement
–limit-burst 1000: This value indicates that the limit/minute will be enforced only after the total number of connection have reached the limit-burst level.

22.Port forwarding using IPTables

Forward port 80 from IP address to another IP

iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 80 -j DNAT –to <DESTIP>:80
iptables -t nat -A POSTROUTING -p tcp –dst <DESTIP> –dport 80 -j SNAT –to <SRCIP>
iptables -t nat -A OUTPUT –dst <SRC> -p tcp –dport 80 -j DNAT –to <DESTIP>:80

Removing the above rules
iptables -t nat -D PREROUTING -i eth0 -p tcp –dport 80 -j DNAT –to <DESTIP>:80
iptables -t nat -D POSTROUTING -p tcp –dst <DESTIP> –dport 80 -j SNAT –to <SRCIP>
iptables -t nat -d OUTPUT –dst <SRC> -p tcp –dport 80 -j DNAT –to <DESTIP>:80

23.List all the rules in the iptables

iptables  -L

24.Check an IP in the rule

iptables -nL | grep <IP>

25.Save the current iptables rules

iptables-save >  File_name

26.Restore iptable rules from the file

iptables-restore <  File_name

MSSQL support to PHP in cpanel server

To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases.

You can refer to the following url to get informations about mssql extension and  the functions supported with it.
http://www.php.net/manual/en/book.mssql.php

To get these functions to work, you have to compile PHP with –with-mssql[=DIR] , where DIR is the FreeTDS install prefix. And FreeTDS should be compiled using
–enable-msdblib

Installation instruction:-

(This is not specific to cpanel servers, you can recompile php directly without easyapache in any normal linux servers with ‘–with-mssql=/usr/local/freetds’)

1-. Download freetds source -> www.freetds.org
2-. tar -zxvf freetds-stable-tgz
3-. cd freetds-*
4-. ./configure –prefix=/usr/local/freetds –with-tdsver=8.0 –enable-msdblib  –with-gnu-ld

Note: If you use SQL 2000, 2005, 2008 then tds version = 8.0
if you use SQL 7.0 then tds version = 7.0

5-. make
6-. make install
7-. To check freetds working, run from terminal
7.1 /usr/local/freetds/bin/tsql -S <ip of the server> -U <User SQL>
7.2 If the connection parameters are correct you will be connected to a prompt.
8-. Add the following text in freetds.conf ( /usr/local/freetds/etc )
[TDS]
host = <ip of the Server with Sql>
port = 1433
tds version = 8.0

9-. Add the following line in the file /etc/ld.so.conf and run ldconfig -v:
include /usr/local/freetds/lib

10-. Recompile PHP with –with-mssql=/usr/local/freetds flag.
Create a file called all_php4 or all_php5 in:

‘/var/cpanel/easy/apache/rawopts/’

The file doesnt exist by default, just create it and add this line to the file:
–with-mssql=/usr/local/freetds
Easy apache will check this file ‘/var/cpanel/easy/apache/rawopts/all_php5’ for any additional php configuration option during recompilation.

11-. Run ‘/scripts/easyapache’

Notes:-

1-. If you are running a 64bit OS and get an error about configure: error: ‘Could not find /usr/local/freetds/lib64/libsybdb.a|so’
then you need to do the following:
1.1 Make sure libsybdb.so is available on the server,then
1.2 ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/lib64/libsybdb.so.5
1.3 ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/local/freetds/lib64/libsybdb.so
1.4 Run   ldconfig -v

2-. If you are getting an error about configure:’ error: Directory /usr/local/freetds is not a FreeTDS installation directory’
2.1 cp [tds source]/include/tds.h /usr/local/freetds/include
2.2 cp [tds source]src/tds/.libs/libtds.a /usr/local/freetds/lib
2.3 Recompile again.

Reference:-

http://www.freetds.org/userguide/
http://www.php.net/manual/en/book.mssql.php
http://forums.cpanel.net

Flex2gateway 404 error with railo

Railo 3.x comes with BlazeDS 3.2, the Adobe open source amf engine to communicate from a Flex application to a Java backend. But we may need to modify some tomcat configurations files to get it work.  You need to verify that tomcat configurations files are properly configured for flex or not. The following are the settings needed for Flex  services:-

#1. Updating the web.xml file

/opt/railo/tomcat/conf/web.xml

Uncomment the following settings in the web.xml if present or add the following details.

<!– Load the MessageBrokerServlet  –>
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<init-param>
<param-name>messageBrokerId</param-name>
<param-value>MessageBroker</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<!– The mappings for the Flex servlet –>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
/flex2gateway/*
</servlet-mapping>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
/flashservices/gateway/*
</servlet-mapping>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
/messagebroker/*
</servlet-mapping>

#2. Updating the uriworkermap.properties file

/opt/railo/tomcat/conf/uriworkermap.properties

Add the following details.

/*.cfm=ajp13
/*.cfc=ajp13
/*.cfml=ajp13
/*.cfres=ajp13
/*.cfchart=ajp13
/*.cfm/*=ajp13
/*.cfml/*=ajp13
/*.cfc/*=ajp13
/*.jsp=ajp13
/*.do=ajp13
/=ajp13
/flex2gateway/*=ajp13
/flashservices/gateway/*=ajp13
/messagebroker/*=ajp13
/=ajp13

Once you’ve updated Tomcat configuration files, restart Tomcat/Railo.

Verify the Flex

Browse to  http:///flex2gateway/  you should get a white page, if you get an error message, this would mean that either you server is not running, the MessageBroker Servlet is not running or there are some configuration mistakes.

Troubleshooting 404 error

Apache 404 error

1.Please understand that if the URL you’re using is this: http://mydomain/flex2gateway , then all your mappings should look like
/flex2gateway*=ajp13
There must no trailing slash on either of them.

2.Also verify the server.xml is updated correctly and hence the domain is  pointing to its  webroot.

3. Most importantly, the mod_jk module needed to be loaded in to apache, then only the connection between tomcat and apache works. So please verify the apache configurations files and verify the mod_jk is enabled. If not add the following details to the apache configuration file.

<IfModule !mod_jk.c>
LoadModule jk_module [modules directory]/mod_jk.so
<!–IfModule>

<IfModule mod_jk.c>
JkMount /*.cfm ajp13
JkMount /*.cfc ajp13
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /*.cfchart ajp13
JkMount /*.cfm/* ajp13
JkMount /*.cfml/* ajp13
Flex Gateway Mappings
# JkMount /flex2gateway/* ajp13
JkMount /flashservices/gateway/* ajp13
JkMount /messagebroker/* ajp13
JkMountCopy all
JkLogFile [log directory]/mod_jk.log
</IfModule>

ps: Please restart the httpd service.

Tomcat 404 error

The reason mostly is Tomcat servlet “MessageBrokerServlet” is unavailable or not loaded. In that case please verify the tomcat configuration files are updated correctly as mentioned above, ie web.xml and uriworkermap.properties files. Also verify tomcat log files to find out why “MessageBrokerServlet” is not loaded. Sometimes you may need to comment “MessageBrokerServlet” in other web.xml files.

Tomcat log file location:- /opt/railo/tomcat/logs/

ps: You need to restart railo/tomcat if you made any changes to tomcat configuration files.

Joomla jos_session table crashed

You may come across the following error sometime if you are working joomla site.
jtablesession::Store Failed
DB function failed with error number 145
Table ‘./eilmccco_cmsicdc/jos_session’ is marked as crashed and should be repaired SQL=INSERT INTO jos_session ( `session_id`,`time`,`username`,`gid`,`guest`,`clie nt_id` ) VALUES ( ‘ca7331cb8a008d79e24df425257229ea’,’1227636484′,” ,’0′,’1′,’0′ )

This is a very common error. The problem with this error is that you cannot access your site nor the admin page.
The error messages means that the table “jos_session” is crashed or damaged. This table stores your session information.

This issue can be easily fixed by repairing the session table. For doing this the first thing you should do is find out your joomla database. This can be done by checking your joomla configuration.php file.
Now we can try  repairing the table in following ways.

Cpanel
If you are using the Cpanel, then you can repair you joomla database by clicking the “Repair DB” option in the Mysql section of the Cpanel.

phpMyAdmin

If you can access your database though phpMyAdmin, then on the phpMyAdmin interface, select the joomla database and look for the table “jos_session”. Once you selected the “jos_session” (tick the checkbox) and choose “Repair table” from the drop-down you find at the bottom of the list of tables.

SSH access

If you have shell access of your server, the database can be repaired within the Mysql.
Login to the mysql with necessary privileges
#mysql -u <dbuser> -p
mysql> use joomla1;                              [Assume your joomla database name is joomla1]
mysql> REPAIR TABLE jos_session;

If all the above tricks failed, then you must recreate the “jos_session” table

First of all, please take a complete backup of the joomla database.

phpMyAdmin

1 – Go to MySQL phpMyadmin Control Panel

2 – Go and click on “SQL” near the top left corner of the page, and paste the following lines (below) into the empty text area :

DROP TABLE IF EXISTS `jos_session`;
CREATE TABLE `jos_session` (
`username` varchar(150) default ”,
`time` varchar(14) default ”,
`session_id` varchar(200) NOT NULL default ‘0’,
`guest` tinyint(4) default ‘1’,
`userid` int(11) default ‘0’,
`usertype` varchar(50) default ”,
`gid` tinyint(3) unsigned NOT NULL default ‘0’,
`client_id` tinyint(3) unsigned NOT NULL default ‘0’,
`data` longtext,
PRIMARY KEY (`session_id`(64)),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

3 – Click on “Execute” or “Go” to execute the command.

Thats it. This must fix your concern…

Please let me know your feedback and also if you have any other easy workaround

It all started here..

Hello Techiez,

This is my first blog on WordPress… I have been working as an Linux Server Administrator for a quite some time. I know there are thousands of Very good forums and blogs regarding the Server administration or Linux and of course i am just a Newbie to the Ocean of Linux Administration. That is the exact reason why started this blog. There are lots of people like me searching and searching in those kind of Big forums but unable to find an exact answer or help. You might not be agree with you, but i knew how it works. So i  thought let’s share whatever you got, atleast try to help…

There is only one thing i can guarantee you, This would not be “Just another WordPress.com site”.

Feel free to leave some words here

Adios for now!!

Page 7 of 7

Powered by WordPress & Theme by Anders Norén