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

yum install mysql mysql-server 1 yum install mysql mysql-server

Nginx

Next install Nginx from their official repo.

Create the following file

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

then put the following configuration within that file

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

Now install nginx

yum install nginx 1 yum install nginx

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

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

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; } } 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

//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 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

yum --enablerepo=remi,remi-php55 install php-fpm php-mysql php-opcache php-common 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

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

Then find the lines

user = apache group = apache 1 2 user = apache group = apache

And change them to

user = nginx group = nginx 1 2 user = nginx group = nginx

Set up a test php page

echo"<?php phpinfo();" > /usr/share/nginx/yourdomain.com/index.php 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

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

Enable the services on system startup

for s in nginx php-fpm mysqld; do chkconfig $s on; done 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

162.243.150.25 mindfsck.net 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