# Magento setup

**URL:** <https://www.ruby-forum.com/t/magento-setup/193023>\
**Category:** NGINX\
**Created:** [August 10, 2010, 4:30am UTC](https://www.ruby-forum.com/t/magento-setup/193023 "2010-08-10T04:30:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablo\_platt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@pablo\_platt](https://www.ruby-forum.com/u/pablo_platt)\
**Post date:** [August 10, 2010, 4:30am UTC](https://www.ruby-forum.com/t/magento-setup/193023/1 "2010-08-10T04:30:04Z")

</div>

Hi,

Anyone can share a working magento setup?  
I’ve read that nginx outperforms apache but couldn’t find a clear  
instructions how to setup on ubuntu:  
nginx + config file  
fcgi + spawn-fcgi + upstart script  
php-fpm

Thanks

---

<div class="post-metadata">

**Author:** ![pablo\_platt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@pablo\_platt](https://www.ruby-forum.com/u/pablo_platt)\
**Post date:** [August 10, 2010, 4:47am UTC](https://www.ruby-forum.com/t/magento-setup/193023/2 "2010-08-10T04:47:38Z")

</div>

Hey Pablo,

I’ve got instructions for CentOS - installation and configuration.  
It’s late for me here and I just finished helping host a birthday  
party, but I will post it for you tomorrow.

Raina

---

<div class="post-metadata">

**Author:** ![pablo\_platt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@pablo\_platt](https://www.ruby-forum.com/u/pablo_platt)\
**Post date:** [August 11, 2010, 7:41pm UTC](https://www.ruby-forum.com/t/magento-setup/193023/3 "2010-08-11T19:41:45Z")

</div>

Thank you very much for the detailed instructions.  
I’ll try it and report the results.

---

<div class="post-metadata">

**Author:** ![pablo\_platt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@pablo\_platt](https://www.ruby-forum.com/u/pablo_platt)\
**Post date:** [August 20, 2010, 5:34am UTC](https://www.ruby-forum.com/t/magento-setup/193023/4 "2010-08-20T05:34:49Z")

</div>

Is nginx going to be faster than apache on a dev server with ~2 users  
or am I going to see a difference only when having large number of  
concurrent users?

---

<div class="post-metadata">

**Author:** ![pablo\_platt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/d6d6ee/32.png) [@pablo\_platt](https://www.ruby-forum.com/u/pablo_platt)\
**Post date:** [August 11, 2010, 5:37am UTC](https://www.ruby-forum.com/t/magento-setup/193023/5 "2010-08-11T05:37:34Z")

</div>

Hi Pablo,

Ok. Here are notes/commands that worked successfully for me when  
installing PHP-FPM, Nginx and Magento on a Media Temple (ve) loaded  
with CentOS. My notes are a little messy. Let me know if you get stuck  
with anything, though if the process is significantly different for  
Ubuntu I might not be able to help. I’ve also pasted my config files  
below.

INSTALL DEPENDENCIES  
yum install -y curl-devel gcc GeoIP\* httpd-devel libevent  
libevent-devel libjpeg-devel libmcrypt-devel libpng-devel  
libtool-ltdl-devel libxml2 libxml2-devel mysql mysql-devel  
mysql-server openssl-devel patch pcre-devel php-gd php-mcrypt  
php-mysql php-pdo php-xml spawn-fcgi xmlrpc zlib-devel

yum install php\* ???

DOWNLOAD OWN LIBEVENT RATHER THAN YUM  
[http://forum.nginx.org/read.php?3,30050](http://forum.nginx.org/read.php?3,30050)  
 → mkdir /opt/libevent  
 → cd /opt/libevent  
 → wget [http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz](http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz)  
 → tar xvf libevent…

PHP: COMPILE AND INSTALL FIRST

# this was the most helpful

[http://interfacelab.com/nginx-php-fpm-apc-awesome/](http://interfacelab.com/nginx-php-fpm-apc-awesome/)

# helpful but failed

> **[How to install PHP-fpm + Nginx on CentOS 5.3](https://adityo.blog.binusian.org/?p=428)**

# didn’t use these but they look good

[http://www.newmediaist.com/n/installing-nginx-mysql-php-fpm-xcache-centos-53-howto](http://www.newmediaist.com/n/installing-nginx-mysql-php-fpm-xcache-centos-53-howto)  
[http://www.linode.com/forums/viewtopic.php?p=26342](http://www.linode.com/forums/viewtopic.php?p=26342)

./configure --enable-fpm --enable-inline-optimization --enable-pdo  
–enable-soap --enable-sockets --enable-zip --with-curl --with-gd  
–with-jpeg-dir --with-libdir=lib64 --with-mcrypt --with-mhash  
–with-mysql --with-mysqli=mysqlnd --with-openssl --with-pear  
–with-pdo-mysql=mysqlnd --with-zend-vm=GOTO --with-zlib

make  
make test  
make install

Wrote PEAR system config file at: /usr/local/etc/pear.conf  
You may want to add: /usr/local/lib/php to your php.ini include\_path  
/usr/local/src/php-5.3.3/build/shtool install -c ext/phar/phar.phar  
/usr/local/bin  
ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar  
Installing PDO headers: /usr/local/include/php/ext/pdo/

#strip /usr/local/bin/php-cgi

PHP: CONFIG  
/usr/local/etc/php-fpm.conf

INSTALLING NGINX  
wget [http://sysoev.ru/nginx/nginx-0.7.67.tar.gz](http://sysoev.ru/nginx/nginx-0.7.67.tar.gz)  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/NginxInstallOptions)

./configure   
–prefix=/   
–sbin-path=/usr/sbin/nginx   
–conf-path=/etc/nginx/nginx.conf   
–error-log-path=/var/log/nginx/error.log   
–pid-path=/var/run/nginx/nginx.pid   
–lock-path=/var/lock/nginx.lock   
–with-http\_geoip\_module   
–without-http\_autoindex\_module   
–with-http\_stub\_status\_module   
–user=nginx   
–group=nginx   
–with-http\_ssl\_module   
–with-http\_flv\_module   
–with-http\_gzip\_static\_module   
–http-log-path=/var/log/nginx/access.log   
–http-client-body-temp-path=/var/tmp/nginx/client/   
–http-proxy-temp-path=/var/tmp/nginx/proxy/   
–http-fastcgi-temp-path=/var/tmp/nginx/fcgi/

make && make install

NGINX SYMLINK (USUALLY CREATED AUTOMATICALLY ON INSTALL)  
ln -s /usr/local/nginx/conf /etc/nginx  
OR MOVE LOCATION  
cd /usr/local/src/nginx…  
cp -a nginx-0.7.67 ../nginx

#be sure to set the correct paths  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

TO START WEBSERVER  
uncomment ‘nobody’ in /etc/nginx/nginx.conf  
create init:

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

/etc/init.d/nginx

TODO  
#integrate apc  
[http://www.chilipepperdesign.com/2009/12/18/configuring-and-compiling-nginx-and-php-fpm-on-ubuntu-for-magento-part-2](http://www.chilipepperdesign.com/2009/12/18/configuring-and-compiling-nginx-and-php-fpm-on-ubuntu-for-magento-part-2)  
#get ssl working  
#add these to server boot  
/etc/init.d/php\_cgi start  
mysql  
service mysqld start  
review php and nginx configuration options

INSTALL MYSQL  
5.0.77 Source distribution

> **[MySQL :: installing with yum](https://forums.mysql.com/read.php?11,153632)**

chgrp -R mysql /var/lib/mysql  
chmod -R 770 /var/lib/mysql  
chkconfig mysqld on && service mysqld restart && chkconfig --list | grep  
mysqld  
service mysqld start  
/usr/bin/mysqladmin -u root password ‘password’

TROUBLESHOOTING  
one ve2, had to use 127.0.0.1 instead of localhost, had to skip base  
url validation, and had to change root password as follows:

update user set Password=PASSWORD(‘password’) where user=‘user’;  
or  
set Password=PASSWORD(‘password’) where user=‘user’;  
flush privileges;  
exit;

INSTALL PEAR & APC  
[http://www.webtatic.com/blog/2009/06/php-530-on-centos-5/](http://www.webtatic.com/blog/2009/06/php-530-on-centos-5/)  
#didn’t work#  
#yum install nfs-utils  
#/sbin/service portmap start  
#/sbin/service nfslock start  
#/sbin/service nfs start  
##mount nfs -t /dev/simfs -o remount,exec /tmp  
##mount nfs -o remount,exec /tmp  
##/dev/simfs on /tmp type simfs (rw,noexec)  
##pecl install apc

> **[PHP: Compiling shared PECL extensions with phpize - Manual](https://www.php.net/manual/en/install.pecl.phpize.php)**
>
> Compiling shared PECL extensions with phpize

#WORKS  
yum install autoconf

> **[ConstantShift.com is For Sale | BrandBucket](https://www.brandbucket.com/names/constantshift)**
>
> Buy the domain name ConstantShift.com and launch your business with a premium domain and a high quality logo.

$ cd /usr/local/src  
$ wget [http://pecl.php.net/get/APC-3.1.3p1.tgz](http://pecl.php.net/get/APC-3.1.3p1.tgz)  
$ tar xzvf APC-3.1.3p1.tgz  
$ cd APC-3.1.3p1  
$ phpize  
$ ./configure --enable-apc --enable-mmap  
$ make  
$ make install  
$ cp /usr/local/src/APC-3.1.3p1/modules/apc.so  
/usr/local/lib/php/extensions/no-debug-non-zts-20090626/

### ADD TO PHP.INI

extension = apc.so  
apc.enabled=1  
apc.shm\_size=30  
/etc/init.d/nginx restart && /etc/init.d/php-fpm restart  
cp apc.php /var/www/html/

INSTALL FASTCGI

> **[How to install PHP-fpm + Nginx on CentOS 5.3](https://adityo.blog.binusian.org/?p=428)**

- change to --with-mysql=/usr/bin/mysql

MAGENTO  
use magento check file

> **[Adobe Commerce Documentation](https://experienceleague.adobe.com/en/docs/commerce)**
>
> Search for self-help articles and tutorials on Adobe Commerce. Learn strategies and best practices from experts in live and on-demand video events.

raised php.ini memory/timeout

### END OF NOTES, START FILES###

### /etc/nginx/nginx.conf

user nobody;  
worker\_processes 4;  
error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local] 

```

“$request “’  
'$status $body\_bytes\_sent “$http\_referer” ’  
'”$http\_user\_agent” “$http\_x\_forwarded\_for”';  
access\_log /var/log/nginx/access.log main;

```
sendfile on;
map $scheme $fastcgi_https { ## Detect when HTTPS is used
    default off;
    https on;
}

```

client\_body\_timeout 5;  
client\_header\_timeout 5;  
keepalive\_timeout 5 5;  
send\_timeout 5;

```
gzip on;
gzip_comp_level 2;
gzip_proxied any;

```

gzip\_static on;  
gzip\_buffers 16 8k;  
gzip\_http\_version 1.0;  
gzip\_min\_length 0;  
gzip\_vary on;  
gzip\_types text/plain text/css application/x-javascript  
text/xml application/xml application/xml+rss text/javascript;

```
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;

```

}

### /etc/nginx/conf.d/domain.conf

server {  
listen 80;  
server\_name [domain.com](http://domain.com);

root /var/www/html;

```
location / {
    index index.html index.php; ## Allow a static html file to be

```

shown first  
try\_files $uri $uri/ @handler; ## If missing pass the URI to  
Magento’s front handler  
expires max; ## Assume all files are cachable  
error\_page 404 = @handler;  
log\_not\_found off;  
}

```
location ~ /(.*)/index\.php$ { ## strip index.php from product urls
  if (!-e $request_filename) { rewrite ^(.*)/index\.php$ $1/ 

```

permanent; }  
}

```
location /minify/ { ## Needed for Fooman Speedster
    rewrite ^/minify/([0-9]+)(/.*\.(js|css))$

```

/lib/minify/m.php?f=$2&d=$1 last;  
}

```
## These locations would be hidden by .htaccess normally
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /lib/minify/ { allow all; } ## Deny is applied

```

after rewrites so must specifically allow minify  
location /media/downloadable/ { deny all; }  
location /pkginfo/ { deny all; }  
location /report/config.xml { deny all; }  
location /var/ { deny all; }

```
location /var/export/ { ## Allow admins only to view export folder
    auth_basic "Restricted"; ## Message shown in login 

```

window  
auth\_basic\_user\_file htpasswd; ## See /etc/nginx/htpassword  
}

```
location /. { ## Disable .htaccess and other hidden files
    return 404;
}

location @handler { ## Magento uses a common front handler
    rewrite / /index.php;
}

location ~ \.php/ { ## Forward paths like /js/index.php/x.js to

```

relevant handler  
rewrite ^(.\*.php)/ $1 last;  
}

```
location ~ \.php$ { ## Execute PHP scripts
    expires off; ## Do not cache dynamic content
    fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param SCRIPT_FILENAME 

```

$document\_root$fastcgi\_script\_name;  
fastcgi\_param PATH\_INFO $fastcgi\_script\_name;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param MAGE\_RUN\_CODE base;  
fastcgi\_param MAGE\_RUN\_TYPE website;  
include fastcgi\_params; ## See /etc/nginx/fastcgi\_params  
}

}

### END

This is not necessarily the most optimal or logical configuration, but  
it works for me. It could probably be simplified, though you’ll also  
likely want to at least add a server configuration for SSL.

Hope that helps! Let me know how it goes for you.

Best,  
Raina
