{"id":185,"date":"2012-02-22T00:28:51","date_gmt":"2012-02-21T16:28:51","guid":{"rendered":"http:\/\/blog.yaojun.sg\/?p=185"},"modified":"2012-02-22T00:28:51","modified_gmt":"2012-02-21T16:28:51","slug":"installing-centos-6-lnmp","status":"publish","type":"post","link":"https:\/\/blog.yaojun.sg\/?p=185","title":{"rendered":"Installing Centos 6 &#8211; LNMP"},"content":{"rendered":"<p>I&#8217;ve decided to re-start blogging again! That is after 1 year of silence&#8230;<\/p>\n<p>Well, I guess it&#8217;s time to start a Tech blog on what I do as a techie and to document what&#8217;s necessary, as a reference for myself and others if they chance into the problem, let me start first by getting LNMP to work on CentOS6. LNMP is otherwise know as Linux Nginx MySQL and PHP.<\/p>\n<p>Installing CentOS6 is pretty straight forward. Pop the disc\/USB in, follow the instructions and voilla, you have a working machine. There are some variations also like installing using the network method, but I won&#8217;t cover that here.<\/p>\n<p>Nginx. Nginx is an awesome piece of web server. It&#8217;s lightweight and fast. Much lighter than the world famous Apache. Installing it in today&#8217;s context is rather easy. With the package already compiled for you.<\/p>\n<p>Firstly, you have to add the Nginx repo into your repo list. And CentOS uses yum. So, you have to create a &#8220;nginx.repo&#8221; in &#8220;\/etc\/yum.repo.\/&#8221; with this following code<\/p>\n<pre>[nginx]\nname=nginx repo\nbaseurl=http:\/\/nginx.org\/packages\/centos\/6\/$basearch\/\ngpgcheck=0\nenabled=1<\/pre>\n<p>After that, it&#8217;s just run<\/p>\n<pre>yum install nginx<\/pre>\n<p>And nginx will be installed. Next, Centos usually has iptables enabled, iptables is a firewall, so you&#8217;ll have to add in a rule to allow 80 (http) or 443 (https) into the Allow rules.<\/p>\n<pre>vim \/etc\/sysconfig\/iptables<\/pre>\n<pre>-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT\n-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT<\/pre>\n<pre>service nginx start<\/pre>\n<p>Then you restart iptables and http(s) should work.<\/p>\n<p>Then for nginx to load everytime the machine boots<\/p>\n<pre>chkconfig --level 345 nginx on<\/pre>\n<hr \/>\n<p>MySQL, the lovely database magic box. Installing a updated copy is not that straight forward as it seems. I have to add additional repos, in this case &#8220;remi&#8221;&#8216;s repo, set of repo maintained by this french guy. But you also have to get &#8220;epel&#8221; repo also. So here are the commands:<\/p>\n<pre>rpm -Uvh http:\/\/mirror.nus.edu.sg\/fedora\/epel\/6\/i386\/epel-release-6-5.noarch.rpm\nrpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm<\/pre>\n<p>Then you install MySQL as such<\/p>\n<pre>yum --enablerepo=remi install mysql mysql-server<\/pre>\n<p>After installing the binaries, you have to install the database<\/p>\n<pre>mysql_install_db --user=mysql<\/pre>\n<p>After which start MySQL<\/p>\n<pre>mysqld_safe &amp;<\/pre>\n<p>Change the default password using<\/p>\n<pre>mysql_secure_installation<\/pre>\n<p>verify that the change was correct by properly shutting down MySQL<\/p>\n<pre>mysqladmin shutdown -p<\/pre>\n<p>Similarly for load on reboot<\/p>\n<pre>chkconfig --levels 235 mysqld on<\/pre>\n<p>Note: unless necessary, remember to add additional firewall rule if you want your MySQL to be remotely\u00a0accessible. There are also some configuration changes to me made to make that work which I will not cover here.<\/p>\n<hr \/>\n<p>Now PHP. Pre-Hypertext Processor and my favourite language. We will still be using &#8220;remi&#8221; repo. So,<\/p>\n<pre>yum --enablerepo=remi install php php-fpm\nyum --enablerepo=remi install php-gd php-mysql php-mbstring php-xml php-mcrypt php-pecl-apc php-pecl-memcache php-xmlrpc<\/pre>\n<p>After installation<\/p>\n<pre>service php-fpm start<\/pre>\n<p>To check whether PHP is working, you have to configure some things.<\/p>\n<p>Firstly, edit nginx config file.<\/p>\n<pre>vim \/etc\/nginx\/conf.d\/default.conf<\/pre>\n<pre>location \/ {\n root \/usr\/share\/nginx\/html;\n index index.html index.htm <strong>index.php<\/strong>;\n }<\/pre>\n<p>Uncomment the php-pfm codes and input the root of the web file directory.<\/p>\n<pre>location ~ .php$ {\n root html;\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME <strong>\/usr\/share\/nginx\/html<\/strong>$fastcgi_script_name;\n include fastcgi_params;\n }<\/pre>\n<p>Reload nginx<\/p>\n<pre>service nginx reload<\/pre>\n<p>And create a test file at the document root<\/p>\n<pre>vim \/usr\/share\/nginx\/html\/info.php<\/pre>\n<p>Append the following<\/p>\n<pre>&lt;?php phpinfo(); ?&gt;<\/pre>\n<p>Go to the website<\/p>\n<pre>http:\/\/serverNameOrIPAddressHere\/info.php<\/pre>\n<p>And you should see information related to PHP.<\/p>\n<p>A\u00a0recommendation by me will be to move PHP-FPM from the TCP socket to the Unix socket and it can be done in such a manner.<\/p>\n<p>Firstly edit<\/p>\n<pre>vim \/etc\/php-fpm.d\/www.conf<\/pre>\n<p>comment\/delete and change the following lines to<\/p>\n<pre>;listen = 127.0.0.1:9000\nlisten = \/tmp\/php-fpm.sock<\/pre>\n<pre>;listen.allowed_clients = 127.0.0.1<\/pre>\n<p>Change your user and group to<\/p>\n<pre>user = nginx\ngroup = nginx<\/pre>\n<p>You can verify the changes using<\/p>\n<pre>netstat -l -n<\/pre>\n<p>Now if you reload your info.php() it will not work, you have to go and adjust the nginx server\u00a0configuration\u00a0file. Comment away the old TCP socket and replace with the Unix socket.<\/p>\n<pre>vim \/etc\/nginx\/conf.d\/default.conf<\/pre>\n<pre>location ~ .php$ {\n root html;\n<strong> #fastcgi_pass 127.0.0.1:9000;<\/strong>\n <strong>fastcgi_pass unix:\/tmp\/php-fpm.sock;<\/strong>\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \/usr\/share\/nginx\/html$fastcgi_script_name;\n include fastcgi_params;\n }<\/pre>\n<p>Restart nginx<\/p>\n<pre>service nginx restart<\/pre>\n<p>And reload your info.php test page to make sure that it&#8217;s running.<\/p>\n<p>To make sure php-fpm runs every time the machine boots<\/p>\n<pre>chkconfig --levels 235 php-fpm on<\/pre>\n<hr \/>\n<p>An there as you have it, a Linux Nginx MySQL PHP machine is ready for you to use, be it for WordPress, OwnCloud, phpMyAdmin or other PHP based software.<\/p>\n<p>Hope you had fun configuring it. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve decided to re-start blogging again! That is after 1 year of silence&#8230; Well, I guess it&#8217;s time to start a Tech blog on what I do as a techie and to document what&#8217;s necessary, as a reference for myself and others if they chance into the problem, let me start first by getting LNMP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[6,12,14,16,19,24],"class_list":["post-185","post","type-post","status-publish","format-standard","hentry","category-tech","tag-centos","tag-linux","tag-mysql","tag-nginx","tag-php","tag-unix-socket"],"_links":{"self":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=185"}],"version-history":[{"count":0,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/185\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}