Environment: Linux Centsos 6.7 32-bit
Task: Build a Web environment:linux--nginx-php-mysql
(1) Installing PHP includes some additional parts:
Yum install php php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc
(2) Install MySQL client and server:
Yum-y install MySQL #安装客户端 can find yum search Mysqlyum install mysql-server #安装服务器chkconfig--level 345 mysq L on #设置mysql自启动 can not service mysqld start #开启mysql服务mysql_secure_installation #设置mysql用户根据英文提示完成配置, need to be set to root user Password, #其他按需要设置, is generally the first time you use MySQL no password directly enter, then prompt to the root user to set the password, and then straight to enter the right.
(3) Install Nginx:
#直接yum安装需要更新一下yum源, the methods and files are as follows: #1. New nginx.repo file cd /etc/under /etc/yum.repos.d folder yum.repos.dvim nginx.repo# Add the following content :[nginx]name=nginx repobaseurl=http://nginx.org/packages/ centos/$releasever/$basearch/gpgcheck=0enabled=1# See if Yum is finished updating: Yum list| grep nginx return content (similar to Different versions may vary):nginx.i386 1.10.1-1.el6.ngx @nginx nginx-debug.i386 1.8.0-1.el6.ngx nginx nginx-debuginfo.i386 1.10.1-1.el6.ngx nginx nginx-module-geoip.i386 1.10.1-1.el6.ngx nginx nginx-module-image-filter.i386 1.10.1-1.el6.ngx nginx nginx-module-njs.i386 1.10.1.0.0.20160414.1c50334fbea6-1.el6.ngx nginx nginx-module-perl.i386 1.10.1-1.el6.ngx nginx nginx-module-xslt.i386 1.10.1-1.el6.ngx nginx nginx-nr-agent.noarch 2.0.0-9.el6.ngx nginx pcp-pmda-nginx.i686 3.10.9-6.el6 base#yum Source update complete, start installation nginx yum install -y nginx# installation completed
(4) Install php-fpm to make Nginx explain PHP (not standard):
This place is the most important place, because Nginx and PHP, by default, have a little feeling between them. Before, many friends have built apache+php,apache+php compiled after the build is a module file, and nginx+php need PHP to generate executable files, so to use fastcgi technology to achieve the integration of Nginx and PHP, This as long as we install is enabled fastcgi can. This time we install PHP not only use the fastcgi, but also use php-fpm such a thing, PHP-FPM is a management fastcgi a manager, it as a plugin for PHP exists, In the installation of PHP to use PHP-FPM will need to PHP-FPM as a patch installed in PHP, and PHP to be consistent with the PHP-FPM version, it is necessary, remember!
Yum install-y php-fpm #有需要的可以先查找下, yum search php-fpm #可能需要更新解决依赖, Yum will take care of ... You just have to look at the installation to finish it.
(5) configuration
1. Configure ngingx :# nginx configuration files under /etc/nginx/ and /etc/nginx/conf.d (1) The configuration file under the/etc/nginx/file is nginx.conf# the profile does not need to be configured #nginx.conf configuration explanation: http://blog.csdn.net/tjcyjd/article/details/ 50695922 (2) /etc/nginx/conf.d configuration file default.confvim default.confserver { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log /nginx/log/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; #修改为:index index.html index.htm index.php; } #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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI Server listening on 127.0.0.1:9000#nginx not like apache it is to send php files to PHP to perform normal display, by the last sentence can be sent through 9000 port to PHP # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_ param script_filename /script$fastcgi_script_name; #修改为: Fastcgi_param script_filename /usr/share/nginx/html$fastcgi_ script_name;#/usr/share/nginx/html the location of the PHP file include fastcgi_params; } # deny access&nBsp;to .htaccess files, if apache ' s document root # Concurs with nginx ' s one # #location ~ /\.ht { # deny all; #}}2. Configuration php-fpm : #配置文件为: /etc/php-fpm.conf and /etc/php-fpm.d/www.conf# because the port being monitored in the default configuration is 9000 So no need to modify, can be used directly
(6) test
#在/usr/share/nginx/html # Rename or delete your own index.html cd/usr/share/nginx/html# rename: mv index.html index.html.bak# Delete: rm-f index.html# new PHP File: Vim index.php<?php phpinfo ()?> #开启服务: Service nginx restartservice php-fpm restart# host access: 127. 0.0.1
This article is from the "Creative Pilgrim" blog, so be sure to keep this source http://dearch.blog.51cto.com/10423918/1790382
The Linux--nginx-php-mysql of Web environment construction