Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Guide to installing Magento with nginx on CentOs plus performance notes
 
bansal
Jr. Member
 
Total Posts:  2
Joined:  2008-10-04
 

Hi after many hours of googling and trial and error I thought I’d post something on how to install Magento with nginx.  Note I’m a relative Linux noob and there are probably (ok almost definitely) things in here that need improving, but I think that at least this will be a good starting point that will save someone a lot of time to get started.  I currently have a Magento store running on a vps on slicehost, and although I’ve had no problem with them and performance has been adequate, I know it could be better, and I firmly believe that a slower site affects store conversion rates so I decided to go in search of an optimal solution to give me the best performance for my current store and others that I planning on opening down the road.  After doing some research I decided I wanted to go with nginx over apache.  However getting Magento running even on Apache with all the correct php extensions can be tough, nevermind with nginx for which there is very little documentation.  So here is my quick and dirty setup of Magento with nginx, cobbled together from various sources on the web and my own trial and error.  Hope you find it helpful, and please post any improvements that might benefit myself and others.

First we need to get a 5.2+ version of php & install apc:

wget -q -O - http://www.atomicorp.com/installers/atomic.sh | sh
yum -y update php
yum -y install php-pear
yum -y install php-devel
yum -y install httpd-devel
pecl install apc

do a php -v, and you should get that you now have php 5.2.9 installed.

Now create apc.ini with the following in /etc/php.d (or add to your existing php.ini)

extension = apc.so
apc.enabled = 1
apc.shm_size = 48
apc.include_once_override = 1
apc.mmap_file_mask = /tmp/apc.XXXXXX

Note I don’t know much about APC, so this may be tweaked, but again is a good starting point.

Now we need to install all the php extensions necessary to run Magento:

yum -y install php-mcrypt
yum -y install php-pdo
yum -y install php-xml
yum -y install php-gd
yum -y install php-mysql

Ok now php is ready for Magento, so let’s install Magento itself.  This will install Magento with the sample data.  Go to your html root directory and do the following:

wget http://www.magentocommerce.com/downloads/assets/1.2.1.2/magento-1.2.1.2.tar.gz
wget http://www.magentocommerce.com/downloads/assets/1.2.0/magento-sample-data-1.2.0.tar.gz
tar -zxvf magento-1.2.1.2.tar.gz
tar -zxvf magento-sample-data-1.2.0.tar.gz
mv magento-sample-data-1.2.0/media/* magento/media/
mv magento-sample-data-1.2.0/magento_sample_data_for_1.2.0.sql magento/data.sql
mv magento/* magento/.htaccess .
chmod o+w var var/.htaccess app/etc
chmod -R o+w media
mysql magento < data.sql (create database magento)
./pear mage-setup .
./pear install magento-core/Mage_All_Latest-stable
rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
rm -rf magento/ magento-sample-data-1.2.0/
rm -rf magento-1.2.1.2.tar.gz magento-sample-data-1.2.0.tar.gz data.sql

Ok, now we have Magento installed!  I recommend first testing under Apache before installing nginx.  So restart apache and server from your browser.  You should get the installation screen and wizard.  You can go ahead and complete the wizard so that you’ll be all set to try out the store with nginx.

Ok now let’s compile and run nginx:

cd /usr/src
wget http://sysoev.ru/nginx/nginx-0.6.35.tar.gz
tar xvzf nginx-0.6.35.tar.gz
wget http://downloads.sourceforge.net/pcre/pcre-7.8.tar.bz2?use_mirror=superb-west
tar xjvf pcre-7.8.tar.bz2
cd nginx-0.6.35
./configure --with-http_ssl_module --sbin-path=/usr/sbin --with-pcre=/usr/src/pcre-7.8
make
make install
cd ..
rm -f *.gz *.bz2

Now that we have nginx compiled and ready let’s compile and run spawn-fcgi:

wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2
tar -xvjf lighttpd-1.4.18.tar.bz2
cd lighttpd-1.4.18
./configure
make
cp src/spawn-fcgi /usr/bin/spawn-fcgi
cd ..
rm -rf lighttpd-1.4.18/
rm -f lighttpd-1.4.18.tar.bz2
/usr/bin/spawn-fcgi -f /usr/bin/php-cgi -a 127.0.0.1 -p 53217 -P /var/run/fastcgi-php.pid -u apache

Almost done, now we need to go to cd /usr/local/nginx/conf
and edit nginx.conf.  Go to the listener for port 80 and add the following:

location / {
root /var/www/html; # absolute path doc root
index index.php index.html index.htm;

# this serves static files that exist without running other rewrite tests
if (-f $request_filename) {
expires 30d;
break;
}

# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}

location ~ \.php$ {
fastcgi_pass localhost:53217; # port where FastCGI processes were spawned
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; # same path as above

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
bansal
Jr. Member
 
Total Posts:  2
Joined:  2008-10-04
 

Note I’m not an expert on nginx configuration, but again a good starting point.  Now you can stop apache and run nginx.  If you hit your server with your browser you should see the store with the demo products running properly.  Here are a couple of tweaks to implement:

set in /etc/my.cnf under mysqld:
query_cache_size=32M

and create tmpfs:

mount tmpfs /var/www/html/var/cache -t tmpfs -o size=64m

Also one other note, for SSL copy the same nginx.conf modifications for the listener for port 80 to port 443 but make sure you add the following:

fastcgi_param HTTPS on;

otherwise it won’t work properly.

Of course you will have to play around with these settings a bit based upon your system.  Tweaks are probably best covered elsewhere.  Anyway I hope this helps someone else get up and running with nginx and saves them the time I put into it smile.  Good luck…

 
Magento Community Magento Community
Magento Community
Magento Community
 
nickweisser
Sr. Member
 
Avatar
Total Posts:  218
Joined:  2007-09-03
Zurich, Switzerland
 

Thank you very much for posting this! Saved be a lot of time.

I installed on Debian Etch and your rewrite config for nginx saved my day

# this sends all non-existing file or directory requests to index.php
if (!-e $request_filename{
rewrite 
^(.+)$ /index.php?q=$1 last;
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Carumba
Jr. Member
 
Total Posts:  18
Joined:  2009-02-27
California
 

Actually, this is wrong.

You need to remove the ?q=$1 part.

Look at your search box. It’ll show whatever query string you have.

I also posted some results the other day.
http://tumblelog.jauderho.com/post/85252024/improving-magento-performance

 
Magento Community Magento Community
Magento Community
Magento Community
 
Invictus
Jr. Member
 
Total Posts:  2
Joined:  2008-09-01
Indonesia
 
Carumba - 13 March 2009 03:10 PM

Actually, this is wrong.

You need to remove the ?q=$1 part.

Look at your search box. It’ll show whatever query string you have.


I also posted some results the other day.
http://tumblelog.jauderho.com/post/85252024/improving-magento-performance

Worked very well.
Thanks for the advice.

 
Magento Community Magento Community
Magento Community
Magento Community
 
thaddeusmt
Member
 
Avatar
Total Posts:  33
Joined:  2009-02-02
Bozeman, MT
 

thanks for this thread! finally got me up and running on nginx.

anyone have any tips for getting Fooman Speedster working?

 
Magento Community Magento Community
Magento Community
Magento Community
 
joshgeake
Jr. Member
 
Total Posts:  11
Joined:  2011-05-12
 

Hmm, the above may not still be valid because of the PHP 5.2 requirements on Magento 1.6. See here http://www.geakeit.co.uk/installations/install-magento-1-6-on-centos.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
trailblazer
Jr. Member
 
Total Posts:  3
Joined:  2011-06-07
 

Thanks for your sharing, I have done as above, but it seems I always fail to visit my : domain.com/magento
If I copy all the subdirectory and files to domain/, no problem, but if on domain.com/magento/ , error appear!!

can anybody help me, thanks very very much!!

address bar :
http://domain.com/shop/index.php/install/
error:
file not found

below is my nginx.conf file:

server {
listen 80;
server_name domain.com;
root /home/www/wwwroot/domain;
index index.php index.html index.htm
location / {
if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php last;
}
try_files $uri $uri/ /index.php;
}
location ~ \\.php$ {

if (!-e $request_filename) {
rewrite ^ /index.php break;
}
#fastcgi_split_path_info ^(.+\\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fcgi.conf;
}
location /magento {
root /home/www/wwwroot/domain;
index index.php;
if (!-e $request_filename) {
rewrite ^ /index.php break;
}
#fastcgi_split_path_info ^(.+\\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fcgi.conf;
}
}#server end
}## http end

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagenX
Enthusiast
 
Total Posts:  791
Joined:  2008-05-26
Dublin
 

not sure if this config will work at all,
but simplify it to just 1(one) root location, and remove all extra.
install magento, then->
add all other stuff step by step, then you will make it work…

check your error.log, it shows you everything…

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
trailblazer
Jr. Member
 
Total Posts:  3
Joined:  2011-06-07
 

Thank you very much, dear powerdude.

I have solved above problem by updating my new nginx.conf file.

Now I successfully install Magento 1.7 and also successfully login to my admin platform.

Best Regards

 
Magento Community Magento Community
Magento Community
Magento Community
 
firefire123
Jr. Member
 
Total Posts:  24
Joined:  2011-11-09
 

creating a magento site via NGINX / mysql / putty / filezila - every step of the way
The secret is now out! Heres the step by step guide

You will need Filezilla & PuTTY
PuTTY found here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
I used the top one:
For windows on Intel x86
PuTTY putty.exe

once downloaded it open and press run
add your ip address and press open
add your root password and your in

I used filezilla for the main upload of files.

1) (uploaded via filezilla) created a folder in vhosts called default.co.uk - all magento files uploaded here - /var/www/vhosts

2) (uploaded via filezilla) created a conf file added to /etc/nginx/conf.d from another file on there (changing site names to default)

3) (uploaded via filezilla) Created a php-fpm conf file created from another file on there (changing site names to default) /ect/php-fpm.d called defaultcouk.conf

4) (in putty) restarted php-frm using following command: service restart php-fpm

5) (in putty) create user called default.co.uk using useradd using command: useradd --home-dir /var/www/vhosts/default.co.uk --no-create-home --shell /sbin/nologin default.co.uk

6) (in putty) change vhost ownership (because I created the confi files and folder containing the magento files before creating a user - their owner was down as \\\"root\\\" which is wrong. It needs to be i.e. default.co.uk
changed with command: chown -R default.co.uk:default.co.uk /var/www/vhosts/default.co.uk

7) (in putty) opened mysql:  command: mysql

8) (in putty) Created data base:
Command: create database typedatabasename;
should then get this message: Query OK, 1 row affected (0.16 sec) (means its worked)
Command: grant all privileges on typedatabasename.* to \\\’typeusername\\\’@\\\’localhost\\\’ identified by \\\"typepassword\\\";
Command in mysql: flush privileges;
followed by: exit;

9) on ssh (filezilla) go to : /var/www/vhosts/default.co.uk/app/etc config.xml - this holds the data base name, username and password which magento will read off - change and re upload

10) (in putty) restart web server with command: service nginx restart

see full post here including file contents http://nginxputtymagento.blogspot.co.uk/

This works!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top