One of CentOS5VPS nginx + php + mysql solutions

Source: Internet
Author: User
This solution uses the latest stable version Nginx compiled by Ruihao open source, fastcgi Process Management using spawn-fcgi, and CentO

There are multiple nginx + php + mysql solutions under CentOS5 VPS. This article describes one of the solutions.

This article is based on the 64-bit CentOS 5 VPS. if it is a 32-bit VPS, modify it in the corresponding section.

This solution uses the latest stable version of Nginx compiled by Ruihao open source, the fastcgi process management uses spawn-fcgi, and MySQL 5.0.45 and php 5.1.6 of CentOS 5.

Advantages and disadvantages

The advantage of this solution is the use of php and mysql that comes with CentOS5, which has good scalability and can be used directly in various extension yum libraries of php. In addition, because php and mysql come with the system, the security is better. if you have any vulnerabilities, you can upgrade them to the latest official centos version. Because spawn-fcgi is used, php does not need to be re-compiled.

Disadvantages of this solution include:

  1. Php and mysql are both built-in centos versions, not the latest version. if some features of the latest version of php are used, they will not work.
  2. Spawn-fcgi performance is not as good as php-fpm, if you want to use php-fpm, please refer to the http://rashost.com/blog/centos5-vps-nginx-solution2
Install Nginx

Download http://rashost.com/download to nginx-0.7.61-1.x86_64.rpm

Installation Command:

Rpm-ivh nginx-0.7.61-1.x86_64.rpm
Chkconfig -- list nginx
Chkconfig nginx on
/Etc/init. d/nginx start
Rpm-ql nginx

The above rpm-ql nginx command is to check which directories the nginx files are installed under. you can see that the default nginx webpage directory should be/usr/share/nginx/html/

When you access nginx through a browser, you can see the default web page of nginx, which means nginx is working properly!

Install MySQL

Yum install-y mysql-server
Chkconfig -- list mysqld
Chkconfig mysqld on
/Etc/init. d/mysqld start

Run the mysql-u root command to connect to MySQL normally.

Install PHP

Yum install-y php-cgi php-mysql

Install spawn-fcgi

Download http://rashost.com/download to spawn-fcgi-1.6.2-1.32.x86_64.rpm

Rpm-ivh spawn-fcgi-1.6.2-1.32.x86_64.rpm

Then add the spawn-fcgi startup command in/etc/rc. local:

Spawn-fcgi-C 10-a 127.0.0.1-p 9000-u nginx-d/tmp-f php-cgi

The-C 10 parameter indicates the number of php fastcgi processes started. The value can be modified based on the website traffic and memory size.

Then start php manually:

Spawn-fcgi-C 10-a 127.0.0.1-p 9000-u nginx-d/tmp-f php-cgi

Integration

First, create the file test. php in the/usr/share/nginx/html Directory. the content is very simple, as long as the following line:

Assume that the VPS address is centos5.rashost.com. then, access http://centos5.rashost.com/test.php through a browser.

Modify the nginx configuration file/etc/nginx. conf, search for fastcgi_pass in the file, and modify this part:

Location ~ \. Php $ {
Root html;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root/$ fastcgi_script_name;
Include fastcgi_params;
}

Restart nginx:

/Etc/init. d/nginx/restart

Then access the test. php page in the browser and the page will be correctly displayed. reboot VPS test, each module should be able to be started by itself. We're done! we should have some beer to celebrate!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.