Apache Web Server with PHP on cloud

1-click AWS Deployment    1-click Azure Deployment 1-click Google Deployment

Overview

This version of Apache is latest GA release of the new generation 2.4.x branch of Apache HTTPD . The Apache HTTPD package contains an open-source HTTP server.

Apache 2.4.x is the most widely used web server software. Developed and maintained by Apache Software Foundation,
Apache 2.4.x is an open source software available for free. It runs on 67% of all web servers in the world. It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules. Most WordPress hosting providers use Apache as their web server software. However, WordPress can run on other web server software as well.

What is Apache?

Apache is a remarkable piece of application software.  It is the most widely used Web Server application in the world with more than 50% share in the commercial web server market. Apache is the most widely used Web Server application in Unix-like operating systems but can be used on almost all platforms such as Windows, OS X, OS/2, etc. The word, Apache, has been taken from the name of the Native American tribe ‘Apache’, famous for its skills in warfare and strategy making.

It is a modular, process-based web server application that creates a new thread with each simultaneous connection. It supports a number of features; many of them are compiled as separate modules and extend its core functionality, and can provide everything from server side programming language support to authentication mechanism. Virtual hosting is one such feature that allows a single Apache Web Server to serve a number of different websites.

How to install Apache

There are numerous ways of installing the package or application.  There are enlisted below –

  1. One of the features of this open source web application is that anyone can make installer as per their own environment.This has allowed various vendors like Debian, Red Hat, FreeBSD, Suse etc. to customize the file location and configuration of apache taking into account other installed applications and base OS.
  2. Apart from installing it from a vendor based installer, there is always the option of building and installing it from the source code. Installing Apache from source file is a platform independent & works for all OS.

The apache web server is a modular application where the administrator can choose the required functionality and install different modules as per his/her requirement.

All modules can be compiled as a Dynamic Shared Objects (DSO is an object file that could be shared by multiple apps while they are executing) that exists separately from the main apache file.  The DSO approach is highly recommended, it makes the task of adding/removing/updating modules from the servers configuration very simple.

Install Apache:Linux Platform

On Red Hat or rpm based systems

If you are using an rpm (RedHat Package Manager is a utility for installing application on Linux systems) based Linux distribution i.e. Red Hat, Fedora, CentOs, Suse, you can install this application by either vendor specific Package Manager or directly building the rpm file from the available source tarball.

You can install Apache via the default Package Manager available on all Red Hat based distributions like CentOs, Red Hat and Fedora.

[root@amsterdam ~]# yum install httpd

The apache source tarball could be converted into an rpm file using the following command.

[root@amsterdam ~]# rpmbuild -tb httpd-2.4.x.tar.bz2

It is mandatory to have -devel package installed on your server for creating .rpm file from source.

Once you convert the source file into an rpm installer, you could use the following command to install Apache.

[root@amsterdam ~]# rpm –ivh httpd-2.4.4-3.1.x86_64.rpm

After the installation the server does not start automatically, in order to start the service, you have to use any of the following command on Fedora, CentOs or Red Hat.

[root@amsterdam ~]# /usr/sbin/apachectl start [root@amsterdam ~]# service httpd start [root@amsterdam ~]# /etc/init.d/httpd start

Install Apache from Source

Installing apache from the source require the –devel package to be installed on your server. .You can find the latest available version of Apache, you can download it here .  Once you download the source file move it to the /usr/local/src folder.

[root@amserversterdam ~] cd /usr/local/src [root@amserversterdam ~] gzip -d httpd-2.2.26.tar.gz [root@amserversterdam ~] tar xvf httpd-2.2.26.tar [root@amserversterdam ~] httpd-2.2.26

In order to see all configuration option available for Apache, you can use ./configure –help option.  The most common configuration option is –prefix={install directory name}.

[root@amserversterdam ~]./configure –help [root@amserversterdam ~]./configure –prefix=/usr/local/apache –enable-so [root@amserversterdam ~] make [root@amserversterdam ~] make install

The above example shows the compilation of Apache within the /usr/local/apache directory with the DSO capability. The –enable-so option, can load required modules to apache at run time via the DSO mechanism rather than requiring a recompilation.

Once the installation completes, you can browse the web servers default page with your favorite browser.  If firewall is enabled on your server, you must have to make exception for port 80 on your OS firewall.  You can use the following command to open port 80.

iptables -I INPUT -p tcp –dport 80 -j ACCEPT

service iptables save

You can see the default Apache2 Welcome screen by browsing your server IP address.

Apache Tutorials for Beginners

What Apache needs to Run Php File?

Running Php files on Apache needs mod_php enabled on your server.  It allows Apache to interpret .Php files.  It has Php handlers that interpret the Php code in apache and send HTML to your web server.

 If mod_php is enabled on your server, you will have a file named php.conf in /etc/httpd/conf.d/ directory.  You can also check it with:

httpd -M | grep "php5_module"

The output will be similar to:

Apache Tutorials for Beginners

Php handlers in Apache

  • mod_php
  • CGI
  • FastCGI
  • suPHP

mod_phpis the oldest PHP handler, it makes PHP part of apache and does not call any external PHP process. This module is installed by default in every Linux distribution repository, so enabling/disabling this module is very easy.

If you are using FastCGI as your PHP handler, you can set multiple versions of PHP to be used by different accounts on your server.

FastCGI i.e. mod_fastcgi is an extension of mod_fcgid, where as mod_fcgid is a high performance alternative of CGI i.e. mod_cgi . It starts sufficient number of instances of CGI to handle concurrent web requests.  It also uses suexec to support different users with their own instances of PHP and improves web security. 

Running ruby files on Apache needs mod_ruby to be enabled.  Apache can also handle ruby files through FastCGI.  It is possible to use multiple version of ruby with the help of mod_fcgid i.e. FastCGI.

You can also install apache passenger and configure Apache to use it for serving ruby pages.

(Phusion Passenger also known as “passenger” is a free web server module that is designed to integrate with Apache and Nginx )

Steps to install mod_ruby on your server –

cd /tmp

wget http://www.modruby.net/archive/mod_ruby-1.2.6.tar.gz

tar zxvf mod_ruby-1.2.6.tar.gz

cd mod_ruby-1.2.6/                    

./configure.rb --with-apr-includes=/usr/include/apr-1

make

make install

 

PHP 5.6.x is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP 5.6.x is most commonly used PHP version and it comes tagged with some exclusive features and some backward incompatible changes for improvements.

PHP 7.1.x has introduced a new pseudo-type that is similar to callable. It can be used in parameter and return type. It accepts either, arrays or objects, that implement Traversable interface.

  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free. Download it from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side
  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data

With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP.

 

While Apache is a free and updated product, it doesn’t skimp on features. In fact, it’s one of the most feature-filled HTTP web servers available, which is another reason it’s so popular.

 

Modules are used to add more functions to the software; password authentication and digital certificates are supported; you can customize error messages; one Apache install can deliver multiple websites with its virtual hosting capabilities; proxy modules are available; it supports SSL and TLS, and GZIP compression to speed up web pages.

Configure your very first Production Web Sever

1.  In order to have a running production web server, you need a dedicated node (Physical/Virtual or cloud instance) running Linux/Unix, Windows, MacOS etc. 

2.  The Web Server must have a direct network connection and a staticIP address configured on it.

3.  It needs to have all the modules required for running web pages.  If a web server processes PHP pages, it needs to have PHP  module enabled.

Apache Tutorials for Beginners

  1. It also needs to have a good Antivirus application configured and running for securing the Web Server from Malware or Virus attacks.  You also need mechanism to update the configured antivirus/anti malware application on regular basis without any manual intervention in order to get maximum benefit from them.
  2. If you have hundreds of domains to be hosted on your web server, you must have to implement limitations on file system quota for each domain, number of databases each domain can create, number of email accounts per domain etc.
  3. If your web server has been setup for shared hosting services, users on your web server needs to be restricted. A shared hosting  user should have least user privilege so that he does not damage important files & break the entire server. Apache does not provide any such functionality and needs different third party applications, customization of OS to achieve this. 
  4. If you are adding a new domain on your web server, it needs editing hundreds of configuration file to enable all features for the added domain.
  5. If one of the hosted domains requires different PHP setting than rest of the domains, implementing this in core Apache web server is very complex and needs customization of your web server in great extent.
  6. A production web server needs a firewall to block unwanted traffic that could cause high load on your server.  Implementing IPTABLE rules with command line is very complex.  It needs expertise of core Linux/Unix environment to write effective firewall rules for blocking unwanted traffic.  IPTABLE is based on netfilter module; it is an OS level firewall that allows an administrator to create rules for incoming/outgoing traffic on the server.
  7. A production web server requires several different applications like EmailFTP for file upload, Domain Name System for parked domains.  Managing all these applications on a core Linux/Unix system requires expertise on the respective technologies.

So, one can say that managing a web server for multiple domains is very complex task and requires editing hundreds of configuration file, customizing each application to fulfill the desired result.  Troubleshooting any miss configuration will be very difficult for beginners.

Advantages of Apache Web server

• The source code of Apache is available for free to anyone and no license is required.

• It can be modified to adjust the code and also to fix errors.

• The ability to add more features and modules makes it a favorite among the techies.

• It is highly reliable and performs better.

• It can be installed easily.

• The changes made are recorded immediately, even without restarting the server.

• Apache can run on almost any operating systems like Windows, Linux etc.

• It is regularly maintained and updated.

• It is an effortless task to get help for Apache web servers, as its technical support is readily available on several websites all over the world.

• The documentation of Apache is quite useful and is very extensive.

• With Apache web server, multiple websites can be run from the same server. In other words, it can create virtual hosts on the same server.

• It is flexible.

Disadvantages of Apache Web Server

With the enormous possibilities an Apache web server can offer, there is very little that an Apache Web server cannot do. Yet it has a few disadvantages.

• One of the prominent features of Apache is its ability to modify its configuration. This, however, can cause a serious threat to the security, if not dealt properly

• While creating personalized protocol means new bugs will also be created. Thus need for debuggers arise.

• Requires a strict updating policy that needs to be done regularly without fail.

• Recognising and disabling unwanted services and modules. Leaving them on could cause serious threats.

• Apache is a process based server

Features

AWS

Azure

Google

Videos


 

Apache Web Server with PHP on cloud

Related Posts