Setup nginx, php-fpm 5.6, mariadb on CentOS 4

nginx-php-mariadb-centos_5Setting up a good performance PHP-Stack is not a trivial work. We will need to choose which software is necessary for the stack based on some specific needs. Today I will guide how to setup nginx php-fpm 5.6 mariadb on CentOS server.

Remove out-dated softwares

[bash]yum remove -y httpd
yum remove -y mysqld
yum remove -y php-common[/bash]

Setting up repos

For PHP5.6:

[bash]rpm -Uvh
rpm -Uvh[/bash]

Or we can add Epel repository (rpm -Uvh and install using remi and remi-php56 repos instead of the webtatic repo.

For Nginx (/etc/yum.repos.d/nginx.repo):

name=nginx repo

For MariaDB (/etc/yum.repos.d/MariaDB.repo): go to MariaDB repositories to choose appropriate repo. For example, for MariaDB 5.5 on CentOS 6 32-bit:

name = MariaDB
baseurl =

Install nginx, php-fpm 5.6, mariadb

[bash]yum install -y nginx
yum install -y php56w-fpm php56w-opcache php56w-mysqlnd php56w-mcrypt php56w-mbstring php56w-cli php56w-dom
yum install -y MariaDB-server MariaDB-client[/bash]

For installing using remi and remi-php56 repos, we will need to add repoforge repo (for libmcrypt) and install package without 56w (so it will be yum install -y php-fpm php-opcache php-mysqlnd php-mcrypt php-mbstring php-cli php-dom …) as above.


1. MariaDB

  • Start the service:

    [bash]service mysql start[/bash]

  • Change root password:

    [bash][root@web ~]# mysql -u root
    MariaDB [(none)]> UPDATE `mysql`.`user` SET `Password` = PASSWORD(‘YOUR-NEW-PASSWORD’) WHERE `User` = ‘root’;
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> exit[/bash]

  • If replication is needed, edit the /etc/my.cnf.d/server.cnf file. Parameter configuration is also needed to put here.


  • Change loglevel to error in /etc/php-fpm.conf.
  • Create the following folders for php-fpm to store session and also wsdlcache (can change in /etc/php-fpm.d/www.conf):

    [bash]mkdir /var/lib/php/session
    chown -R apache:apache /var/lib/php/session
    mkdir /var/lib/php/wsdlcache
    chown -R apache:apache /var/lib/php/wsdlcache[/bash]

  • Restart and enable service:

    [bash]service php-fpm restart
    chkconfig –add php-fpm
    chkconfig –levels 235 php-fpm on[/bash]

3. Nginx

  • Create a default configuration for php-fpm (/etc/nginx/php-fpm.conf):

    [bash]location ~ \.php {
    try_files $uri = 404;
    fastcgi_index index.php;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  • Create a server config file in /etc/nginx/conf.d/your-website.conf and include the above config file. Sample configuration:

    [bash]server {
    listen 80;

    root /home/yourdomain/public;
    index index.html index.htm index.php;


    access_log off;
    error_log /var/log/nginx/yourdomain.error.log error;

    charset utf-8;

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|css|zip|tgz|gz|rar|bz2|exe|pdf|doc|xls|ppt|txt|odt|ods|odp|odf|tar|bmp|rtf|js|mp3|avi|mpeg|flv|html|htm|mp4|woff|ttf|eot)$ {
    root /home/yourdomain/public;
    expires max;
    #try_files $uri @fallback;

    location / {
    try_files \$uri \$uri/ /index.php?$query_string;

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; }

    error_page 404 /index.php;

    #include hhvm.conf; # The HHVM Magic Here
    include php-fpm.conf;

    # Deny .htaccess file access
    location ~ /\.ht {
    deny all;

  • Restart service:

    [bash]service nginx restart
    chkconfig –add nginx
    chkconfig –levels 235 nginx on[/bash]

It’s all.


1. Mariadb-server is conflicted with mariadb-libs

In most case, the conflict will be with mariadb-libs. This package is required by postfix, so we can simply remove postfix and mariadb-libs before installing mariadb-server again.

About NhocConan

A super lazy guy who tries to write tech blog entries in English.He is lazy, so he can only write when he is in a good mood or when he is tired of coding.

Leave a comment

Your email address will not be published. Required fields are marked *

4 thoughts on “Setup nginx, php-fpm 5.6, mariadb on CentOS