安裝配置php

來源:互聯網
上載者:User

標籤:

安裝PHP
       1、安裝PHP
       yum install php   #根據提示輸入Y直到安裝完成 
       2、安裝PHP組件,使PHP支援 MySQL、PHP支援FastCGI模式
      yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm           #根據提示輸入Y斷行符號
      /etc/init.d/mysqld restart  #重啟MySql
      /etc/init.d/nginx  restart  #重啟nginx
      /etc/rc.d/init.d/php-fpm  start  #啟動php-fpm
      chkconfig php-fpm on  #設定開機啟動
#############################################################################
配置篇

一、配置nginx支援php
       cp /etc/nginx/nginx.conf  /etc/nginx/nginx.confbak    #備份原有設定檔
       vi /etc/nginx/nginx.conf  #編輯
       user   nginx  nginx;  #修改nginx運行帳號為:nginx組的nginx使用者
       :wq!    #儲存退出

cp /etc/nginx/conf.d/default.conf  /etc/nginx/conf.d/default.confbak   #備份原有設定檔
vi /etc/nginx/conf.d/default.conf   #編輯

index  index.php index.html index.htm;   #增加index.php

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  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;
  }
     #取消FastCGI server部分location的注釋,並要注意fastcgi_param行的參數,改為$document_root$fastcgi_script_name,或者使用絕對路徑

二、配置php

  vi  /etc/php.ini   #編輯

  date.timezone = PRC     #在946行 把前面的分號去掉,改為date.timezone = PRC

  disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
                          #在386行 列出PHP可以禁用的函數,如果某些程式需要用到這個函數,可以刪除,取消禁用。
  expose_php = Off        #在432行 禁止顯示php版本的資訊
  magic_quotes_gpc = On   #在745行 開啟magic_quotes_gpc來防止SQL注入
  open_basedir = .:/tmp/  #在380行,設定表示允許訪問目前的目錄(即PHP指令檔所在之目錄)和/tmp/目錄,可以防止php木馬跨站,如果改了之後安裝程式有問題,可登出此行,或者直接寫上程式目錄路徑/var/www/html/www.osyunwei.com/:/tmp/
      :wq!  #儲存退出

三、配置php-fpm

cp /etc/php-fpm.d/www.conf   /etc/php-fpm.d/www.confbak   #備份原有設定檔
       vi /etc/php-fpm.d/www.conf   #編輯
       user = nginx   #修改使用者為nginx
       group = nginx   #修改組為nginx

 /etc/init.d/mysqld restart  #重啟MySql
       /etc/init.d/nginx  restart  #重啟nginx
       /etc/rc.d/init.d/php-fpm  restart  #重啟php-fpm
#############################################################################
測試篇
      
cd  /usr/share/nginx/html/   #進入nginx預設網站根目錄
       vi  index.php   #建立index.php檔案

<?php
           phpinfo();
       ?>
       :wq! #儲存

chown nginx.nginx /usr/share/nginx/html/ -R  #設定目錄所有者

chmod 700  /usr/share/nginx/html/ -R   #設定目錄許可權

在用戶端瀏覽器輸入伺服器IP地址,可以看到相關的配置資訊!
#############################################################################

備忘

nginx預設網站目錄是:/usr/share/nginx/html/

使用權限設定:chown nginx.nginx /usr/share/nginx/html/ -R

MySQL資料庫目錄是:/var/lib/mysql

使用權限設定:chown mysql.mysql -R  /var/lib/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.