web環境搭建之Linux--nginx-php-mysql

來源:互聯網
上載者:User

標籤:php   linux   mysql   nginx   

環境:Linux CentsOs 6.7 32位

任務:搭建web環境:Linux--nginx-php-mysql


(1)安裝PHP包括一些附加件:

yum install php php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc

(2)安裝MySQL用戶端及伺服器:

yum -y install mysql         #安裝用戶端   可以尋找一下 yum search mysqlyum install mysql-server     #安裝伺服器chkconfig --level 345 mysql on     #設定mysql自啟動 可以不要service mysqld start         #開啟mysql服務mysql_secure_installation  #設定mysql使用者根據英文提示完成配置,需要給root使用者佈建密碼,#其他按需要設定,一般是斷行符號到底 第一次使用mysql沒有密碼直接斷行符號,然後會提示給root使用者佈建密碼,然後直接一直斷行符號就OK了。

(3)安裝nginx:

#直接yum安裝需要更新一下yum源,方法及檔案如下:#1.在  /etc/yum.repos.d 檔案夾下建立 nginx.repo 檔案cd /etc/yum.repos.dvim nginx.repo#添加以下內容 :[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1#查看yum是否完成更新:yum list| grep nginx返回內容(類似即可,版本不同可能會有差異):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源更新完畢,開始安裝nginx yum install -y nginx#安裝完成

(4)安裝  php-fpm  使nginx解釋php(說法不標準):

  這個地方是最重要的地方,因為預設情況下Nginx和PHP他倆之間是一點感覺沒有的。在之前,很多朋友都搭建過Apache+PHP,Apache+PHP編譯後產生的是模組檔案,而Nginx+PHP需要PHP產生可執行檔才可以,所以要利用fastcgi技術來實現Nginx與PHP的整合,這個只要我們安裝是啟用FastCGI即可。此次我們安裝PHP不僅使用了FastCGI,而且還使用了PHP-FPM這麼一個東東,PHP-FPM說白了是一個管理FastCGI的一個管理器,它作為PHP的外掛程式存在,在安裝PHP要想使用PHP-FPM時就需要把PHP-FPM以補丁的形式安裝到PHP中,而且PHP要與PHP-FPM版本一致,這是必須的,切記!

yum install -y php-fpm #有需要的可以先尋找下,yum search php-fpm                       #可能需要更新解決依賴,yum會搞定...只需要看著安裝完成就可以了

(5)配置

1.配置 ngingx :# nginx 的設定檔在 /etc/nginx/ 下 和 /etc/nginx/conf.d (1)/etc/nginx/檔案下的設定檔是 nginx.conf#該設定檔不需要配置#nginx.conf配置解釋:http://blog.csdn.net/tjcyjd/article/details/50695922(2) /etc/nginx/conf.d 下的設定檔 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 不像Apache 它是將php檔案交給php執行才能正常顯示,通過上句可以它是通過 9000 連接埠發給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   為php檔案所在地址        include        fastcgi_params;    }    # deny access to .htaccess files, if Apache‘s document root    # concurs with nginx‘s one    #    #location ~ /\.ht {    #    deny  all;    #}}2.配置php-fpm :#設定檔為: /etc/php-fpm.conf 和 /etc/php-fpm.d/www.conf#因為其預設配置中監聽的連接埠為 9000 所以不需要修改,可以直接使用

(6)測試

#在 /usr/share/nginx/html 下#將內建的 index.html 重新命名或者刪除cd /usr/share/nginx/html#重新命名:mv index.html index.html.bak#刪除:rm -f index.html#建立php檔案:vim index.php<?php     phpinfo(); ?>#開啟服務:service nginx restartservice php-fpm restart#主機訪問:127.0.0.1

本文出自 “啟思·朝聖者” 部落格,請務必保留此出處http://dearch.blog.51cto.com/10423918/1790382

web環境搭建之Linux--nginx-php-mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.