LAMP Setup on Your Dedicated Server - Step 2 of 3 - Configuring PHP

July 1, 2008

By now you have already installed Apache onto your dedicated server. Now, let’s configure Apache to run with PHP4 or PHP5, whichever is your preference in scripting.

For PHP4, it’s as simple as apt-get:

apt-get install apache2 php4 libapache2-mod-php4

Since PHP5 can be automatically installed if you don’t specify the package ‘4’, you can do that or apt-get:

apt-get install apache2 php5 libapache2-mod-php5

To test and ensure that you are now hosting with PHP4 or PHP5, create a test file called test.php in /var/www folder with phpinfo() function as follows:

nano /var/www/test.php

# test.php

php phpinfo();

Now, just point your web browser to http://ip.address/test.php and you’ll be able to see your php config and default settings. If you don’t, check with your dedicated server administrators or web hosting provider.

From there, you can also edit necessary values or setup virtual domains, enable CAPTCHA, and more.

LAMP Setup on Your Dedicated Server - Step 1 of 3 - Installing Apache

June 26, 2008

LAMP web hosting is probably the most popular and affordable server setting for webmasters these days. If you aren’t already aware, LAMP stands for Linux, Apache, MySQL, and PHP and defines how your dedicated server will run – it will be Linux hosting with an Apache server, MySQL databases, and PHP development.

The first step to create a LAMP server setup is to install Apache on your Linux machine.

1) Download Apache from Apache Software Foundation.

2) Uncompress the archive using gunzip and tar and replace apache_1.3.11.tar.gz in the example here with the name of the current live version you just downloaded:

gunzip < apache_1.3.11.tar.gz | tar xvf –

This should create an apache_1.3.11 directory.

3) Move into the new directory you just created and use cd apache_1.3.11.

4) ./configure in the root so that your screen appears as such:

# ./configure
Configuring for Apache, Version 1.3.11

Creating Makefile
Creating Configuration.apaci in src
Creating Makefile in src
+ configured for Linux platform
+ setting C compiler to gcc
+ setting C pre-processor to gcc -E
+ checking for system header files
+ adding selected modules
+ checking sizeof various data types
+ doing sanity check on compiler and options

Creating Makefile in src/modules/standard

5) make so that your screen looks like this:

# make
===> src
make[1]: Entering directory `src/httpd/apache_1.3.11′
make[2]: Entering directory `src/httpd/apache_1.3.11/src’
===> src/regex

[several lines later]

gcc  -DLINUX=2 -DUSE_HSREGEX -DUSE_EXPAT -I../lib/expat-lite

-DNO_DL_NEEDED `../apaci` -o ab   -L../os/unix

-L../ap ab.o -lap -los  -lm -lcrypt

make[2]: Leaving directory `src/httpd/apache_1.3.11/src/support’
<=== src/support

make[1]: Leaving directory `src/httpd/apache_1.3.11′
<=== src
#

6) Install your new Apache with # make install and you’re done!

Now you are welcome to start Apache to make sure it’s working if you’d like.

As root, type /usr/local/apache/bin/apachect1 start and your browser at your brand new web server at yourdomain.com. If you see the Apache standard “It worked!” homepage, you are set.

Blocking an IP Address on Your Dedicated Server

June 18, 2008

You may be thinking why do I want to block IP addresses from my dedicated server? If you have never run a dedicated server before, you might not be aware that there are people who attempt to hack entire servers to bring websites down. There are many types of server attacks, and one of the most popular can occur from a single dedicated IP address – a DdoS attack!

In order to subdue the attacker and ban them from coming back, you will need to block their IP address from your dedicated server entirely. Luckily, you can do this in one simple step.

Add the following code to your .htaccess file, which can be found in your web server’s document root directory. More than likely this is named public_html, httpdocs, or webdocs.

<Limit GET>
order deny,allow
deny from 209.23.123.110
</Limit>

Adding this to .htaccess will block a single IP across your entire website and server! Be aware though: spammers and hackers alike can change their IP addresses very easily and most IPs that come from a home computer, for example, are not static and may update often. You can always add more IPs to your server, but this really showcases the importance of having a workable managed hosting solution on your dedicated server.

Setting Up Private Nameservers on Your Dedicated Server (Part 2 of 2)

May 22, 2008

Step 6: Edit Files in SSH Shell

Login to your SSH Shell into your server as root and open the following 2 files to edit using the information below:

* file 1:
nano /etc/resolv.conf

From there, the file needs to be edited. Make sure it looks like this:

domain yourwebsite.com
search yourwebsite.com
nameserver 127.0.0.1
nameserver IP1
nameserver IP2

At this point you should save by typing ctrl+o and entering. Then, close the file by typing ctrl+x.

* file 2:
nano /etc/nameserverips

The file needs to be edited, just like File 1. Make sure it looks like this:

IP0=0
IP1=ns1.yourwebsite.com
IP2=ns2.yourwebsite.com

**Please note IP0=your server IP**

Save and close as per File 1.

Step 7: Setup Nameservers in WHM

In WHM, select Edit Server again and set your Primary Nameserver to ns1.yourwebsite.com and assign the IP Address once more – it should now be the correct IP. Then click Add an A Entry for This Nameserver and repeat the process for the Secondary Nameserver using ns2.yourwebsite.com. Make sure you save.

Then you can double check that everything is setup properly by selecting Manage Nameserver IPs in WHM. If you see the 2 IPs and nameservers, you’re all set.

Step 8: Reboot Your Dedicated Server

Get into the Shell via SSH as root and type the simple command: reboot

Step 9: Point Your Domain Nameservers

If you host with LPDedicated.com or Lunarpages, you can login via the instructions in our previous post to manage your domain nameservers. Make sure they are pointed correctly, and once they fully propagate (24 hours or so), your nameservers will be listed properly and your website will resolve on your dedicated server!

Setting up Private Nameservers on Your Dedicated Server (Part 1 of 2)

May 21, 2008

When you purchase a dedicated server hosting plan, you will need to specify which nameservers you want to use. Unlike shared web hosting where you can only use your web host’s company name servers, with dedicated web hosting you can create your own private nameservers! This means your website will point to ns1.yourwebsite.com and ns2.yourwebsite.com

Step 1: Register Your Domain Name

If you purchase dedicated web hosting with LPDedicated.com, you can get your domain name registered for free. Otherwise, you can purchase the domain from a domain registrar or if you already have it purchased, just skip this step.

Step 2: Purchase 2 Dedicated IP Addresses

LPDedicated.com provides 2 Free IP Addresses for your dedicated server, both of which can be used for this purpose. Otherwise, IPs normally cost under $5 per IP per month.

Step 3: Register Your Nameservers

If you purchased hosting with LPDedicated.com or Lunarpages, you can do this easily. Simply read through this quick tutorial on Registering Your Name Servers. If you purchased through an outside domain registrar, contact them and let them know you need to register your domain as a nameserver. Most registrars normally take about 3 days to propagate.

Step 4: Fix NDC

You’ll need to login via SSH into your server at the root and run the following command:

/scripts/updatenow
/scripts/fixndc

Then, if you’re hosting with LPDedicated.com, in WHM on the left window pane, restart DNS/Nameserver (BIND). If you’re hosting elsewhere, check with your provider for further instructions.

Step 5: Set Up Your Nameservers in WHM

Visit your WHM panel again, and select Edit Setup near the top fo the left window pane and then set the Primary Nameserver to ns1.yourwebsite.com. Then assign the IP Address and repeat the process using ns2.yourwebsite.com for the Secondary Nameserver. Make sure you save your work!

More Help with Securing Dedicated SSH

After yesterday’s article I thought I would also list an alternative way to help secure the SSH.  You can also secure your ssh changing default port (22).  Change the port that SSH listens for connections on:

      #Port 22
      Port XX    (where XX = your new portnumber)

You can choose something like 22202 or something you can remember.

You are now done editing the /etc/ssh/sshd_config file (save your changes, and quit your editor).
Another important thing dont forgot to allow the port you choose from firewall:

      /etc/apf/conf.apf

Then you add there your new ssh port.  Hope you enjoyed.  Any good dedicated hosting provider should be able to provide you with additional help if needed.

Securing Shell on a Dedicated Server

May 20, 2008

By default SSH will give root and any local user secure access to the server. For security reasons it is a good idea to change this setting and specify the users which are allowed to have SSH access. The configuration file for SSH is called sshd_config and is either in /etc or /etc/ssh

Login to the server and on the command prompt do:

[root@office root]# vi /etc/ssh/sshd_config

things to change:

#don't allow root to SSH in to the server:
PermitRootLogin no

#users allowed to login:
AllowUsers user1 user2 user3

Now do a “shift zz” (hold down the shift key and tab 2 times the z key)
The configuration file now is saved and closed and you have to restart ssh:

[root@office root]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@office root]#

Now you can SSH to your server with your username,then do a su on the command prompt and type in the root password to become root.

More on Cron Jobs for Your Dedicated Server

May 19, 2008

Using cron jobs on your dedicated server can help you backup your server, send emails, delete files, or run scripts. In the long run, this can save you precious manpower and even money, as you don’t have to pay a technician, system admin, or other employee to do these things on a scheduled basis for you.

To get started using cron jobs, you need to know a bit more about how to use them.

Start by typing “contab -e” to begin editing your cron file. A couple other really useful commands include “crontab-l” for a list or “crontab -r” to delete a previously-created cron job.

Looking at your list of cron jobs, they should look like this:

1 2 3 4 5 /bin/YourStuff etc

Each of the numbers above represent specific schedule times that you can incorporate to produce tasks on a monthly, daily, hourly, etc., basis. They are as follows:

1: Stands for minutes, so if you want a cron job to run every 5 minutes, you would start that sequence above with “5”. Works with numeric values from 0-59.

2: Stands for hours, so as above, if you want it to run every 2 hours, you would include a “2” in the above sequence. Works with numbers 0-23.

3: Stands for days, so if you want to run a cron job in dedicated web hosting every 6 days, you would input a “6” where applicable. Works with numbers 0-31.

4: Stands for the month, where 0=January and 12=December.

5: Stands for the actual day of the week, where 0=Monday and 7=Sunday.

Keep in mind, you can also edit these cron jobs to apply to various other formats. For example, you could set up a cron job to run 1-4/2 or every third week with */3. You can also define executions via the Shell and specify where you want the results emailed as below:

SHELL=/bin/whatever
MAILTO=youremail@yourdomain.com

Cron Jobs

May 15, 2008

Using cron jobs can save you time, money, and lots of headaches! But do you know what a cron job is and what it can do for you and your dedicated server hosting?

To start, you can impress your friends and tech-geeks alike by letting them know that ‘cron’ comes from the Greek word ‘chronos’, which means ‘time’. And in fact cron jobs manage things in a time-based banner – for example, every minutes, every hour, every day, etc.

Cron jobs are simply scheduling devices and work through SSH shell without you. In other words, once you set up a cron job, it will essentially perform its task in the background while you sip margaritas and watch the money roll in. Okay, maybe they won’t make you rich, but they will save you time and money by performing the same tasks you need to implement without costing you any trouble. Once you set them up once, they do what they’re told until told to stop.

By using cron jobs, you eliminate the middle-man. You can set tasks for your website like checking for new subscribers, deleting inactive website members, sending email newsletters and more. Especially for email marketing on a dedicated server, cron jobs can help manage the amount of emails sent per hour and eliminate the worry of getting blacklisted for normal email marketing and newsletter distribution.

Using APF on a Dedicated Server

April 4, 2008

You should have a look at the first 4 parts of this tutorial series on installing, configuring, and running APF (Advanced Policy Firewall) on a Dedicated Server before proceeding here, just to be sure your dedicated server is setup correctly with APF configurations. Here is a quick list to roundup these tutorials on dedicated web hosting and APF setup:

1. Installing APF on a Dedicated Server

2. Configuring APF on a Dedicated Server

3. Configuring AntiDOS on a Dedicated Server for APF (optional)

4. Starting APF on a Dedicated Server

Now, here are some helpful commands for your Firewall Usage. With these codes and options, you can do nearly everything necessary to run APF, block IP addresses, flush the firewall, etc. Please review these APF codes below and keep them handy for future reference.

Firewall Usage

Usage /usr/local/sbin/apf [OPTION]

OPTIONS are as below

-s|–start ……………………. load firewall policies
-r|–restart ………………….. flush & load firewall
-f|–flush|–stop ……………… flush firewall
-l|–list …………………….. list chain rules
-st|–status ………………….. firewall status
-a HOST CMT|–allow HOST COMMENT … add host (IP/FQDN) to allow_hosts.rules and immediately load new rule into firewall
-d HOST CMT|–deny HOST COMMENT …. add host (IP/FQDN) to deny_hosts.rules and immediately load new rule into firewall

As an example, if you would like to deny an IP from accessing your sites, execute,

apf -d 123.123.123.123

Hopefully this tutorial series for APF on a Dedicated Server has been extremely helpful to you, but if you’re ever stuck, contact your dedicated web hosting provider and ask for Managed Hosting solutions.