Home Backend Development PHP Tutorial 1 minute perfect installation of the latest CentOS+Nginx+PHP-FPM+MySQL_PHP tutorial

1 minute perfect installation of the latest CentOS+Nginx+PHP-FPM+MySQL_PHP tutorial

Jul 22, 2016 am 09:02 AM
mysql php Install Perfect up to date

PHP 5.3.1

MySQL 5.0.89

Nginx 0.8.33 or 0.7.65 (optional)

Now, we can quickly and fully automate it CentOS + Nginx + PHP-FPM + MySQL is installed

This is much better than the one-click installation package circulated on the Internet. This method of installation is highly recommended, suitable for all novices and experts

The source code compilation and installation that I use on my server is not much better. Go, it’s still very laborious

My installation already includes some common extensions of PHP, PDO, eaccelerator, memcache, tidy, etc.

First create a new repo

<ol class="dp-xml"><li class="alt"><span><span># vi /etc/yum.repos.d/centos.21andy.com.repo </span></span></li></ol>
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

Put in the following content

<ol class="dp-xml">
<li class="alt"><span><span>[21Andy.com]  </span></span></li>
<li>
<span></span><span class="attribute"><font color="#ff0000">name</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">21Andy</font></span><span>.com Packages for Enterprise Linux 5 - $basearch  </span>
</li>
<li class="alt">
<span></span><span class="attribute"><font color="#ff0000">baseurl</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">http</font></span><span>://www.21andy.com/centos/5/$basearch/  </span>
</li>
<li>
<span></span><span class="attribute"><font color="#ff0000">enabled</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span> </span>
</li>
<li class="alt">
<span></span><span class="attribute"><font color="#ff0000">gpgcheck</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">0</font></span><span> </span>
</li>
<li>
<span></span><span class="attribute"><font color="#ff0000">protect</font></span><span>=</span><span class="attribute-value"><font color="#0000ff">1</font></span><span> </span>
</li>
</ol>
Copy after login

Enable EPEL repo

i386

<ol class="dp-xml">
<li class="alt"><span><span>rpm -ihv</span></span></li>
<li class="alt"><span><span> http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm </span></span></li>
</ol>
Copy after login

x86_64

<ol class="dp-xml">
<li class="alt"><span><span>rpm -ihv   </span></span></li>
<li><span>http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm  </span></li>
</ol>
Copy after login

Then import the key

<ol class="dp-xml"><li class="alt"><span><span>rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL  </span></span></li></ol>
Copy after login

Okay, one-click installation

<ol class="dp-xml"><li class="alt"><span><span># yum install nginx php-fpm mysql-server  </span></span></li></ol>
Copy after login

If you want to use nginx 0.7.65, the latest stable version, yum- Just replace y install nginx with yum -y install nginx-stable

More complete installation

<ol class="dp-xml">
<li class="alt"><span><span>yum -y update  </span></span></li>
<li><span>yum -y mysql-server  </span></li>
<li class="alt"><span>service mysqld start  </span></li>
<li><span>mysqladmin -u root password root  </span></li>
<li class="alt"><span>service mysqld stop  </span></li>
<li><span>yum -y install nginx php-fpm   </span></li>
<li class="alt"><span>php-cli php-pdo php-mysql php-mcrypt php-mbstring   </span></li>
<li><span>php-gd php-tidy php-xml php-xmlrpc   </span></li>
<li class="alt"><span>php-pear php-pecl-memcache php-eaccelerator  </span></li>
<li><span># APC 和 eAccelerator 有冲突,2选1  </span></li>
<li class="alt"><span>yum -y install php-pecl-apc  </span></li>
</ol>
Copy after login

Look at my complete installation, just one sentence

yum -y install nginx mysql-server php- fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator

Installation results, fully automatic

<ol class="dp-xml">
<li class="alt"><span><span>Dependencies </span><span class="attribute"><font color="#ff0000">Resolved</font></span><span> </span></span></li>
<li><span>==========================================================  </span></li>
<li class="alt">
<span>Package Arch Version Repository </span><span class="attribute"><font color="#ff0000">Size</font></span><span> </span>
</li>
<li><span>==========================================================  </span></li>
<li class="alt"><span>Installing:  </span></li>
<li><span>mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M  </span></li>
<li class="alt"><span>mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M  </span></li>
<li><span>nginx x86_64 0.8.33-3.el5 21Andy.com 422 k  </span></li>
<li class="alt"><span>php-cli x86_64 5.3.1-2.el5 21Andy.com 2.4 M  </span></li>
<li><span>php-eaccelerator x86_64 2:0.9.6-1.el5 21Andy.com 118 k  </span></li>
<li class="alt"><span>php-fpm x86_64 5.3.1-2.el5 21Andy.com 1.2 M  </span></li>
<li><span>php-gd x86_64 5.3.1-2.el5 21Andy.com 110 k  </span></li>
<li class="alt"><span>php-mbstring x86_64 5.3.1-2.el5 21Andy.com 1.1 M  </span></li>
<li><span>php-mcrypt x86_64 5.3.1-2.el5 21Andy.com 27 k  </span></li>
<li class="alt"><span>php-mysql x86_64 5.3.1-2.el5 21Andy.com 84 k  </span></li>
<li><span>php-pdo x86_64 5.3.1-2.el5 21Andy.com 91 k  </span></li>
<li class="alt"><span>php-pear noarch 1:1.9.0-1.el5 21Andy.com 420 k  </span></li>
<li><span>php-pecl-memcache x86_64 2.2.5-3.el5 21Andy.com 44 k  </span></li>
<li class="alt"><span>php-tidy x86_64 5.3.1-2.el5 21Andy.com 31 k  </span></li>
<li><span>php-xml x86_64 5.3.1-2.el5 21Andy.com 115 k  </span></li>
<li class="alt"><span>php-xmlrpc x86_64 5.3.1-2.el5 21Andy.com 48 k  </span></li>
<li><span>Installing for dependencies:  </span></li>
<li class="alt"><span>gmp x86_64 4.1.4-10.el5 base 201 k  </span></li>
<li><span>libXaw x86_64 1.0.2-8.1 base 329 k  </span></li>
<li class="alt"><span>libXmu x86_64 1.0.2-5 base 63 k  </span></li>
<li><span>libXpm x86_64 3.5.5-3 base 44 k  </span></li>
<li class="alt"><span>libedit x86_64 2.11-2.20080712cvs.el5 epel 80 k  </span></li>
<li><span>libmcrypt x86_64 2.5.8-4.el5.centos extras 105 k  </span></li>
<li class="alt"><span>libtidy x86_64 0.99.0-14.20070615.el5 epel 140 k  </span></li>
<li><span>php-common x86_64 5.3.1-2.el5 21Andy.com 554 k  </span></li>
<li class="alt"><span>sqlite2 x86_64 2.8.17-5.el5 21Andy.com 165 k  </span></li>
<li><span>t1lib x86_64 5.1.1-7.el5 epel 208 k  </span></li>
<li class="alt"><span>Updating for dependencies:  </span></li>
<li><span>libevent x86_64 1.4.12-1.el5 21Andy.com 129 k  </span></li>
<li class="alt">
<span>Transaction </span><span class="attribute"><font color="#ff0000">Summary</font></span><span> </span>
</li>
<li><span>==========================================================  </span></li>
<li class="alt"><span>Install 26 Package(s)  </span></li>
<li><span>Update 1 Package(s)  </span></li>
<li class="alt"><span>Remove 0 Package(s  </span></li>
</ol>
Copy after login

Finally, just yum -y update, everything is the latest

Don’t forget to boot up

<ol class="dp-xml">
<li class="alt"><span><span>chkconfig --level 345 mysqld on  </span></span></li>
<li><span>chkconfig --level 345 php-fpm on  </span></li>
<li class="alt"><span>chkconfig --level 345 nginx on  </span></li>
</ol>
Copy after login

Come and see the powerful results of my virtual machine test

http://www.21andy.com/ blog/20100219/1703.html

Additional: All configuration files are in the /etc directory, including configuration files for nginx, php-fpm, and mysql. Please find the settings by yourself. The following is my nginx configuration example

First create a new /www directory. Websites and logs are also placed here.

Don’t forget to create a log storage directory. The /www/logs you use for access_log in the configuration file

Note: fastcgi_params is required Join this line v# vim/etc/nginx/fastcgi_params

<ol class="dp-xml"><li class="alt"><span><span><font color="#000000">fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  </font></span></span></li></ol>
Copy after login

# vi /etc/nginx/nginx.conf

<ol class="dp-c">
<li class="alt"><span><span>user nobody nobody;  </span></span></li>
<li><span> </span></li>
<li class="alt"><span>worker_processes 8; #这里根据你的CPU和内存配置, 设置2到10都OK  </span></li>
<li><span> </span></li>
<li class="alt">
<span class="func">error_log</span><span>  /www/logs/nginx_error.log  crit;  </span>
</li>
<li><span> </span></li>
<li class="alt"><span>pid        /usr/local/nginx/logs/nginx.pid;  </span></li>
<li><span> </span></li>
<li class="alt">
<span>#Specifies the value </span><span class="keyword">for</span><span> maximum file descriptors that can be opened by this process.  </span>
</li>
<li><span>worker_rlimit_nofile 51200;  </span></li>
<li class="alt"><span> </span></li>
<li><span>events {  </span></li>
<li class="alt">
<span>    </span><span class="keyword">use</span><span> epoll;  </span>
</li>
<li><span>    worker_connections 51200;  </span></li>
<li class="alt"><span>}  </span></li>
<li><span> </span></li>
<li class="alt"><span>http {  </span></li>
<li>
<span>    </span><span class="keyword">include</span><span>       mime.types;  </span>
</li>
<li class="alt"><span>    default_type  application/octet-stream;  </span></li>
<li><span> </span></li>
<li class="alt"><span>    #charse  gb2312; # 默认编码,可以不设置  </span></li>
<li><span> </span></li>
<li class="alt"><span>    server_names_hash_bucket_size 128;  </span></li>
<li><span>    client_header_buffer_size 16k;  </span></li>
<li class="alt"><span>    large_client_header_buffers 4 16k;  </span></li>
<li><span>    client_max_body_size 8m;  </span></li>
<li class="alt"><span> </span></li>
<li><span>    sendfile on;  </span></li>
<li class="alt"><span>    tcp_nopush     on;  </span></li>
<li><span> </span></li>
<li class="alt"><span>    keepalive_timeout 60;  </span></li>
<li><span> </span></li>
<li class="alt"><span>    tcp_nodelay on;  </span></li>
<li><span> </span></li>
<li class="alt"><span>    fastcgi_connect_timeout 300;  </span></li>
<li><span>    fastcgi_send_timeout 300;  </span></li>
<li class="alt"><span>    fastcgi_read_timeout 300;  </span></li>
<li><span>    fastcgi_buffer_size 64k;  </span></li>
<li class="alt"><span>    fastcgi_buffers 4 64k;  </span></li>
<li><span>    fastcgi_busy_buffers_size 128k;  </span></li>
<li class="alt"><span>    fastcgi_temp_file_write_size 128k;  </span></li>
<li><span> </span></li>
<li class="alt"><span>    gzip on;  </span></li>
<li><span>    gzip_min_length  1k;  </span></li>
<li class="alt"><span>    gzip_buffers     4 16k;  </span></li>
<li><span>    gzip_http_version 1.0;  </span></li>
<li class="alt"><span>    gzip_comp_level 5;  </span></li>
<li><span>    gzip_types       text/plain text/javascript application/x-javascript text/css application/xml;  </span></li>
<li class="alt"><span>    gzip_vary on;  </span></li>
<li><span> </span></li>
<li class="alt">
<span>    #limit_zone  crawler  </span><span class="vars">$binary_remote_addr</span><span>  10m;  </span>
</li>
<li><span>    server {  </span></li>
<li class="alt"><span>        listen 80;  </span></li>
<li><span>        server_name localhost;  </span></li>
<li class="alt"><span>        root  /www;  </span></li>
<li><span>        location /status {  </span></li>
<li class="alt"><span>            stub_status on;  </span></li>
<li><span>            access_log  off;  </span></li>
<li class="alt"><span>        }  </span></li>
<li><span>        location / {  </span></li>
<li class="alt"><span>            # 这里是把所有不存在的文件和目录,全都转到 index.php 处理  </span></li>
<li>
<span>            try_files </span><span class="vars">$uri</span><span> </span><span class="vars">$uri</span><span>/ /index.php?q=</span><span class="vars">$uri</span><span>&</span><span class="vars">$args</span><span>;  </span>
</li>
<li class="alt"><span>        }  </span></li>
<li><span>          </span></li>
<li class="alt"><span>        # 这里分开放到 server.conf 是为了再开 server 的时候方便,统一调用,放到/etc/nginx/ 目录下  </span></li>
<li>
<span>        </span><span class="keyword">include</span><span> server.conf;  </span>
</li>
<li class="alt"><span> </span></li>
<li>
<span>        log_format  access  </span><span class="string">'$remote_addr - $remote_user [$time_local] "$request" '</span><span> </span>
</li>
<li class="alt">
<span>             </span><span class="string">'$status $body_bytes_sent "$http_referer" '</span><span> </span>
</li>
<li>
<span>             </span><span class="string">'"$http_user_agent" $http_x_forwarded_for'</span><span>;  </span>
</li>
<li class="alt"><span>        access_log  /www/logs/access.log  access;  </span></li>
<li><span>    }  </span></li>
<li class="alt"><span> </span></li>
<li><span>    server {  </span></li>
<li class="alt"><span>        listen 80;  </span></li>
<li><span>        server_name www.21andy.com 21andy.com *.21andy.com;  </span></li>
<li class="alt"><span>        root  /www/21andy.com;  </span></li>
<li>
<span>        </span><span class="keyword">if</span><span> (</span><span class="vars">$host</span><span> !~* 21andy.com$) {  </span>
</li>
<li class="alt">
<span>            </span><span class="keyword">return</span><span> 444;  </span>
</li>
<li><span>        }  </span></li>
<li class="alt"><span>        location / {  </span></li>
<li>
<span>            try_files </span><span class="vars">$uri</span><span> </span><span class="vars">$uri</span><span>/ /index.php?q=</span><span class="vars">$uri</span><span>&</span><span class="vars">$args</span><span>;  </span>
</li>
<li class="alt"><span>        }  </span></li>
<li>
<span>        </span><span class="keyword">include</span><span> server.conf; # 这里复用了,这段就省了  </span>
</li>
<li class="alt"><span>        access_log  /www/logs/21andy.com_access.log  access;  </span></li>
<li><span>    }  </span></li>
<li class="alt"><span>} </span></li>
</ol>
Copy after login
e# vi /etc/nginx/Server.conf

<ol class="dp-c">
<li class="alt"><span><span>index index.html index.htm index.php;  </span></span></li>
<li><span> </span></li>
<li class="alt"><span>#limit_conn   crawler  20;  </span></li>
<li><span> </span></li>
<li class="alt"><span>location ~ /.ht {  </span></li>
<li><span>    deny all;  </span></li>
<li class="alt"><span>}  </span></li>
<li><span> </span></li>
<li class="alt"><span>location ~ .*.(sqlite|sq3)$ {  </span></li>
<li><span>    deny all;  </span></li>
<li class="alt"><span>}  </span></li>
<li><span> </span></li>
<li class="alt"><span>location ~ .*.php$ {  </span></li>
<li><span>    fastcgi_pass  unix:/tmp/php-cgi.sock;  </span></li>
<li class="alt"><span>    #fastcgi_pass  127.0.0.1:9000;  </span></li>
<li><span>    fastcgi_index index.php;  </span></li>
<li class="alt">
<span>    </span><span class="keyword">include</span><span> fastcgi_params;  </span>
</li>
<li><span>}  </span></li>
<li class="alt"><span> </span></li>
<li><span>location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$ {  </span></li>
<li class="alt"><span>    expires      30d;  </span></li>
<li><span>    access_log   off;  </span></li>
<li class="alt"><span>}  </span></li>
<li><span> </span></li>
<li class="alt"><span>location ~ .*.(js|css)?$ {  </span></li>
<li><span>    expires      30d;  </span></li>
<li class="alt"><span>    access_log   off;  </span></li>
<li><span>} </span></li>
</ol>
Copy after login
You can skip the following content in this linephp-fpm can also use the following settings, but it is recommended to use the above, which is more stable

<ol class="dp-c">
<li class="alt"><span><span>location ~ .php$ {  </span></span></li>
<li><span>    root           /www;  </span></li>
<li class="alt"><span>    fastcgi_pass   127.0.0.1:9000;  </span></li>
<li><span>    fastcgi_index  index.php;  </span></li>
<li class="alt"><span>    #下面这一行要加在 /etc/nginx/fastcgi_params 里  </span></li>
<li>
<span>    #fastcgi_param  SCRIPT_FILENAME  </span><span class="vars">$document_root</span><span class="vars">$fastcgi_script_name</span><span>;  </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">include</span><span>        fastcgi_params;  </span>
</li>
<li><span>} </span></li>
</ol>
Copy after login
Whether you use php-cgi.sock or 9000 port method, nginx and php-fpm must be used at the same time Set it to the same

nginx settings as mentioned above, remember to modify the corresponding place in php-fpm.conf at the same time

# vi /etc/php-fpm.conf

<value name="listen_address">127.0.0.1:9000</value>
Copy after login
or
<value name="listen_address">unix:/tmp/php-cgi.sock</value>
Copy after login

Original address :

http://www.21andy.com/blog/20100219/1701.html


http://www.bkjia.com/PHPjc/445841.html

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445841.htmlTechArticle PHP 5.3.1 MySQL 5.0.89 Nginx 0.8.33 or 0.7.65 (optional) Now, we can quickly and fully automatically install CentOS + Nginx + PHP-FPM + MySQL. This one-click installation is comparable to what is being circulated on the Internet. .
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

Compare and contrast MySQL and MariaDB. Compare and contrast MySQL and MariaDB. Apr 26, 2025 am 12:08 AM

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

See all articles