centos7 伺服器安裝nginx,mysql,php

來源:互聯網
上載者:User

標籤:

一、概述

  項目的需要,今天在虛擬機器上基於Centos安裝配置了伺服器運行環境,web服務用 nginx,資料庫儲存在mysql,動態指令碼語言是php。

二、步驟

首頁保證Centos7已經安裝完畢,正常運行。如果沒有安裝,請到官網下載(http://www.centos.org/download/ )。如何安裝就不在這裡贅述了。接下來分5步介紹nginx,mysql,php的安裝和配置。
1.第一步:安裝nginx

  添加centos yum源。

  # sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

  安裝nginx

  # sudo yum install nginx

  啟動nginx服務

  # sudo systemctl start nginx.service

  訪問ip地址,如出現Nginx歡迎頁面,則說明nginx已經安裝並正常運行。

  設定開機自動啟動Nginx

  # sudo systemctl enable nginx.service

 

2.第二步:安裝mysql

  CentOS7預設使用MariaDB,yum源中預設好像是沒有mysql的。為瞭解決這個問題,我們要先下載mysql的repo源。

  下載mysql的repo源

  # wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

  安裝mysql-community-release-el7-5.noarch.rpm包

  # sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

  安裝mysql

  # yum install mysql-server

  啟動

  # service mysqld restart

 

3.第三步,安裝PHP

  安裝Php和php 擴充

  # sudo yum install php php-mysql php-fpm php-mbstring php-gd php-pear php-mcrypt  php-mhash php-eaccelerator  php-cli php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mssql php-snmp php-soap php-tidy php-common php-devel php-pecl-xdebug -y

  編輯php設定檔

  # sudo vi /etc/php.ini

  cgi.fix_pathinfo=0

  設定php-fpm設定檔

  # sudo vi /etc/php-fpm.d/www.conf

  listen = /var/run/php-fpm/php-fpm.sock

  啟動php-fpm服務

  # sudo systemctl start php-fpm

  設定開機自動重啟php-fpm

  # sudo systemctl enable php-fpm.service

 

4.第四步:配置nginx網站

  編輯網站設定檔

  # sudo vi /etc/nginx/conf.d/default.conf

  server {
    listen       80;
    server_name  drupaluser.org;

    root   /opt/data;
    index index.php index.html index.htm;

    location / {
      try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
      root /usr/share/nginx/html;
    }

    location ~ \.php$ {
      try_files $uri =404;
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
  }

 

  重啟nginx

  # sudo systemctl restart nginx

 

5.第五步:測試php指令碼web服務

  編輯測試檔案

  # sudo vi /opt/data/info.php

  訪問頁面,能看到php各種配置資訊的話說明配置成功。
  http://drupaluser.org/info.php

  刪除測試檔案

  # sudo rm /opt/data/info.php

  到此CentOS 7下nginx,mysql,php安裝配置全部完成,可以做為web平台的應用環境使用。

centos7 伺服器安裝nginx,mysql,php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.