CentOS 7, lamp

來源:互聯網
上載者:User

標籤:centos 7   lamp   

CentOS 7, LAMP


 簡要介紹:

   LAMP指的Linux(作業系統)、ApacheHTTP 伺服器,MySQL(有時也指MariaDB,資料庫軟體) 和PHP(有時也是指Perl或Python) 的第一個字母,一般用來建立web應用平台。   

   CentOS發布7.0版本,新版本帶來很多特性,除了核心更新到3.10外,支援 Linux 容器、Open VMware Tools 及 3D 映像能即裝即用,轉用 systemd、firewalld 及 GRUB2 ,而預設的檔案系統為XFS等等,可以說是比較重大的升級。筆者嘗試了使用Centos7搭建LAMP伺服器平台,記錄如下。


1.啟用Apache2


  Centos7預設已經安裝httpd服務,只是沒有啟動。如果你需要全新安裝,可以yum install -y httpd

 啟動服務:systemctl start httpd.service

 設定開機自動啟動:systemctl enable httpd.service

 HTTP伺服器已經啟動,進行一下簡單配置

 vi /etc/httpd/conf/httpd.conf #編輯檔案

 ServerSignature On  #添加,在錯誤頁中顯示Apache的版本,Off為不顯示

 Options Indexes FollowSymLinks  

 #修改為:Options Includes ExecCGI FollowSymLinks(允許伺服器執行CGI及SSI,禁止列出目錄)

 #AddHandler cgi-script .cgi

 #修改為:AddHandler cgi-script .cgi .pl (允許副檔名為.pl的CGI指令碼運行)

 AllowOverride None  #修改為:AllowOverride All (允許.htaccess)

 AddDefaultCharset UTF-8 #修改為:AddDefaultCharset GB2312 (添加GB2312為預設編碼)

 #Options Indexes FollowSymLinks 

 #修改為 Options FollowSymLinks(不在瀏覽器上顯示樹狀目錄結構)

 DirectoryIndex index.html  #修改為:DirectoryIndex index.html index.htm Default.html  Default.htm index.php(設定預設首頁檔案,增加index.php)

 MaxKeepAliveRequests 500  #添加MaxKeepAliveRequests 500 (增加同時串連數)

 

 :wq! #儲存退出


 systemctl restart httpd.service #重啟apache

 rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #刪除預設測試頁


2.設定防火牆


 Centos7下的防火牆已經由iptables改為firewall,使用firewall-cmd命令開放80及443連接埠:

 

  firewall-cmd –permanent –zone=public –add-service=http

  firewall-cmd –permanent –zone=public –add-service=https

  firewall-cmd –reload

 設定SELinux為permissive模式 命令列下 setenforce 0 立即生效,重啟失效。

 編輯 vim/etc/sysconfig/selinux  SELinux=enforcing 修改為disabled 關閉SELinux,重啟永久生效。

筆者ip為192.168.1.108,測試下伺服器能否開啟,瀏覽器http://192.168.1.108斷行符號後看到歡迎頁面,說明伺服器正常運行。


3.安裝MariaDB資料庫


 CentOS 7.0中,已經使用MariaDB替代了MySQL資料庫,原因你懂的,MYSQL被Oracle收購以後,前景堪憂,所以MYSQL兄弟MariaDB就出來了,繼續開源事業。


 安裝:yum -y install mariadb-server mariadb

 啟動:systemctl start mariadb.service

      systemctl enable mariadb.service

 配置:cp /usr/share/mysql/my-huge.cnf /etc/my.cnf  覆蓋原配置就好了。

 設定資料庫管理員密碼:mysql_secure_installation  一路y就可以了,當然第一次y後面要輸入兩次密碼。


4.安裝PHP


 安裝PHP主程式: yum -y install php

 安裝PHP組件,使PHP支援 MariaDB

 yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel


 重啟: systemctl restart httpd.service

 配置: vi /etc/php.ini


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

  disable_functions = passthru,exec,system……

  #列出PHP可以禁用的函數,如果某些程式需要用到這個函數,可以刪除,取消禁用。

  expose_php = Off #禁止顯示php版本的資訊

  short_open_tag = ON #支援php短標籤

 open_basedir = .:/tmp/  

 #設定表示允許訪問目前的目錄(即PHP指令檔所在之目錄)和/tmp/目錄,可以防止php木馬跨站,如果改了之後安裝程式有問題,可以登出此行,或者直接寫上程式的目錄/data/www.osyunwei.com/:/tmp/


 測試:vi /var/www/html/index.php  

 輸入<?php phpinfo(); ?>  

 wq儲存退出。 

 開啟http://192.168.1.108 如果能看到PHP配置資訊頁,說明PHP伺服器正常。


至此,LAMP平台就搭建好了!


本文出自 “11253644” 部落格,請務必保留此出處http://11263644.blog.51cto.com/11253644/1765987

CentOS 7, lamp

相關文章

聯繫我們

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