The .htaccess file is pretty handy as it can also allow you to set various PHP flags that you may not want enable for all of you websites and in turn will let you run just about every PHP flag or directive on a one on one website basis.
You will need to log into your Linux server directly using SSH. If you are not familiar on how to do this, we have articles on how to implement this on both Windows and Mac;
Windows - http://www.hosting.com/support/linux/general/sshwindows
Mac - http://www.hosting.com/support/linux/general/sshmac
To create the .Htaccess file, you meerly need to create a text file with any Linux editor. The file must be called .htaccess and it must exist in the root directory of the website you want override the Php global directives for.
The format of the .htaccess is simple, however you will want to comment out exactly what flag or directive you are enabling for the site. An example of this would be as seen below;
#Turn register goabls of
php_value register_globals off
#Php max upload size
php_value upload_max_filesize 12M
php_value post_max_size 12M
#Enable another version of php if you have two installed (Enable Php 5)
AddType application/x-httpd-php5 .htm .html .php
Make sure you save the file when you are done editing it.
Just about any directive or flag can be added to the .htaccess file so you can commently customize the php functions of the website instead of changing it globally in the php.ini file. For a list of what you can use, please review the PHP manual at http://php.net/manual/en/index.php.
Using a .htaccess file will grant you greater control over your website, such as safe guarding it from hacking attempts or even keeping out spammers who may frequent your website. A great feature of using a .htaccess file is the ability to populate it with single IP addresses or entire IP ranges, effectively blocking those IP's from being able to access your server. This article will explain how to implement this via the .htaccess file.
You will need to log into your Linux server directly using SSH. If you are not familiar on how to do this, we have articles on how to implement this on both Windows and Mac.
To create the .htaccess file, you need to create a text file with any Linux editor. The file must be called .htaccess and it must exist in the root directory of the website you want to deny access to.
In the file, there is a specify format you must adhere to. To block both single IP's and IP ranges, you must include the following;
order allow,deny - The rule set
deny from 192.168.1 - IP you want to block
deny from 24.0.0.0/23 - IP Range you want to block
Please note to block an IP Range, you must know the subnet.
You can also specify a deny all and allow rule set as well;
order deny,allow - The rule set
deny from all - Deny access from all IP's.
Allow from 192.12.4.1 - IP you want to allow.
An example of a file blocking IP address 1.2.3.4 and a subnet 2.0.x.x is below:
order allow,deny
allow from all
deny from 1.2.3.4
deny from 2.0.
You will need to log into your Linux server directly using SSH. If you are not familiar on how to do this, we have articles on how to implement this on both Windows and Mac.
To create the .htaccess file, you need to create a text file with any Linux editor. The file must be called .htaccess and it must exist in the root directory of the website you want to deny access to.
In the file, there is a specify format you must adhere to. To block both single IP's and IP ranges, you must include the following;
order allow,deny - The rule set
deny from 192.168.1 - IP you want to block
deny from 24.0.0.0/23 - IP Range you want to block
Please note to block an IP Range, you must know the subnet.
You can also specify a deny all and allow rule set as well;
order deny,allow - The rule set
deny from all - Deny access from all IP's.
Allow from 192.12.4.1 - IP you want to allow.
An example of a file blocking IP address 1.2.3.4 and a subnet 2.0.x.x is below:
order allow,deny
allow from all
deny from 1.2.3.4
deny from 2.0.
VNstat is a bandwidth monitoring tool that will let you monitor your bandwidth and provide daily, weekly and monthly tracking metrics.
To install and setup Vnstat, you will need to follow the steps in this article.
Log into your linux server and type the following command.wget http://humdi.net/vnstat/vnstat-1.10.tar.gz
Next to uncompress the file you will need to run the following command. tar -zxvf vnstat-1.10.tar.gz
Now that you have the file uncompressed, you will need to install Vnstat. To do this, you will need to navigate to the VNstat directory and run the following command.
make & make install
Now that it has been installed, you will first need to run "vnstat --iflist" on your server, so you know the name of your network adaptors. vnstat --iflist
You will now be presented with the any available adaptors on your server. Available interfaces lo eth0 sit0
Now that you know what adaptors you have on your server, you will need to tell VNstat to create a small database for that adapator. To do this, simply type /usr/bin/vnstat -u -i then the adaptor name. So for our example, we would run the following /usr/bin/vnstat -u -i eth0 If you have multiple adaptors, you will need to do this for each adaptor. However you do not have to if you only want to monitor specific adaptors.
Next, make sure that Vnstat restarts whenever you reboot your server. To do this, add the service to your server's "Chkconfig" list by running the following command.
chkconfig --add vnstat
chkconfig vnstat on
Now you can access Vnstat by logging into the server at anytime and typing "vnstat". Doing so will give you a realtime status of your bandwidth.
To install and setup Vnstat, you will need to follow the steps in this article.
Log into your linux server and type the following command.wget http://humdi.net/vnstat/vnstat-1.10.tar.gz
Next to uncompress the file you will need to run the following command. tar -zxvf vnstat-1.10.tar.gz
Now that you have the file uncompressed, you will need to install Vnstat. To do this, you will need to navigate to the VNstat directory and run the following command.
make & make install
Now that it has been installed, you will first need to run "vnstat --iflist" on your server, so you know the name of your network adaptors. vnstat --iflist
You will now be presented with the any available adaptors on your server. Available interfaces lo eth0 sit0
Now that you know what adaptors you have on your server, you will need to tell VNstat to create a small database for that adapator. To do this, simply type /usr/bin/vnstat -u -i then the adaptor name. So for our example, we would run the following /usr/bin/vnstat -u -i eth0 If you have multiple adaptors, you will need to do this for each adaptor. However you do not have to if you only want to monitor specific adaptors.
Next, make sure that Vnstat restarts whenever you reboot your server. To do this, add the service to your server's "Chkconfig" list by running the following command.
chkconfig --add vnstat
chkconfig vnstat on
Now you can access Vnstat by logging into the server at anytime and typing "vnstat". Doing so will give you a realtime status of your bandwidth.
Mumble is an opensource, low-latency, high quality VoIP voice chat software that is primarily intended for gaming. It's a free and worthy (often consider superior) alternative to more widely used software such as Teamspeak or Ventrilo.
Mumble's server component, known as 'murmur', is not provided in rpm format for easy installation to Redhat or CentOS server. The software is also not provide by the default or common third party yum repositories. However, installation can be done using a static binary package that is available.
Download
Before we can extract needed files, the lzma compression tool must be installed. This can easily be done using yum.
yum install lzma
Now, both the static binary package and an RPM from another Linux distribution must be downloaded to the server.
wget http://sourceforge.net/projects/mumble/files/Mumble/1.2.3/murmur-static_x86-1.2.3.tar.bz2/download
wget ftp://rpmfind.net/linux/Mandriva/devel/cooker/x86_64/media/contrib/release/mumble-server-1.2.2-3mdv2011.0.x86_64.rpm
Extract and Install Executable
Next, the murmur executable must be extract from the static binary package and installed into the server's PATH.
tar -xjf murmur-static_x86-1.2.3.tar.bz2
cp murmur-static_x86-1.2.3/murmur.x86 /usr/sbin/murmurd
Extract and Install Service Script and Config
To obtain a init startup script as well as a default config file, the downloaded rpm must be extracted.
rpm2cpio mumble-server-1.2.2-3mdv2011.0.x86_64.rpm > file.lzma
lzma -d file.lzma
mkdir mumble-rpm
cd mumble-rpm
cpio -imv --make-directories < ../file
rm ../file
The extracted files can now be moved into the system.
cp etc/mumble-server.ini /etc
cp etc/rc.d/init.d/mumble-server /etc/rc.d/init.d
chmod a+x /etc/rc.d/init.d/mumble-server
Next, a system user for murmur must be created and assigned to required directories and files.
upadd -g 4000 mumble-server useradd -g 4000 -G mumble-server -s /sbin/nologin -d / -M mumble-server mkdir /var/lib/mumble-server chown mumble-server:mumble-server /var/lib/mumble-server
mkdir /var/log/mumble-server
chown mumble-server:mumble-server
/var/log/mumble-server
Starting Mumble Server
Due to difference between Redhat/CentOS init scripts and the distribution the extracted RPM was built for, we must modify the installed init.d scripts
Execute:
nano /etc/rc.d/init.d/mumble-server
In nano editor, type CTRL+\ to bring up the search and replace tool. Search for the text 'gprintf', and replace with 'printf'. Select 'A' to replace all instances, then CTRL+o to save, and CTRL+x to exit.
The mumble server can now be started.
service mumble-server start
You may now connect your mumble client to your server using your server's IP and the default mumble port.
Run at System Boot
To have mumble server start at system boot, simply add the init script to the run level with ckconfig.
chkconfig --add mumble-server
chkconfig mumble-server on
Mumble's server component, known as 'murmur', is not provided in rpm format for easy installation to Redhat or CentOS server. The software is also not provide by the default or common third party yum repositories. However, installation can be done using a static binary package that is available.
Download
Before we can extract needed files, the lzma compression tool must be installed. This can easily be done using yum.
yum install lzma
Now, both the static binary package and an RPM from another Linux distribution must be downloaded to the server.
wget http://sourceforge.net/projects/mumble/files/Mumble/1.2.3/murmur-static_x86-1.2.3.tar.bz2/download
wget ftp://rpmfind.net/linux/Mandriva/devel/cooker/x86_64/media/contrib/release/mumble-server-1.2.2-3mdv2011.0.x86_64.rpm
Extract and Install Executable
Next, the murmur executable must be extract from the static binary package and installed into the server's PATH.
tar -xjf murmur-static_x86-1.2.3.tar.bz2
cp murmur-static_x86-1.2.3/murmur.x86 /usr/sbin/murmurd
Extract and Install Service Script and Config
To obtain a init startup script as well as a default config file, the downloaded rpm must be extracted.
rpm2cpio mumble-server-1.2.2-3mdv2011.0.x86_64.rpm > file.lzma
lzma -d file.lzma
mkdir mumble-rpm
cd mumble-rpm
cpio -imv --make-directories < ../file
rm ../file
The extracted files can now be moved into the system.
cp etc/mumble-server.ini /etc
cp etc/rc.d/init.d/mumble-server /etc/rc.d/init.d
chmod a+x /etc/rc.d/init.d/mumble-server
Next, a system user for murmur must be created and assigned to required directories and files.
upadd -g 4000 mumble-server useradd -g 4000 -G mumble-server -s /sbin/nologin -d / -M mumble-server mkdir /var/lib/mumble-server chown mumble-server:mumble-server /var/lib/mumble-server
mkdir /var/log/mumble-server
chown mumble-server:mumble-server
/var/log/mumble-server
Starting Mumble Server
Due to difference between Redhat/CentOS init scripts and the distribution the extracted RPM was built for, we must modify the installed init.d scripts
Execute:
nano /etc/rc.d/init.d/mumble-server
In nano editor, type CTRL+\ to bring up the search and replace tool. Search for the text 'gprintf', and replace with 'printf'. Select 'A' to replace all instances, then CTRL+o to save, and CTRL+x to exit.
The mumble server can now be started.
service mumble-server start
You may now connect your mumble client to your server using your server's IP and the default mumble port.
Run at System Boot
To have mumble server start at system boot, simply add the init script to the run level with ckconfig.
chkconfig --add mumble-server
chkconfig mumble-server on
Configure the YUM repository to look in the correct location for an upgraded PHP RPM. There are many different repositories online that offer upgraded RPMs for PHP so a quick search via Google will be of assistance. For this article we'll be referencing the YUM repositories at webtatic.com
Tell rpm to accept rpm's signed by webtatic
rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy
Add the yum repository information to yum
wget -P /etc/yum.repos.d/ http://repo.webtatic.com/yum/webtatic.repo
Update the existing installation of PHP which will also update all of the other PHP modules installed
yum --enablerepo=webtatic update php
Type Y and let the process complete.
You can now see your current version of PHP using php –v from the shell prompt.
Tell rpm to accept rpm's signed by webtatic
rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy
Add the yum repository information to yum
wget -P /etc/yum.repos.d/ http://repo.webtatic.com/yum/webtatic.repo
Update the existing installation of PHP which will also update all of the other PHP modules installed
yum --enablerepo=webtatic update php
Type Y
You can now see your current version of PHP using php –v from the shell prompt.
By default the Linux OS has a very efficient memory management process that should be freeing any cached memory on the machine that it is being run on. However when it comes to Cached memory the Linux OS may at times decide that the Cached memory is being used and is needed which can lead to memory related issues and ultimately rob your server of any potentially free memory. To combat this you can force the Linux OS to free up and stored Cached memory.
Connect via shell using a program such as Putty
At the shell prompt type crontab -e as this will allow you to edit cron jobs for the root user.
If you are not familiar with vi (linux editor) you press "i" to insert text and once done hit "esc" and type ":wq" to save the file.
Scroll to the bottom of the cron file using the arrows key and enter the following line:
0 * * * * /root/clearcache.sh
Create a file in '/root' called 'clearcache.sh' with the following content:
#!/bin/sh
sync; echo 3 > /proc/sys/vm/drop_caches
Once you have saved this file, the job is complete!
Every hour the cron job will run this command and clear any memory cache that has built up.
An example from a test server before and after running this task.
BEFORE:
AFTER:
Note before the server was using 1.918Gb of RAM with 1.4983Gb in Cache and after running the script the server is now only using 172Mb of RAM and only 38.9Gb in Cache.
Connect via shell using a program such as Putty
At the shell prompt type crontab -e
If you are not familiar with vi (linux editor) you press "i" to insert text and once done hit "esc" and type ":wq" to save the file.
Scroll to the bottom of the cron file using the arrows key and enter the following line:
0 * * * * /root/clearcache.sh
Create a file in '/root' called 'clearcache.sh' with the following content:
#!/bin/sh
sync; echo 3 > /proc/sys/vm/drop_caches
Once you have saved this file, the job is complete!
Every hour the cron job will run this command and clear any memory cache that has built up.
An example from a test server before and after running this task.
BEFORE:
AFTER:
Note before the server was using 1.918Gb of RAM with 1.4983Gb in Cache and after running the script the server is now only using 172Mb of RAM and only 38.9Gb in Cache.
The network scripts are located in /etc/sysconfig/network-scripts/. Go into that directory.
cd /etc/sysconfig/network-scripts/
The file we're interested in is ifcfg-eth0, the interface for the Ethernet device. Let's assume we want to bind three additional IP's (192.168.1.111, 192.168.1.112, and 192.168.1.113) to the NIC. We need to create three alias files while ifcfg-eth0 maintains the primary IP address. This is how we'll set up the aliases to bind the IP addresses.
Adapter IP Address Type
-----------------------------------
eth0 192.168.1.110 Primary
eth0:0 192.168.1.111 Alias 1
eth0:1 192.168.1.112 Alias 2
eth0:2 192.168.1.113 Alias 3
The :X (where X is the interface number) is appended to the interface file name to create the alias. For each alias you create you assign a number sequentially. For this example we will create aliases for eth0. Make a copy of ifcfg-eth0 for the three aliases.
cp ifcfg-eth0 ifcfg-eth0:0
cp ifcfg-eth0 ifcfg-eth0:1
cp ifcfg-eth0 ifcfg-eth0:2
Take a look inside ifcfg-eth0 and review the contents.
more ifcfg-eth0
We're interested in only two lines (DEVICE and IPADDR). We'll rename the device in each file to its corresponding interface alias and change the IP's. We'll start with ifcfg-eth0:0. Open ifcfg-eth0:0 in vi and change the two lines so they have the new interface and IP address.
vi ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=192.168.1.111
Save ifcfg-eth0:0 and edit the other two alias files (ifcfg-eth0:1 and ifcfg-eth0:2) so they have the new interfaces and IP addresses set (follow the table from above). Once you save all your changes you can restart the network for the changes to take effect.
service network restart
To verify all the aliases are up and running you can run ifconfig (depending on how many new IP's you set up, you can use ifconfig | more to pause the output).
ifconfig
You can also test the IP's by pinging them from a different machine. If everything is working then there should be a response back.
ping 192.168.1.111
ping 192.168.1.112
ping 192.168.1.113
cd /etc/sysconfig/network-scripts/
The file we're interested in is ifcfg-eth0, the interface for the Ethernet device. Let's assume we want to bind three additional IP's (192.168.1.111, 192.168.1.112, and 192.168.1.113) to the NIC. We need to create three alias files while ifcfg-eth0 maintains the primary IP address. This is how we'll set up the aliases to bind the IP addresses.
Adapter IP Address Type
-----------------------------------
eth0 192.168.1.110 Primary
eth0:0 192.168.1.111 Alias 1
eth0:1 192.168.1.112 Alias 2
eth0:2 192.168.1.113 Alias 3
The :X (where X is the interface number) is appended to the interface file name to create the alias. For each alias you create you assign a number sequentially. For this example we will create aliases for eth0. Make a copy of ifcfg-eth0 for the three aliases.
cp ifcfg-eth0 ifcfg-eth0:0
cp ifcfg-eth0 ifcfg-eth0:1
cp ifcfg-eth0 ifcfg-eth0:2
Take a look inside ifcfg-eth0 and review the contents.
more ifcfg-eth0
We're interested in only two lines (DEVICE and IPADDR). We'll rename the device in each file to its corresponding interface alias and change the IP's. We'll start with ifcfg-eth0:0. Open ifcfg-eth0:0 in vi and change the two lines so they have the new interface and IP address.
vi ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=192.168.1.111
Save ifcfg-eth0:0 and edit the other two alias files (ifcfg-eth0:1 and ifcfg-eth0:2) so they have the new interfaces and IP addresses set (follow the table from above). Once you save all your changes you can restart the network for the changes to take effect.
service network restart
To verify all the aliases are up and running you can run ifconfig (depending on how many new IP's you set up, you can use ifconfig | more to pause the output).
ifconfig
You can also test the IP's by pinging them from a different machine. If everything is working then there should be a response back.
ping 192.168.1.111
ping 192.168.1.112
ping 192.168.1.113
Subscribe to:
Posts (Atom)