Jason Whatson

  • Git hub
  • Twitter
  • Skype
  • Linkedin
  • Instagram
  • STAY CONNECTED

Software engineer - Web & Mobile development, cloud computing : Sydney, AU;
  • About me
  • My resume
  • Contact
  • My Blog
  • Quotes
  • My portfolio’s
    • Software portfolio
    • Graphics portfolio
    • Music production & recording

Installing NGINX + PHP 5.5 with opcache + MySql on CentOS 6 (LEMP)

  • Nov 26, 2013

    Ive been using CentOS since CentOS 4 and it is my Linux flavour of choice because a) its what I know, and b) it has compatibility with Red Hat Enterprise.

    So when I moved from AWS to Digital Ocean for this blog it was my go to choice.

    The following is a guide on installing the latest PHP stack backed by MySQL and Nginx (interfacing with PHP via FastCGI-Process-Manager (FPM)) on currently the latest version of CentOS, CentOS 6. WordPress will run nicely on top of this stack (incase you were wondering).

    All commands should be run as the root user. Replace vi in the commands with your editor of choice (vi, nano, emacs, other)

    Mysql

    First install mysql and mysql server

    1
    yum install mysql mysql-server

    Nginx

    Next install Nginx from their official repo.

    Create the following file

    1
    vi /etc/yum.repos.d/nginx.repo

    then put the following configuration within that file

    1
    2
    3
    4
    5
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1

    Now install nginx

    1
    yum install nginx

    Setting up a virtual domain in Nginx (replace ‘yourdomain.com’ with your actual domain)

    1
    vi /etc/nginx/conf.d/yourdomain.com.conf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    server {
        listen       80;
        server_name  yourdomain.com;
     
        #charset koi8-r;
        access_log  /var/log/nginx/yourdomain.com.access.log  main;
     
        location / {
            root   /usr/share/nginx/yourdomain.com;
            index  index.php index.html index.htm;
        }
     
        #error_page  404              /404.html;
     
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
     
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /usr/share/nginx/yourdomain.com;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
     
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

    PHP

    PHP is in Extra packages so we need to add these repositories

    1
    2
    3
    4
    5
    6
    7
    8
    9
    //32 bit system
     
    rpm -Uvh http://epel.blizoo.mk/epel/6/i386/epel-release-6-8.noarch.rpm
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
     
    //64 bit system
     
    rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

    Install, PHP 5.5, PHP-FPM and the new PHP 5.5 op-cache by Zend

    1
    yum --enablerepo=remi,remi-php55 install php-fpm php-mysql php-opcache php-common

    Changing the PHP FPM process’s to run under the user ‘nginx’.

    Open the following file

    1
    vi /etc/php-fpm.d/www.conf

    Then find the lines

    1
    2
    user = apache
    group = apache

    And change them to

    1
    2
    user = nginx
    group = nginx

    Set up a test php page

    1
    echo"<?php phpinfo();" > /usr/share/nginx/yourdomain.com/index.php

    Restarting the process’s and setting them to spawn at system boot

    Finishing up and testing

    1
    2
    3
    service mysqld restart;
    service nginx restart;
    service php-fpm restart;

    Enable the services on system startup

    1
    for s in nginx php-fpm mysqld; do chkconfig $s on; done

    Finally test to see if the setup is working..

    Add a line to your local computers hosts file

    1
    162.243.150.25 mindfsck.net

    Replacing the domain with youdomain.com and the IP with your CentOS machines IP address

    Next go to yourdomain.com in your browser and check for the following in the PHP config output


    Centos, PHP, Wordpress
Jason Whatson

Jason Whatson

Jason is a software developer from Sydney Australia who loves to write software to build great products and help businesses succeed with their goals. Jason is a aspiring entrepreneur who subscribes to the lean startup ideology.

6 Comments

  1. Mark Greenall

    −Reply
    January 10th, 2014

    This is a good article. As a follow up you should look at NGiNX security by compiling from source?

  2. Ankit

    −Reply
    February 28th, 2014

    Awseome tutorial. Helped me a lot with the installation.

    Thanks a ton Jason.

    • Jason Whatson

      Jason Whatson

      −Reply
      February 28th, 2014

      Your welcome Ankit 🙂

  3. Pranav

    −Reply
    June 24th, 2014

    Thanks Jason.
    It helped me setup my server.
    I read through a lot of tutorials, but nothing worked as great as yours.
    I have bookmarked it so I dont loose it.

    Have A Great Day.

  4. Performa Digital

    −Reply
    October 27th, 2014

    Great article for any web developer or server admin. Nginx is such a great platform for fast WordPress sites.

    Thanks very much.

  5. Kaden

    −Reply
    September 16th, 2015

    Is it me, or did you forget to enable opcache? From what I understand it is not enabled by default. There are additional parameters that need to be added to configure and enable it.

Leave A Reply

Leave a Reply Cancel reply

Recent Posts

  • Book Review: Unnatural Selection: Why the Geeks will Inherit the Earth – Mark Roeder
  • Incremental backups to Amazon S3 on CentOS using duplicity
  • An example of how Golang makes concurrent programming easy and awesome
  • Installing NGINX + PHP 5.5 with opcache + MySql on CentOS 6 (LEMP)
  • Basic software engineering principles – Don’t Repeat Yourself (DRY)

Recent Comments

  • Speakerzdn on Book Review: Unnatural Selection: Why the Geeks will Inherit the Earth – Mark Roeder
  • http://daftarnova88.info on Basic software engineering principles – Don’t Repeat Yourself (DRY)
  • Donald Webb on Golang vs JAVA vs PHP: Comparing productivity
  • Donald Webb on Golang vs JAVA vs PHP: Comparing productivity
  • Lensamovie on Basic software engineering principles – Don’t Repeat Yourself (DRY)

Archives

  • March 2014
  • February 2014
  • January 2014
  • November 2013
  • June 2013
  • April 2013
  • May 2010

Categories

  • Book Reviews
  • Programming
  • Software engineering
  • Web hosting

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

About me

I am a software developer from Sydney Australia who loves to write software to build great products and help businesses succeed with their goals.

I am an aspiring entrepreneur who subscribes to the lean startup ideology and creator of “positive affirmations”, a app for Android and iPhone.

Contact

Phone: 0439372293
Email: jason@mindfsck.net

Random Quote

The best way to predict the future is to invent it. — Alan Kay

© Copyright 2021 Jason Whatson. All Rights Reserved.