Introduction / Requirements
Before reading this, please remember that NginX and Apache are fundamentally different.
Therefore, not all functions can be emulated.
When converting, be prepared to lose :
- .htaccess
I didn't do this, but I believe it should be doable for anyone who has too much time.
To me, they are really useless as accessing a script in /docroot/1/2/3/4/5/6 will force the server to do 7 or 8 stat calls all the way upwards.
Nothing near efficient if you ask me.
- mod_rewrite
This should be more doable than .htaccess in terms of implementing, as NginX has a powerful rewrite module in place.
However, I don't like extra stuff done per access, so this isn't useful for me.
In turn, you will gain :
- The ability to handle sync-floods and thousands of concurrent connections
- Use FastCGI for each user, creating a secure environment.
- Set a limit of FastCGI processes per user.
- Use php_admin_value and php_admin_flag with FastCGI
- Drastic Speed Improvements!
==========================================================
How To Install
Part 1 : NginX
1. Visit their website at http://www.nginx.net/
2. On their homepage, download either the stable or developmental version.
*Note: I went for the developmental version, but it doesn't really matter.*
*The command below is valid as of time of posting, but will probably be outdated.
3. Execute :
4. Configure according to your preference. I chose this :
This ends the nginx install.
Part 2 : PHP
1. Prepare your configuration options. If PHP is already installed, create a phpinfo(); page and extract the configuration line.
2. Download the latest version of PHP, extract and enter that directory.
3. Execute
This ends the PHP install.
Part 3 : Spawn FCGI Script
We need to download LightTPD to get it's spawn-fcgi.
1. To get it, download it from http://www.lighttpd.net.
2. Download, extract, and then run :
3. Try running /usr/local/bin/spawn-fcgi. Make sure it exists and returns this :
4. You can remove the extracted folder. lighttpd has not been installed as make install was not executed.
Part 4 : Apache Parser
I've written a parser to parse Apache configuration (attached to this post).
1. Download the attachment, rename it nginx.php and place it in /etc/init.d/
2. Execute :
3. Use your favourite editor nano/pico/vi to open nginx.php.
4. At the top of the file, you should see :
Replace /usr/local/bin/php with wherever your PHP binary is.
Be careful NOT to remove the ending -n.
5. The top part of the file (after that first line) should look like :
Make sure the file paths are correct. For example, my PHP is located in /opt/php.
Yours probably isn't.
Some particularly important variables :
$nginx_init - Where the controllable nginx init script will be. Leaving as-is is probably fine.
$da_vhosts - This file must contain the list of includes of every user's httpd.conf
$tmp_folder - The temporary folder. Must be world writable.
$php_startport - The PHP FastCGI will bind to a port starting from this number.
6. Execute the php script was rewrite-init as the parameter.
Eg.
7. The init file will be written to wherever you specified it previously.
8. You can now run [init_file] start/stop/restart/reload/graceful/status.
Part 5 : DirectAdmin Touchup
1. Open /usr/local/directadmin/data/admin/services.status in a text editor.
2. Replace httpd=ON with nginx=ON.
3. Execute : (remember to replace INIT_FILE below with where your nginx init file is)
Part 6 : htscanner (Optional)
This module installs a PHP plugin to emulate Apache's scanning for PHP options.
1. Locate where your PHP Pecl is :
2. Using the full path of pecl found, execute :
Installation has completed from this point onwards.
Please reply to this post if you find any bugs.
ChangeLog
v0.90 - FastCGI accepts php_admin_value, etc. configuration and uses its own user.
v1.00 - First Public Release.
v1.01 - Introduced new tutorial - htscanner
Before reading this, please remember that NginX and Apache are fundamentally different.
Therefore, not all functions can be emulated.
When converting, be prepared to lose :
- .htaccess
I didn't do this, but I believe it should be doable for anyone who has too much time.
To me, they are really useless as accessing a script in /docroot/1/2/3/4/5/6 will force the server to do 7 or 8 stat calls all the way upwards.
Nothing near efficient if you ask me.
- mod_rewrite
This should be more doable than .htaccess in terms of implementing, as NginX has a powerful rewrite module in place.
However, I don't like extra stuff done per access, so this isn't useful for me.
In turn, you will gain :
- The ability to handle sync-floods and thousands of concurrent connections
- Use FastCGI for each user, creating a secure environment.
- Set a limit of FastCGI processes per user.
- Use php_admin_value and php_admin_flag with FastCGI
- Drastic Speed Improvements!
==========================================================
How To Install
Part 1 : NginX
1. Visit their website at http://www.nginx.net/
2. On their homepage, download either the stable or developmental version.
*Note: I went for the developmental version, but it doesn't really matter.*
*The command below is valid as of time of posting, but will probably be outdated.
3. Execute :
Code:
wget http://sysoev.ru/nginx/nginx-0.6.5.tar.gz
tar -xzf nginx-0.6.5.tar.gz
cd nginx-0.6.5
4. Configure according to your preference. I chose this :
Code:
./configure --with-http_stub_status_module --with-openssl=/usr/lib/openssl
make
make install
This ends the nginx install.
Part 2 : PHP
1. Prepare your configuration options. If PHP is already installed, create a phpinfo(); page and extract the configuration line.
2. Download the latest version of PHP, extract and enter that directory.
3. Execute
Code:
./configure --enable-fastcgi ... (Insert your configuration)
make
make install
This ends the PHP install.
Part 3 : Spawn FCGI Script
We need to download LightTPD to get it's spawn-fcgi.
1. To get it, download it from http://www.lighttpd.net.
2. Download, extract, and then run :
Code:
./configure
make
cd src
cp ./spawn-fcgi /usr/local/bin/spawn-fcgi
3. Try running /usr/local/bin/spawn-fcgi. Make sure it exists and returns this :
Code:
spawn-fcgi-1.4.15 - spawns fastcgi processes
4. You can remove the extracted folder. lighttpd has not been installed as make install was not executed.
Part 4 : Apache Parser
I've written a parser to parse Apache configuration (attached to this post).
1. Download the attachment, rename it nginx.php and place it in /etc/init.d/
2. Execute :
Code:
chmod 700 nginx.php
3. Use your favourite editor nano/pico/vi to open nginx.php.
4. At the top of the file, you should see :
Code:
#!/usr/local/bin/php -n
Replace /usr/local/bin/php with wherever your PHP binary is.
Be careful NOT to remove the ending -n.
5. The top part of the file (after that first line) should look like :
Code:
// Configuration Section
$nginx_init = "/etc/init.d/nginx";
$apache_config = "/etc/httpd/conf/httpd.conf";
$da_vhosts = "/etc/httpd/conf/extra/directadmin-vhosts.conf";
$tmp_folder = "/tmp/";
$debug_level = 0; // 0 => FATAL, 1 => WARN, 2 => INFO
$killall_bin = "/usr/bin/killall";
$spawn_bin = "/usr/local/bin/spawn-fcgi";
// Nginx Configuration
$nginx_config = "/usr/local/nginx/conf/nginx.conf";
$nginx_bin = "/usr/local/nginx/sbin/nginx";
$mod_status = true;
// PHP Configuration
$php_childs = 3;
$php_bin = "/opt/php/bin/php-cgi";
$php_startport = 11000;
Make sure the file paths are correct. For example, my PHP is located in /opt/php.
Yours probably isn't.
Some particularly important variables :
$nginx_init - Where the controllable nginx init script will be. Leaving as-is is probably fine.
$da_vhosts - This file must contain the list of includes of every user's httpd.conf
$tmp_folder - The temporary folder. Must be world writable.
$php_startport - The PHP FastCGI will bind to a port starting from this number.
6. Execute the php script was rewrite-init as the parameter.
Eg.
Code:
/etc/init.d/nginx.php rewrite-init
7. The init file will be written to wherever you specified it previously.
8. You can now run [init_file] start/stop/restart/reload/graceful/status.
Part 5 : DirectAdmin Touchup
1. Open /usr/local/directadmin/data/admin/services.status in a text editor.
2. Replace httpd=ON with nginx=ON.
3. Execute : (remember to replace INIT_FILE below with where your nginx init file is)
Code:
mv /etc/init.d/httpd /etc/init.d/httpd.old
ln -vs INIT_FILE /etc/init.d/httpd
Part 6 : htscanner (Optional)
This module installs a PHP plugin to emulate Apache's scanning for PHP options.
1. Locate where your PHP Pecl is :
Code:
locate pecl
2. Using the full path of pecl found, execute :
Code:
/location/to/pecl install htscanner
Installation has completed from this point onwards.
Please reply to this post if you find any bugs.
ChangeLog
v0.90 - FastCGI accepts php_admin_value, etc. configuration and uses its own user.
v1.00 - First Public Release.
v1.01 - Introduced new tutorial - htscanner
Attachments
Last edited: