{"id":235,"date":"2013-06-05T19:53:47","date_gmt":"2013-06-05T19:53:47","guid":{"rendered":"http:\/\/blog.shineservers.com\/?p=235"},"modified":"2013-06-05T19:53:47","modified_gmt":"2013-06-05T19:53:47","slug":"how-to-install-wordpress-with-nginx-on-centos-6","status":"publish","type":"post","link":"https:\/\/www.shineservers.com\/2013\/06\/05\/how-to-install-wordpress-with-nginx-on-centos-6\/","title":{"rendered":"How to Install WordPress With Nginx On CentOS 6"},"content":{"rendered":"<h1>Installing Linux, nginx, MySQL, PHP (LEMP) stack<\/h1>\n<p>LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.<\/p>\n<h2>Step One\u2014Install the Required Repositories<\/h2>\n<hr \/>\n<p>We will be installing all of the required software with Yum. However, because neither nginx nor php-fpm are available straight from CentOS, we need to download two extra repositories to our virtual private server first.<\/p>\n<pre>sudo rpm -Uvh http:\/\/download.fedoraproject.org\/pub\/epel\/6\/i386\/epel-release-6-8.noarch.rpm\nsudo rpm -Uvh http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm\n\n<img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/MOXpnT9.png\" width=\"986\" height=\"195\" \/><\/pre>\n<h2>Step Two\u2014Install MySQL<\/h2>\n<hr \/>\n<pre>The next step is to begin installing the server software on the virtual private server, starting with MySQL and dependancies.<\/pre>\n<pre>sudo yum install mysql mysql-server\n\n<img decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/AR7l4Rp.png\" width=\"1346\" height=\"309\" \/>\n\nOnce the download is complete, restart MySQL:<\/pre>\n<pre>sudo \/etc\/init.d\/mysqld restart\n\n<img decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/Om6b8oZ.png\" width=\"1180\" height=\"581\" \/>\n\nYou can do some configuration of MySQL with this command:<\/pre>\n<pre>sudo \/usr\/bin\/mysql_secure_installation<\/pre>\n<pre>The prompt will ask you for your current root password.\u00a0\n\nSince you just installed MySQL, you most likely won\u2019t have one, so leave it blank by pressing enter.<\/pre>\n<pre>Enter current password for root (enter for none): \nOK, successfully used password, moving on...<\/pre>\n<pre>Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.\u00a0\n\nCentOS automates the process of setting up MySQL, asking you a series of yes or no questions.\u00a0\n\nIt\u2019s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the changes.<\/pre>\n<pre>By default, a MySQL installation has an anonymous user, allowing anyone\nto log into MySQL without having to have a user account created for\nthem.  This is intended only for testing, and to make the installation\ngo a bit smoother.  You should remove them before moving into a\nproduction environment.\n\nRemove anonymous users? [Y\/n] y                                            \n ... Success!\n\nNormally, root should only be allowed to connect from 'localhost'.  This\nensures that someone cannot guess at the root password from the network.\n\nDisallow root login remotely? [Y\/n] y\n... Success!\n\nBy default, MySQL comes with a database named 'test' that anyone can\naccess.  This is also intended only for testing, and should be removed\nbefore moving into a production environment.\n\nRemove test database and access to it? [Y\/n] y\n - Dropping test database...\n ... Success!\n - Removing privileges on test database...\n ... Success!\n\nReloading the privilege tables will ensure that all changes made so far\nwill take effect immediately.\n\nReload privilege tables now? [Y\/n] y\n ... Success!\n\nCleaning up...\n\nAll done!  If you've completed all of the above steps, your MySQL\ninstallation should now be secure.\n\nThanks for using MySQL!<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/Aj8I9Zy.png\" width=\"633\" height=\"682\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/Vy4f8zG.png\" width=\"617\" height=\"459\" \/><\/p>\n<h2>Step Three\u2014Install nginx<\/h2>\n<hr \/>\n<p>As with MySQL, we will install nginx on our virtual private server using yum:<\/p>\n<pre>sudo yum install nginx\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/bStzyUi.png\" width=\"1340\" height=\"515\" \/>\n\nnginx does not start on its own. To get nginx running, type:<\/pre>\n<pre>sudo \/etc\/init.d\/nginx start\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/LWtH21B.png\" width=\"570\" height=\"53\" \/>\n\nYou can confirm that nginx has installed on your virtual private server by directing your browser to your IP address. You can run the following command to reveal your server\u2019s IP address.<\/pre>\n<pre>ifconfig eth0 | grep inet | awk '{ print $2 }'<\/pre>\n<h2>Step Four\u2014Install PHP<\/h2>\n<hr \/>\n<pre>The php-fpm package is located within the REMI repository, which, at this point, is disabled. The first thing we need to do is enable the REMI repository and install php and php-fpm:<\/pre>\n<pre>sudo yum --enablerepo=remi install php-fpm php-mysql\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/qOMWUGS.png\" width=\"1301\" height=\"185\" \/><\/pre>\n<h2>Step Five\u2014Configure php<\/h2>\n<hr \/>\n<p>We need to make one small change in the php configuration. Open up php.ini:<\/p>\n<pre> sudo vi \/etc\/php.ini<\/pre>\n<p>Find the line, cgi.fix_pathinfo=1, and change the 1 to 0.<\/p>\n<pre>cgi.fix_pathinfo=0<\/pre>\n<p>If this number is kept as a 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path\u2014a much safer alternative. Save and Exit.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/ZZQRwx2.png\" width=\"744\" height=\"147\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Step Six\u2014Configure nginx<\/h2>\n<hr \/>\n<p>Open up the default nginx config file:<\/p>\n<pre>sudo vi \/etc\/nginx\/nginx.conf<\/pre>\n<p>Raise the number of worker processes to 4 then save and exit that file.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/bQUD2Pi.png\" width=\"669\" height=\"309\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Now we should configure the nginx virtual hosts. In order to make the default nginx file more concise, the virtual host details are in a different location.<\/p>\n<pre>sudo vi \/etc\/nginx\/conf.d\/default.conf<\/pre>\n<p>The configuration should include the changes below (the details of the changes are under the config information):<\/p>\n<pre>#\n# The default server\n#\nserver {\n    listen       80;\n    server_name example.com;\n\n    location \/ {\n        root   \/usr\/share\/nginx\/html;\n        index index.php  index.html index.htm;\n    }\n\n    error_page  404              \/404.html;\n    location = \/404.html {\n        root   \/usr\/share\/nginx\/html;\n    }\n\n    error_page   500 502 503 504  \/50x.html;\n    location = \/50x.html {\n        root   \/usr\/share\/nginx\/html;\n    }\n\n    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n    #\n    location ~ \\.php$ {\n        root           \/usr\/share\/nginx\/html;\n        fastcgi_pass   127.0.0.1:9000;\n        fastcgi_index  index.php;\n        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;\n        include        fastcgi_params;\n    }\n}<\/pre>\n<p>Here are the details of the changes:<\/p>\n<ul>\n<li>Add index.php within the index line.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>Change the server_name to your domain name or IP address (replace the example.com in the configuration)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>Change the root to \/usr\/share\/nginx\/html;<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>Uncomment the section beginning with &#8220;location ~ \\.php$ {&#8220;,<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>Change the root to access the actual document root, \/usr\/share\/nginx\/html;<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul>\n<li>Change the fastcgi_param line to help the PHP interpreter find the PHP script that we stored in the document root home.<\/li>\n<\/ul>\n<p>Save and Exit<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/LN1PrHK.png\" width=\"705\" height=\"555\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/TIHrVk8.png\" width=\"674\" height=\"424\" \/><\/p>\n<p>Open up the php-fpm configuration:<\/p>\n<pre>sudo vi \/etc\/php-fpm.d\/www.conf<\/pre>\n<p>Replace the apache in the user and group with nginx:<\/p>\n<pre>[...]\n; Unix user\/group of processes\n; Note: The user is mandatory. If the group is not set, the default user's group\n;\twill be used.\n; RPM: apache Choosed to be able to access some dir as httpd\nuser = nginx\n; RPM: Keep a group allowed to write in log dir.\ngroup = nginx\n[...]\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/teaKgsF.png\" width=\"701\" height=\"124\" \/>\n\nFinish by restarting php-fpm.<\/pre>\n<pre>sudo service php-fpm restart\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/IBl5HxB.png\" width=\"600\" height=\"67\" \/><\/pre>\n<h2>Step Seven\u2014RESULTS: Create a php info page<\/h2>\n<hr \/>\n<pre>Although LEMP is installed, we can still take a look and see the components online by creating a quick php info page\n\nTo set this up, first create a new file:<\/pre>\n<pre>sudo vi \/usr\/share\/nginx\/html\/info.php<\/pre>\n<pre>Add in the following line:<\/pre>\n<pre>&lt;?php\nphpinfo();\n?&gt;<\/pre>\n<pre>Then Save and Exit.\u00a0\n\nRestart nginx so that all of the changes take effect:<\/pre>\n<pre>sudo service nginx restart\n\nFinish up by visiting your php info page (make sure you replace the example ip address with your correct one): \n<strong>http:\/\/IP\/info.php\n\n<\/strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/IT14JPj.png\" width=\"634\" height=\"661\" \/><\/pre>\n<h2>Step Eight\u2014Set Up Autostart<\/h2>\n<hr \/>\n<pre>You are almost done. The last step is to set all of the newly installed programs to automatically begin when the VPS boots.<\/pre>\n<pre>sudo chkconfig --levels 235 mysqld on\nsudo chkconfig --levels 235 nginx on\nsudo chkconfig --levels 235 php-fpm on\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/UMTnuOx.png\" width=\"541\" height=\"65\" \/><\/pre>\n<h3>About WordPress<\/h3>\n<hr \/>\n<pre>WordPress is a free and open source website and blogging tool that uses php and MySQL. It was created in 2003 and has since then expanded to manage 22% of all the new websites created and has over 20,000 plugins to customize its functionality.<\/pre>\n<h2>Step Nine\u2014Download WordPress<\/h2>\n<hr \/>\n<pre>We can download WordPress straight from their website:<\/pre>\n<pre>wget http:\/\/wordpress.org\/latest.tar.gz<\/pre>\n<pre>This command will download the zipped wordpress package straight to your user's home directory. You can unzip it the the next line:<\/pre>\n<pre>tar -xzvf latest.tar.gz<\/pre>\n<h2>Step Ten\u2014Create the WordPress Database and User<\/h2>\n<p>After we unzip the wordpress files, they will be in a directory called wordpress in the home directory.<\/p>\n<p>Now we need to switch gears for a moment and create a new MySQL directory for wordpress.<\/p>\n<p>Go ahead and log into the MySQL Shell:<\/p>\n<pre>mysql -u root -p<\/pre>\n<p>Login using your MySQL root password, and then we need to create a wordpress database, a user in that database, and give that user a new password. Keep in mind that all MySQL commands must end with semi-colon.<\/p>\n<p>First, let&#8217;s make the database (I&#8217;m calling mine wordpress for simplicity&#8217;s sake; feel free to give it whatever name you choose):<\/p>\n<pre>CREATE DATABASE wordpress;\nQuery OK, 1 row affected (0.00 sec)<\/pre>\n<p>Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:<\/p>\n<pre>CREATE USER wordpressuser@localhost;\nQuery OK, 0 rows affected (0.00 sec)<\/pre>\n<p>Set the password for your new user:<\/p>\n<pre>SET PASSWORD FOR wordpressuser@localhost= PASSWORD(\"password\");\nQuery OK, 0 rows affected (0.00 sec)<\/pre>\n<p>Finish up by granting all privileges to the new user. Without this command, the wordpress installer will not be able to start up:<\/p>\n<pre>GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';\nQuery OK, 0 rows affected (0.00 sec)<\/pre>\n<p>Then refresh MySQL:<\/p>\n<pre>FLUSH PRIVILEGES;\nQuery OK, 0 rows affected (0.00 sec)<\/pre>\n<p>Exit out of the MySQL shell:<\/p>\n<pre>exit\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/NvLjPmC.png\" width=\"863\" height=\"518\" \/><\/pre>\n<h2>Step Eleven\u2014Setup the WordPress Configuration<\/h2>\n<hr \/>\n<pre>The first step to is to copy the sample WordPress configuration file, located in the WordPress directory, into a new file which we will edit, creating a new usable WordPress config:<\/pre>\n<pre>cp ~\/wordpress\/wp-config-sample.php ~\/wordpress\/wp-config.php<\/pre>\n<pre>Then open the wordpress config:<\/pre>\n<pre>sudo nano ~\/wordpress\/wp-config.php<\/pre>\n<pre>Find the section that contains the field below and substitute in the correct name for your database, username, and password:<\/pre>\n<pre>\/\/ ** MySQL settings - You can get this info from your web host ** \/\/\n\/** The name of the database for WordPress *\/\ndefine('DB_NAME', 'wordpress');\n\n\/** MySQL database username *\/\ndefine('DB_USER', 'wordpressuser');\n\n\/** MySQL database password *\/\ndefine('DB_PASSWORD', 'password');<\/pre>\n<pre>Save and Exit.\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/DPI0igz.png\" width=\"706\" height=\"574\" \/><\/pre>\n<h2>Step Four\u2014Copy the Files<\/h2>\n<hr \/>\n<pre>We are almost done uploading WordPress to the server. We need to create the directory where we will keep the wordpress files:<\/pre>\n<pre>sudo mkdir -p \/usr\/share\/nginx\/html\/wordpress<\/pre>\n<pre>The final move that remains is to transfer the unzipped WordPress files to the website's root directory.<\/pre>\n<pre>sudo cp -r ~\/wordpress\/* \/usr\/share\/nginx\/html\/wordpress\n\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/OCbGEGP.png\" width=\"775\" height=\"49\" \/><\/pre>\n<h2>Step Twelve\u2014RESULTS: Access the WordPress Installation<\/h2>\n<p>Once that is all done, the wordpress online installation page is up and waiting for you:<\/p>\n<p><strong>http:\/\/IP\/wordpress<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/GpKT9U1.png\" width=\"1316\" height=\"936\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>So finally its done ! Once it is installed you can access .<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"http:\/\/i.imgur.com\/0J4ZXRf.png\" width=\"1366\" height=\"1163\" \/><\/p>\n<p>If anyone is facing any issues you can comment below , we&#8217;ll help you to sort that out .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing Linux, nginx, MySQL, PHP (LEMP) stack LEMP stack is a group of open source software to get web servers up and running. The acronym stands for Linux, nginx (pronounced Engine x), MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[60],"tags":[104,105],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-linux","tag-how-to-install-wordpress-on-nginx","tag-how-to-install-wordpress-with-nginx-on-centos-6"],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/comments?post=235"}],"version-history":[{"count":0,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shineservers.com\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}