Apache - SLES 10

In this Session I will explain how to setup and configure the Apache Web server in SLES 10. I will also explain what virtual hosts are and how you can create them in Apache.

So, first let's see how to enable Apache in SLES 10.1.

1. After you have a default installation of SLES the Apache web server is installed on your server, but it is not enabled by default. To enable the Apache web server, open YaST and go to Network Services. In the left panel you see "HTTP Server", click it to open the configuration screen.

A screen comes up to tell you there are some packages that need to be installed, click continue and the packages will be installed. When asked, insert the right installation Disks.. After these packages are installed, the HTTP Server Configuration screen comes up

2. In the Configuration screen you can configure the most important settings.

First of all, make sure to Enable the HTTP Services, don't forget it or your server will not work at all.

The second thing to configure is the ip address and the port number the HTTP Server will listen on. You can choose to select All Addresses but this is not very safe. Typically you should use a separate ip address for your web server. You can also choose the port number the server should listen on, the default port is 80.

If you have a private web server, you can choose a different port here. Tell only the people that use the server what the port is so you have a little security.

The second TAB contains all the modules installed that Apache can use.

For now, leave this as default and click the Default Host TAB.

In this TAB we have a lot of important setting we can do.

Lets start with the Document Root.

This is the directory where you put all of the web server files. Normally, this directory contains the index file for your website.

Then there is the Include path.

This is the path where the primary apache configuration file (/etc/appache2/httpd.conf) can call other configuration files from. So if you have other configuration files that also need to be loaded from within the httpd.conf file, you should place them in this directory.

Server Resolution.

For myself, I think this is a very cool option that Apache has. It listens to the IP Address you connect to and then knows what web site it should present to you.

This can be used when you would like to have more then one website reside on the same web server. Normally this can't be done or you should do something with the port numbers of these sites.

Now you can tell the Apache that you will host two websites on the server, and that you will connect to them with a separate IP Address.

Website One:

It has the ip address 10.10.10.1. The document root is /srv/www/htdocs/site1.

Website Two:

It has the ip address 10.10.10.2. The document root is /srv/www/htdocs/site2.

When you enter 10.10.10.1 in a browser it will show you website one, and when you enter 10.10.10.2 it will show you website two.

The last TAB will show you the Hosts or website that reside on the web server.

You can run more than one website on one web server. This is called Virtual Hosting. If you would like to host another site on the server, this is the place to configure it. I will come back to explain this option later.

Click Finish and the settings will be saved.

3. Now you have configured the basic settings for your http server. You will need to check if the services are running. To do this, open a terminal window and enter: rchttpd status

In my case you see the apache2 server is running.

The final thing to do is create an index file in the document root directory.

Create a new file called index.html in the /srv/www/htdocs/ directory. Open the file with vi and enter some text in it, save and close the file.

Now you are almost there, you only have to set the rights to the /srv/www/ directory so that other users may read the files.

4. To set the appropriate file rights open a terminal window.

Change the Directory to /srv and enter: chmod -R 755 www

The -R option will set the 755 rights to all the files and directories under the www directory.

Now it's time to test and see if the Web server is working.

5. Open a web browser and enter the ip address you configured.

Notice that the text you entered in the index file is displayed.

6. Now we will make a second web site to run on the same web server. This is called a virtual host.

In YaST open the HTTP Server configuration screen.

To create a second website on this server click the TAB Hosts.

The host in the list is the website we just created.

Before we click the ADD button to create a second host on this web server we first add a secondary ip address to the servers NIC.

Open YaST, Network Devices and click Network Card

Click Next

Click Edit to add a secondary ip-address to the Network card.

When you click Edit, the screen shown below comes up.

In here, click the Advance button and from the drop down button select Additional Address.

In the next screen click Add

In this window you can enter the secondary ip address for you network card. Click OK, OK and Next Next to save the settings.

Now go back to the HTTP Server Configuration screen in YaST. In the first TAB Make sure that the Listen IP is set to All Addresses

Now go to the Host TAB. Click Add.

Enter the Host name of the Virtual Web server. I entered: sles2

Give the Document root for the web server. In my case: /srv/www/htdocs/sles2/. In here I have created an index.html filee and entered the text: Dave Simons SLES2 in it.

Also enter an email address for the web server.

Enter the secondary ip address you created earlier (192.168.1.11) and select the last radio button.

Click Next, and in the following window click OK to save you settings.

Now you see that you have 2 Hosts.

Click Finish to save the settings.

Now its time to test your virtual host.

Open a web browser and enter the URL: HTTP:\\192.168.1.10.

This is the default web site that's created during the installation of the HTTP Server.

To test the virtual host we just created, we have to enter the secondary ip-address 192.168.1.11 in the URL of your web browser.

Now you see a different web site, this is the text I entered in the index.html file of the virtual host we created. The index.html file in residing in /srv/www/htdocs/sles2/

In my test lab I used ip addresses to test connectivity to the web server. You can also create a dns record to use you dns names in the browser.

In the above examples I created 2 web sites. One was the Default and the second was the virtual website. I created them with YaST.

There is also the option to configure your apache 2 server from the configuration files.

The most important is /etc/apache2/httpd.conf.

In this file there are a lot of includes, this means that it reads other configuration files.

One of the include statements is the Virtual host statement: Include /etc/apache2/vhosts.d/*.conf

It reads all the conf files in the Include /etc/apache2/vhosts.d/ directory. If you look in this directory you also see a file "YaST2_vhosts.conf". This is the file that contains the virtual hosts we created in YaST.

There is also a file called /etc/srv/www/htdocs/listen.conf.

In this file you can configure on what port the web server is listening for requests. As you all will know the default web server port is 80. Sometimes it can be very useful to choose a different port for your web site. Lets assume you have a site that's more private the a default web site. You can choose to change the port to a different value so it's harder to find for the basic users.

Finally, you can see if the web server is running and you can reload the web server.

To check if the server is running, open a terminal window as the user root and enter: rcapache2 status.

In the above screen you see the server is running.

To restart the apache web server you have 2 main commands: "rcapache2 restart" and "rcapache reload".

The first one will stop apache and restart it, no matter how many clients are using the web server.

The preferred way to restart the web server in a production environment is to use the second command. So if you have to reload the web server because you have done some changes in the configuration use "rcapache2 reload" This will not disconnect the uses that are currently connected.

The restart command.

The reload command:

You can see the difference in the terminal windows. The restart command will also restart the child processes of Apache.

So, I hope that this Session has given you some more detail in how you can configure and install Apache as a web server in SLES. Its really a great web server to use.

PHP 5 and MySQL

This guide is intended for beginners who wanted to install PHP 5 and MySQL Community version 5 and make it work with Apache 2.2 . Installation will be done locally, so that you can test web application such as Wordpress before going live. This is quite a long guide so prepare yourselves for a ride!

install-php-5-mysql-5-on-apache-2.2-windows

Prerequisites : You had already installed Apache 2.2 locally on Windows. If not, please read my previous Apache 2 installation guide and come back later to continue with this post.

Install PHP 5 on Windows

1- Download the latest Windows PHP Binaries (MSI file) from this page. I choose the eZNetworking mirror because it is the closest one to Malaysia. Choose a mirror that is nearer to your country for a faster file download. The latest PHP version that I downloaded is 5.2.4. Save the file to your Desktop.

php5-installer-file-download

2- Right click on the file and click “Install“.

3- Click “Next ” once the Welcome page is displayed.

welcome to php setup wizard to start

4- Select “I accept the license agreement” and click “Next “.

accept-php-license-agreement-to-install

5- Change your PHP installation path OR just accept the default path - C:\Program Files\PHP\ and click “Next “.

enter-default-path-to-install-php-5

6- On the Web Server Setup screen, select the Apache 2.2.x Module and click “Next “.

select-webserver-to-install-php-on-apache-2

7-On the Apache Configuration Directory screen, browse for the Apache configuration directory (conf) OR just enter C:\Program Files\Apache Software Foundation\Apache2.2\conf\ and click “Next ” to proceed with the installation.

select-apache-webserver-configuration-directory

8- For now, accept the default selection and click “Next”.

accept-default-php-5-components-to-install

9-Click “Install ” to install PHP 5 on Windows.

click-install-to-setup-php5-on-apache2

10- Click “Finish ” once completed. PHP 5 is successfully installed.

click-finish-to-finalize-php-5-installation

11- Start your Apache 2.2 server using the “Monitor Apache Servers” console (Start -> Apache HTTP Servers 2.2.4 -> Monitor Apache Servers ). You can see that PHP was successfully installed by checking the Apache status at the bottom of the console.

check-apache2-monitor-to-find-php-5-installed

Test your PHP 5 Installation

1- Open up your Windows Notepad. Type in ” inside the file. Save this file as “info.php” inside your Apache root directory, C:\Program Files\Apache Software Foundation\Apache2.2\htdocs .

php-info-to-test-php-configuration

info-php-file-on-apache-root-directory

2- Open up your web browser. In the address bar, type in your web server domain name plus info.php as the file name. Example: http://www.syahid.com/info.php . You should get a PHP configuration page just like the one below.

php-configuration-page

Congratulations! You have successfully installed and test PHP 5 on Windows!

Tell Apache 2.2.x to Support PHP Index File

What happens if you change your index.html (default web server homepage) to index.php and try to access your homepage? Apache will not recognize it and you won’t see anything displayed on the page. To make sure Apache recognizes index.php as a default homepage too, follow the instructions below.

1- Rename your index.html to index1.html and info.php to index.php (for testing purposes only!).

change-apache-config-to-support-index

2- Edit your Apache configuration file, C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf by opening it with Windows Notepad.

3- Find a line that starts with “DirectoryIndex index.html…“. Add index.php at the end of the line . Save the file and restart your Apache Server from the “Monitor Apache Servers” console.

add-index

4- Load your Internet browser again. Type in your web server address e.g http://www.syahid.com. You should get a page similar to the info.php page above. Index.php now is recognized as a default Apache homepage, just like your normal index.html page.

Install MySQL 5.0 Community Edition on Windows

1- Download MySQL 5.0 Community Edition to your Desktop from here. If you want to download from a different mirror, click here. Make sure you always download the “Complete package “. Current version during this post was written is 5.0.45.

2- Unzip mysql-5.0.45-win32.zip (the downloaded mysql file) to get Setup.exe. Double click Setup.exe to start installing MySQL. Click “Next ” when you are prompted as below.

welcome-to-mysql-community-5-setup

3- Select “Typical” for Setup Type and click “Next ” again.

select-mysql-typical-installation-type

4- Click “Install ” to proceed with the installation process.

click-install-button-to-install-mysql-5

5- The setup activity will show you some advertisement. Read it if you wish and click “Next “.

read-or-ignore-mysql-promotion

6- Tick “Configure the MySQL Server now” and click “Next ” two times.

configure-the-mysql-version-5-now

welcome-message-to-mysql-configuration-wizard

7- Click “Standard Configuration” to ease installation process and click “Next ” again.

select-standard-mysql-configuration

8- Tick “Install As Windows Service” to make MySQL auto-startup with Windows and “Include Bin Directory in Windows PATH ” to make MySQL system files automatically available for other application.

install-mysql-as-windows-service-and-add-to-PATH

9- Tick “Modify Security Settings” and enter a root (Administrator) password to secure your MySQL installation. Don’t skip this step! Click “Next ” again.

enter-root-password-for-mysql-administration-account

10- Click “Execute” to start the MySQL Configuration process. Once finished, click “Finish ” to end configuration.

click-execute-to-configure-mysql-5

click-finish-to-finalize-mysql-version-5-installation

11- Make sure MySQL runs automatically after installation. You can check the status from Administrative Tools Services snap in (Start -> Programs -> Administrative Tools -> Services ), also available via Control Panel.

check-mysql-running-from-services-administrative-tool

12- (OPTIONAL) Open your DOS command prompt (Run -> cud). Type in “net stat -na“. Check out ports opened by MySQL (3306) and Apache (80) . That means the services are up and running.

check-mysql-running-with-ports-cmd-command

13- (OPTIONAL) Run some of MySQL commands to further ensure that the installation is a success. Check out and follow the commands as pictured below. User account is root and password depends on what you have entered previously during your MySQL configuration.

test-to-access-the-mysql-database

14- IMPORTANT: Reboot your machine! This is to ensure all MySQL system files are rss-read by Windows as environment variables.

Configure PHP 5 to Work with MySQL with MySQL PHP Extension

Previously, we have installed PHP with minimal modules / extension. To add MySQL support to PHP, you need to change your PHP installation - by adding the MySQL extension on top of your PHP installation. Please make sure that your original PHP 5 MSI installer still remains at its original place .

1- Open the Add / Remove Programs console via Windows Control Panel. Find the PHP 5.x.x entry and click “Change “.

change-php-configurations-to-enable-mysql-extension

2- Click “Next ” once you are prompted the Welcome page.

change-php-configuration-welcome-page

3- Click the “Change ” button to proceed.

click-change-button-to-edit-php-5-configuration

4- Select Apache 2.2.x as shown in the picture below. Click “Next ” once again.

select-apache-2

5- Select your Apache configuration directory (conf) - the directory where your httpd.conf resides. Click “Next ” once done.

choose-apache-configuration-directory

choose-apache-configuration-directory-2

6- On the “Choose items to install” screen, click on the plus (+) icon next to Extensions to expand the list.

click-plus-button-to-expand-extensions-part

select-extensions-page-on-expandable-part

7- Select on the “X” next to “MySQL” and select “Entire feature will be installed on local hard drive”. Click “Next” again.

select-mysql-extension-to-install

8- Click the “Change” button to save all the PHP configuration changes.

click-change-button-to-install-php-extensions

9- Finally, restart your Apache 2.2 web server! You can check out that the MySQL extension support for PHP was successfully installed by checking out the info.php / index.php page that was created before.

mysql-extension-successfully-installed-for-apache-2

Congratulations! Give yourself a pat on the back to finally manage it here. Now you can run almost many web applications that depends on Apache 2.2, PHP 5 with MySQL 5 database support. If any of those app complain about any missing extensions, remember that you can always reconfigure PHP by following the steps above.

Whew! This is quite a long guide but I really hope that someone out there will benefit from it!

top