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

Major Features of Apache Web Server

  • Apache server is an open source web server.
  • It can be installed on all operating systems like Linux, Windows, Unix, FreeBSD, Solaris, Mac OS X etc.
  • It is a powerful, flexible, HTTP/1.1 compliant web server.
  • This server is highly configurable and extensible with third party modules.
  • It provides complete source code and comes with an unrestricted license.
  • Apache supports some of the capabilities like CGI (Common Gateway Interface) and SSI (Server Side Includes), URL redirection, loading modules support, user authentication, proxy caching abilities etc.
  • Unix Threading :
    On Unix systems with POSIX threads support, Apache httpd can now run in a hybrid multiprocess, multithreaded mode. This improves scalability for many, but not all configurations.
    New Build System
    The build system has been rewritten from scratch to be based on autoconf and libtool. This makes Apache httpd’s configuration system more similar to that of other packages.
    Multiprotocol Support
    Apache HTTP Server now has some of the infrastructure in place to support serving multiple protocols. mod_echo has been written as an example.
    Better support for non-Unix platforms
    Apache HTTP Server 2.0 is faster and more stable on non-Unix platforms such as BeOS, OS/2, and Windows. With the introduction of platform-specific multi-processing modules (MPMs) and the Apache Portable Runtime (APR), these platforms are now implemented in their native API, avoiding the often buggy and poorly performing POSIX-emulation layers.
    New Apache httpd API
    The API for modules has changed significantly for 2.0. Many of the module-ordering/-priority problems from 1.3 should be gone. 2.0 does much of this automatically, and module ordering is now done per-hook to allow more flexibility. Also, new calls have been added that provide additional module capabilities without patching the core Apache HTTP Server.
    IPv6 Support
    On systems where IPv6 is supported by the underlying Apache Portable Runtime library, Apache httpd gets IPv6 listening sockets by default. Additionally, the ListenNameVirtualHost, and VirtualHost directives support IPv6 numeric address strings (e.g., “Listen [2001:db8::1]:8080“).
    Filtering
    Apache httpd modules may now be written as filters which act on the stream of content as it is delivered to or from the server. This allows, for example, the output of CGI scripts to be parsed for Server Side Include directives using the INCLUDES filter in mod_include. The module mod_ext_filter allows external programs to act as filters in much the same way that CGI programs can act as handlers.
    Multilanguage Error Responses
    Error response messages to the browser are now provided in several languages, using SSI documents. They may be customized by the administrator to achieve a consistent look and feel.
    Simplified configuration
    Many confusing directives have been simplified. The often confusing Port and BindAddress directives are gone; only the Listen directive is used for IP address binding; the ServerName directive specifies the server name and port number only for redirection and vhost recognition.
    Native Windows NT Unicode Support
    Apache httpd 2.0 on Windows NT now uses utf-8 for all filename encodings. These directly translate to the underlying Unicode file system, providing multilanguage support for all Windows NT-based installations, including Windows 2000 and Windows XP. This support does not extend to Windows 95, 98 or ME, which continue to use the machine’s local codepage for filesystem access.
    Regular Expression Library Updated
    Apache httpd 2.0 includes the Perl Compatible Regular Expression Library (PCRE). All regular expression evaluation now uses the more powerful Perl 5 syntax.
     
     

There are dozens of features added to PHP 7, the most significant ones are mentioned below

  • Improved performance − Having PHPNG code merged in PHP7, it is twice as fast as PHP 5.

  • Lower Memory Consumption − Optimized PHP 7 utilizes lesser resource.

  • Scalar type declarations − Now parameter and return types can be enforced.

  • Consistent 64-bit support − Consistent support for 64-bit architecture machines.

  • Improved Exception hierarchy − Exception hierarchy is improved.

  • Many fatal errors converted to Exceptions − Range of exceptions is increased covering many fatal error converted as exceptions.

  • Secure random number generator − Addition of new secure random number generator API.

  • Deprecated SAPIs and extensions removed − Various old and unsupported SAPIs and extensions are removed from the latest version.

  • The null coalescing operator (??) − New null coalescing operator added.

  • Return and Scalar Type Declarations − Support for return type and parameter type added.

  • Anonymous Classes − Support for anonymous added.

  • Zero cost asserts − Support for zero cost assert added.

PHP 7 uses new Zend Engine 3.0 to improve application performance almost twice and 50% better memory consumption than PHP 5.6. It allows to serve more concurrent users without requiring any additional hardware. PHP 7 is designed and refactored considering today’s workloads.

AWS

Installation Instructions For CentOS

Note: How to find PublicDNS in AWS

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to CentOS instance on AWS Cloud

1) Download Putty.

2) Connect to the virtual machine using SSH key Refer this link:

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Note: To get started follow the instructions in the file /etc/httpd/conf.d/welcome.conf
You may add your website content to the directory /var/www/html/ or set up custom path
Get PHP info with php -v and php -m

Azure

 

 

Installation Instructions For Ubuntu

Note : How to find PublicDNS in Azure

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to Ubuntu instance on Azure Cloud

1) Download Putty.

2) Connect to virtual machine using following SSH credentials :

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Username: Your chosen username when you created the machine ( For example:  Azureuser)
Password : Your Chosen Password when you created the machine ( How to reset the password if you do not remember)

Step 2) Application URL: Access the application via a browser at http:/PublicDNS/

Step 3)Other Information:
1. Default installation path: will be on your web root folder /var/www/html
2.Default ports:

  • Linux Machines:  SSH Port – 22
  • TCP : 8389


Note: Please allow 8983 port for remote access with http://<yourip>:8983

3. To access Webmin interface for management please follow this link
Configure custom inbound and outbound rules using this link

Installation Instructions For CentOS

Note : How to find PublicDNS in Azure

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to CentOS instance on Azure Cloud

1) Download Putty.

2) Connect to virtual machine using following SSH credentials :

  • Host name: PublicDNS  / IP of machine
  • Port : 22

Username: Your chosen username when you created the machine ( For example:  Azureuser)

Password : Your Chosen Password when you created the machine ( How to reset the password if you do not remember)

Step 2) Application URL: Access the application via a browser at “http:/PublicDNS”

Step 3) Other Information:
1. Default installation path: will be on your web root folder “/var/www/html/”
2.Default ports:

  • Linux Machines:  SSH Port – 22
  • TCP : 8389

Note: Please allow 8983 port for remote access with http://<yourip>:8983

3. To access Webmin interface for management please follow this link

Configure custom inbound and outbound rules using this link

Google

Installation Instructions For CentOS

Installation Instructions For CentOS

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to CentOS instance on Google Cloud

1) Download Putty.

2) Connect to virtual machine using following SSH credentials:

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Username: Your chosen username when you created the machine
Password : Your Chosen Password when you created the machine ( How to reset the password if you do not remember)

Step 2) Other Information:

1.Default ports:

  • Linux Machines:  SSH Port – 22

2. To access Webmin interface for management please follow this link

Videos

Apache Web Server



 

Apache Web Server with PHP on cloud

Related Posts