Mini Servers: Apache 2.2.9 PHP 5.2.6 Service: Difference between revisions
m (→Download) |
m (Text replace - "projects/uniformserver" to "projects/miniserver") |
(One intermediate revision by the same user not shown) | |
(No difference)
|
Latest revision as of 16:11, 17 October 2012
Mini Servers: Introduction | Support | Server 1 - Portable | Server 2 - Service | Server 3 - Portable Authentication | Server 4 - Portable Authen. SSL | Server 5 - SSL Standalone | Browsers dislike self-signed certificates | Server 6 - PHP 5.2.6 Portable | Server 7 - PHP 5.2.6 Service | Server 8 - MySQL Support | Guest Book | Server 9 - Perl 5.2.6 Portable | Server 10 - Perl 5.2.6 Service | Server 11 - MySQL 5.0.67 Portable | Server 12 - MySQL 5.0.67 Service | Server 13 - MySQL 4.1.22 Portable | Server 14 - MySQL 4.1.22 Service | phpMyAdmin - Mini support | MySQL - General problems |
Mini Servers: Compact but fully functional. |
Mini Server 7 running as a service
This page covers running our mini server (describe on the previous page) as a service, its big brother Uniform Server 3.5-Appolo automates this process. We are not going to take this easy option! Well you would never learn anything by doing that, the manual alternative although slightly more difficult provides an insight into Apache and Uniform Servers flexibility.
Note: Check support section for download details
Specification
The server has the following specification:
- Server shall run as a service
- Static HTML and Dynamic PHP pages shall be served.
- The server shall log all web requests.
- All unused modules shall be disabled.
The only difference in this specification server is no longer portable but run as a service. This means every time you restart your PC the Apache server will automatically start. The advantage of this, when running a server permanently connected to the Internet should a power interruption occur the server will automatically restart when power is restored. If other elements of the system have been set accordingly them your Internet presence will also be restored.
Security Issues
Security issues remain as explained on the previous two pages. I would like to stress this is about as best as it gets. If you take this and pop it on a Unix box you can harden the server a little more however they are also faced with the same issues.
Changes
Interestingly if you run the portable version of this sever on a dedicated disk the configuration file would remain unchanged. Use the two new batch files and you are ready to go.
However like many others I run this on C drive with loads of other software yep alarm bells security issue, I am neither complacent nor unaware of these issues, Apache is probably the most secure bit on kit I have on my PC. Anyway I digress; changes are all associated with paths more precisely relative and absolute.
Relative
In theory Apache is quite happy to use relative paths for example “/” refers to the top level of the current disk. Uniform Server and our portable mini server use this to great advantage by defining a dedicated virtual disk “w”. However when changing across disk space Windows gets uptight about relative paths unless you can explicitly define a disk.
Absolute
Windows likes pegs hammered into the ground so to speak, hence when running as a service specifying absolute paths is essential to keep both parties happy for example c:\mini_server_7, the drive must be specified and then any folders etc.
No need to ramble on, just remember absolute paths are the order of the day so lets roll up ours sleeves and look at some code hacking.
Configuring Apache
As mentioned above absolute paths are required in the configuration file. I have chosen to run the server on C drive from folder mini_server_1b you can use a different drive and or folder the choice is yours, just substitute accordingly. I have highlighted these absolute paths in bold interestingly these are the only changes required to our original configuration file.
Note: I have moved the server to port 8087 prevents clashing with other servers.
httpd.conf located in folder: C:\mini_server_7\usr\local\apache2\conf |
---|
# File name: http.conf |
# ================================================ |
# ======================================== |
# ======================================== |
# ======================================== <Directory "c:/mini_server_7/www"> |
# ======================================== |
# ======================================== |
Configuring PHP
As mentioned above absolute paths are required in the configuration files. I am running the server on C drive from folder mini_server_7 No changes other than paths are required I have highlighted these absolute paths in bold.
Line | php.ini located in folder: *\mini_server_2a\udrive\usr\local\php |
---|---|
131 | short_open_tag = On |
149 | output_buffering = Off |
212 | allow_call_time_pass_reference = On |
229 | safe_mode_include_dir = ".;c:/mini_server_7/usr/local/PHP/includes;c:/mini_server_7/usr/local/PHP/pear" |
297 | expose_php = Off |
355 | error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT |
407 | track_errors = On |
431 | error_log = logs/logs.log |
455 | variables_order = "EGPCS" |
492 | magic_quotes_gpc = On |
495 | magic_quotes_runtime = Off |
498 | magic_quotes_sybase = Off |
525 | include_path = ".;c:/mini_server_7/usr/local/PHP/includes;c:/mini_server_7/usr/local/PHP/pear" |
537 | user_dir = "c:/mini_server_7/www" |
541 | extension_dir = "c:/mini_server_7/usr/local/PHP/extensions" |
598 | upload_tmp_dir = c:/mini_server_7/tmp |
601 | upload_max_filesize = 10M |
757 | sendmail_from = me@localhost.com |
1045 | session.save_path = "c:/mini_server_7/tmp/" |
1332 | soap.wsdl_cache_dir="c:/mini_server_7/tmp" |
install.bat
Batch files to install and uninstall Apache as a service are not very complex; the trick is to supply all the right parameters as shown.
Install service employs a nice bit of defensive programming when run the first line checks Apache’s configuration file for errors. Errors are listed including line numbers once corrected rerun the batch file. The second line installs Apache as a service once installed the third line starts the service.
install.bat located in folder: C:\mini_server_7 |
---|
echo. c:\mini_server_7\usr\local\apache2\bin\Apache.exe -k install -n "mini_server_7" echo. net start mini_server_7 echo. echo To access server type http://localhost:8087 into your browser. echo. pause |
uninstall.bat
The uninstall batch file first stops the “mini_server_7” service and then proceeds to uninstall it.
uninstall.bat located in folder: C:\mini_server_7 |
---|
echo. net stop mini_server_7 echo. c:\mini_server_7\usr\local\apache2\bin\Apache.exe -k uninstall -n "mini_server_7" echo. echo Done pause |
Note 1: The service name mini_server_7 this along with a unique port number allows all mini servers to be run alongside each other.
Note 2: To avoid clashing with Uniform Server do not name the service Apache2.
Command Line
After installing the Apache service with the above batch file you can start and stop the "mini_server_7" service at anytime using a command line this saves uninstalling the service every time you want to stop the server:
- net stop mini_server_7
- net start mini_server_7
Support files
Each mini server is complete and zipped into a single self-extracting archive file.
Download
Download this server from SourceForge Project Page save the file mini_server_7.exe to drive C.
Note: Check out the mini server's support and download page detailing how to obtain full binaries for Apache and PHP.
Extract files
Double click on mini_server_7.exe, starts the extraction process. No need to change the folder destination, click extract, this creates a new folder mini_server_7 containing the following files and folders:
|
Test
Testing is straight forward.
- Install the server by double clicking on install.bat (Checks config file, installs service and runs it)
- Type http://localhost:8087/ into the browser address bar.
- An index page is displayed, check out the test site MPG1.
Note 1: The server automatically starts when your PC is restarted (that’s the reason for installing as a service.)
Note 2: Adding extra pages or changing your web site there is no need to either restart or uninstall the server.
Note 3: Stop the service before making changes to Apache's configuration file; restarting service guarantees new changes will be picked up.
Your web site
Open the folder www located in folder *mini_server_7\www delete everything in this folder and copy your site in to it.
Note: Make sure one of your pages in folder www is named index.html, index.htm or index.php, otherwise you will need to type a page name in every time to access your site.
e.g. http://localhost/somepage.html
Change drive letter and or folder
The server requires a fixed location currently: c:\mini_server_7
You can move the server to any drive and folder for example e:\my_server\mini_server_7
To do this you need to edit four files:
- install.bat
- uninstall.bat
- httpd.conf (located in folder C:\mini_server_7\usr\local\apache2\conf)
- php.ini (located in folder C:\mini_server_7\usr\local\php
Find all occurrences of c:\mini_server_7 and replace with e:\my_server\mini_server_7
Change server default port
- Open file: httpd.conf (Located in folder: C:\mini_server_7\usr\local\apache2\conf)
- Locate the lines:
Listen 8087
ServerName localhost:8087 - Change to:
Listen 8080
ServerName localhost:8080
This moves the server to the standard secondary web server port
Note: Type http://localhost:8080 into a browser to view the site.
If port already in use try any value above 2000
Multi Servers
You can run more than one copy of this server as a service.
To do this you need to:
- Create a new folder and copy the contents of folder mini_server_7 to it.
- Edit the files as for (Change drive letter and or folder)
- Change the port see above.
- Edit install.bat and uninstall.bat, change the service name from mini_server_7 to something unique e.g. mini_server_7x
Note: You can run the mini servers alongside Uniform Server 3.5-Apollo however you must start Uniform Server first.
Summary
That concludes server 2, I have shown how to run it either in a portable or service configuration. It is a very powerful mini server you can use for either testing or putting your web site on-line (production server). The Apache configuration file is clean allowing you to easily explore other Apache configurations. The PHP configuration file I decided not to reduce hence it looks more complex than it needed to be.
Apache with PHP makes for a very powerful dynamic page server, OK so you want access a MySQL server. On the next page I show how to enable Apache and PHP to do just that.
Ric |