All posts tagged php

New server setup

By Tavis J. Hampton in: VPS & Dedicated Web servers

server rack

Question: I want to setup my own server. What software and tools will I need?

Answer: The first major decision to make after you have purchased server hardware is what operating system to use. Many servers come with one already, but if yours does not, you will need to decide on one. Linux or other Unix variants, such as BSD or Solaris are by far the most popular, but there are also many Windows servers out there. If you are on a limited budget, go with a free Linux distribution, such as CentOS.

The next thing to choose is the web server. Choices include Apache, Nginx, and Lighttpd. After that, you will probably one a database server such as MySQL or PostgreSQL Finally, you will want a web-based control panel. Depending on the one you choose, it might also install its own versions of Apache, PHP, and MySQL.

There are many control panel solutions on the market, and most of them are commercial. Popular control panels includ cPanel and Plesk. There are also free solutions available like Virtualmin. Decide what you need for whatever type of websites you plan to have and then choose the software that meets those needs.

Photo: Flickr

Continue reading: New server setup

....
share this 0 comments

How to redirect a web page without .htaccess

By Tavis J. Hampton in: Web Hosting

PHP logo
Question: I have a shared hosting account, but my web host has disabled my ability to make .htaccess files. How can I create redirects on my site?

Answer: First of all, it is a bad practice for a web hosting provider to completely disable .htaccess. You should probably consider getting a new host, but if that is not an immediate option, you can use PHP to redirect.

First, replace all of the code in the file you want to redirect to this:

< ?php
header( 'Location: http://www.domainname.com/new-page.html' ) ;
?>

Change the address to reflect your real domain and the correct filename for your new page.

That’s it! There is no second step. You need to make sure that there is no text before the PHP code, not even the <html> tag. Now, every time users visit the old page, they will be automatically redirected to the new one.

Continue reading: How to redirect a web page without .htaccess

....
share this 0 comments

How to compare two files in Linux

By Tavis J. Hampton in: VPS & Dedicated Software

diff command

Question: I have two scripts in a directory on my server. One is the right one and one is not, but I do not remember which is which. How can I compare the two files?

Answer: Linux and UNIX-like operating systems usually come with a comparison command called “diff”. This command will display line-by-line differences between two files. It is useful for software developers, but web developers and web application managers will find it useful as well.

To use it, just enter:

diff script1.php script2.php

It will search through both PHP scripts and find any lines that are different. The output will look something like this:

if(!function_exists('add_action')){
header('HTTP/1.0 404 Not Found');
header('Location: ../../');
> exit();
}

In the first file “exit();” is not present, while the second file correctly contains it. Tomorrow we will learn how to merge the two differing files into one correct file.

Continue reading: How to compare two files in Linux

....
share this 0 comments

Micro-blogging on your own domain with StatusNet

By Tavis J. Hampton in: Web Hosting Web servers Software

StatusNet

Twitter has become very popular in a short amount of time. With it, users can post short updates about what they are currently doing, working on, thinking, or viewing/accessing. For businesses, it is a good way to communicate with others who might not be in the same office or even the same city or country. The downside to this is that Twitter is used by so many others for other purposes, and users are often inundated with requests.

Running a micro-blogging server of your own might be very appealing, particularly if you only need it for a company’s business and do not want outsiders to view it. While hosted solutions like Twitter offer privacy options, you would still be trusting your security to a third party. StatusNet is a free micro messaging platform that powers the also popular Identi.ca.

You can host it on your own domain, share files, create groups, add plug-ins and applications, and access it via both desktop computers and mobile devices. It is a PHP application that stores data in MySQL databases. StatusNet is free software released under the GNU AGPL and is available for download directly from the project’s website.

Continue reading: Micro-blogging on your own domain with StatusNet

....
share this 0 comments

How to set resource limits on PHP

By Tavis J. Hampton in: VPS & Dedicated Web servers Software

PHP logoIn a previous post, we learned how to increase the memory limit on PHP by editing the php.ini file. But limits exist for a reason, and although you would probably love to give every process, every script, and every website unlimited CPU cycles, memory, and bandwidth, it just isn’t possible.

To begin editing, open /etc/php.ini in your text editor of choice. For example:

# nano /etc/php.ini

Look for the following values and change them to fit your requirements for your server. Below are just suggested values:

max_execution_time = 30
max_input_time = 30
memory_limit = 40M
post_max_size = 8M
upload_max_filesize = 2M

You may need to adjust the actual size limits to meet the requirements of certain content management systems or scripts, but be sure to not get carried away with being too liberal.

Continue reading: How to set resource limits on PHP

....
share this 0 comments

Installing software on an OpenSolaris server

By Tavis J. Hampton in: VPS & Dedicated Web servers

OpenSolaris logo
Continuing with our tour of server operating systems, today we will take a look at Sun Microsystems’ OpenSolaris, the free and open source version of the popular Unix-based Solaris OS. Those who experience with other Unix or Linux servers should find much of OpenSolaris familiar. Nevertheless, there are some key differences.

One of the first things you will want to do with a new OpenSolaris dedicated server would be to install software. The command for installing packages is “pkg”. For example, if you wanted to install mysql, you would type from the command line:

pfexec pkg install SUNWmysql

To install the complete PHP, MySQL, and Apache stack, install the meta package called “amp”.

pfexec pkg install amp

The same command “pkg install” can be used for upgrading packages, and it will automatically upgrade any of the packages dependencies as well. For more information about installing packages in OpenSolaris, see the Sun website.

Continue reading: Installing software on an OpenSolaris server

....
share this 0 comments

WampServer on Windows

By Tavis J. Hampton in: Web Hosting Web servers Software

WampServer

We have spent a great deal of blog space learning about Linux servers and how to optimize them, but Linux is certainly not the only kid on the block. This week we will look at some other operating systems and how they interact with the Web. First up is Microsoft Windows.

The standard web server on Windows comes with Microsoft’s IIS (Internet Information Service), but some of us still prefer open source technologies even on Windows. LAMP (Linux Apache MySQL and PHP) has become famous for its stability and reliability, but some people prefer to replace the L with a W. What you get is WAMP, and there is free software available that will install WAMP for you automatically on Windows. It is called WampServer.

WampServer will install versions of Apache, MySQL, and PHP on your Windows system with little hassle. The site does not seem to specify which versions of Windows it supports, but it should work with any Windows server. In addition to the base release, there are also addons that users can install to extend the application’s usability. WampServer is free software released under the GNU General Public License.

Source: WampServer

Continue reading: WampServer on Windows

....
share this 0 comments

Adding "last modified" code to your PHP website

By Tavis J. Hampton in: Web Hosting Software

PHP code

Question: How can I use PHP to display the “last modified” date on my website’s main page?

Answer: For any type of website that includes factual information, it is important to tell users when the information was added to the site. Information that was relevant five years ago might not be so today. Using a “last modified” line at the bottom of the page is a standard way of accomplishing this.

If you are running PHP and have a content management system, it is sufficient to put the “last modified” code at the bottom of the index.php page or its corresponding template. That way, every time someone accesses any page on the site, the last modified code will be executed.

Edit your PHP file, and enter the following code:

< ?php
// outputs e.g. 'Last modified: March 04 1998 20:43:59.'
echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());
?>

The information after “//” is just a comment to remind you of what the code does. Save the file and re-upload it to your server (if necessary), and you are all done.

Photo: Flickr

Continue reading: Adding "last modified" code to your PHP website

....
share this 0 comments

PhpSecInfo: PHP security information tool

By Tavis J. Hampton in: Web Hosting Security Web servers

PHPSecInfo screenshot

Allowing access to any type of scripting on your web server opens the door for security problems. You never know when an attacker might randomly (or purposely) select your server as a target. Any running scripts have the potential for exploitation. PHP is no exception, and taking steps to secure PHP goes a long way in preventing an attack.

PhpSecInfo is one of the steps you can take. It is a small information tool that reports security information about PHP and offers suggestions on how to improve them. It is probably best described as a low level security tool that can be useful in helping identify problems before moving up to higher security auditing.

PhpSecInfo does not examine your PHP code to see if you have any possible security holes. Thus, it states clearly on its website that it is not a replacement for secure coding practices. What it can do is give you information about the PHP environment itself and how it is setup on your server. It is very easy to install, as it is itself a PHP script. Just uncompress it in a document directory on your server and open the URL pointing to it in a browser. PhpSecInfo is available for download from the PHP Security Consortium website and is free software released under the New BSD License.

Source and Photo: PHP Security Consortium

Continue reading: PhpSecInfo: PHP security information tool

....
share this 0 comments

PHP module vs PHP CGI binary

By Tavis J. Hampton in: VPS & Dedicated Web servers Software

PHP logoQuestion: What are the differences between running PHP as an Apache module and running it as a CGI binary on a Linux server?

Answer: One of the biggest differences between a PHP Apache module and a PHP CGI binary is that the Apache module is just that: a module of Apache that is dependent on the web server. They are intrinsically linked. If one goes down, so does the other. A PHP CGI binary is separate program entirely that runs under a different user than the web server. If something goes wrong with PHP, Apache is generally unaffected.

The primary benefit of PHP as a module is speed. When the web server loads, all of the PHP settings and configurations are loaded with it. They stay resident in the memory as long as Apache is resident and running. The drawback is the decreased security of having PHP code run by the Apache user and the fact that any changes to configuration files require an Apache restart. The advantage of PHP as CGI is the stability and security of an independent user running PHP. One of the drawbacks is that it has execute PHP for each instance of a script, which can take a heavier toll on the CPU and create a larger number of processes.

Both methods have benefits and drawbacks, and it is up to the server administrator to decide which is the best for a given situation. Once a policy is set, it is not a good idea to change it, because such a major reconfiguration could adversely affect running scripts and applications. Decide what the best course is for you and stick to it.

Continue reading: PHP module vs PHP CGI binary

....
share this 0 comments

System monitoring with phpSysInfo

By Tavis J. Hampton in: Web servers Software

phpSysInfo screenshot

Sometimes you just need quick information about your server without having to click through numerous control panel screens or logging via SSH. A small PHP software application, called phpSysInfo, allows you to do just that. Installed like a normal PHP script, you can access a plethora of information about your server, including:

Hostname, Listening IP, Kernel version, Distribution name, Uptime, Current number of users, Load averages, Processors, Devices, Memory, Filesystems, Network usage, and Information about running processes. All of this is presented in a user-friendly graphical format that has a changeable theme.

phpSysInfo is available for Linux, BSD, Winows, OS X, and all UNIX-like operating systems. It is completely web-based and is free software, releated under the GNU GPL. You can download it from sourceforge.net free of charge.

Continue reading: System monitoring with phpSysInfo

....
share this 0 comments

Gain access to cPanel from anywhere with JAP

By Tavis J. Hampton in: Web Hosting Web servers Software

cpanel screenshot

Many people who manage websites also have other jobs, and even those who do not frequently find themselves traveling and away from the comfort of their own home Internet connection. In such situations, users sometimes find themselves behind firewalls that prevent them from accessing certain services, including web hosting control panels like cPanel.

The reason for the restriction is usually not to prevent people from specifically accessing cPanel but rather just a general blocking of any “unnecessary” ports by the network’s firewall. JAP4CPANEL (or simply JAP) allows you to access cPanel, WebHostManager, and webmail all through port 80, acting as a proxy between your network and your server.

With JAP, you will be able to access cPanel no matter where you are. It is available for PHP4 and PHP5 and also requires cURL, which is installed on most active web servers. JAP is free and open source software, released under the LGPL.

Source: webhostingtalk.com
Photo: Flickr

Continue reading: Gain access to cPanel from anywhere with JAP

....
share this 0 comments
Network Blogo