CentOS7 安裝LNMP(Linux+Nginx+MySQL+PHP)

來源:互聯網
上載者:User

標籤:

    由於工作須要,須要學習php,本來想安裝lamp的可是考慮到如今nginxserver有良好的效能且應用廣泛。

這裡我決定搭建Linux(CentOS7+Nginx+MySQL+PHP)下的webserver。

一、安裝httpd。
yum install -y httpd
安裝完畢之後使用以下命令啟動httpd服務:
systemctl start httpd.service #啟動apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重新啟動apache
systemctl enable httpd.service #設定apache開機啟動
    能夠在瀏覽器中輸入server所在的主機的IP就可以看到apache的歡迎介面。

要在另外一台主機上實現這樣的訪問,須要關閉系統的防火牆。

    在CentOS7中,改動防火牆的機制已經做了改動,在CentOS 6.x系統中能夠使用以下命令:
service iptables stop
chkconfig iptables off // 開機禁止啟動

    而在CentOS7中僅僅能使用以下命令。假設使用上面的命令並不會報不論什麼錯誤。可是起不到關閉防火牆的效果:
systemctl stop firewalld.service
systemctl disable firewalld.service //禁止防火牆開機啟動
關閉SeLinux
    使用getenforce命令能夠查看SeLinux的狀態,SeLinux有三種狀態。分別為enforcing、permissive和disabled。

由於我們的server僅僅在內部使用。所以這裡我們選擇全然關閉(disabled)。

詳細的做法為改動/etc/sysconfig/selinux檔案,詳細操作能夠看裡面的說明。

    安裝成功httpd(apache)的為:
二、安裝MySQL資料庫。
MySQL資料庫。新版本號碼已經更名為Mariadb。所以這裡須要安裝Mariadb,能夠使用以下的命令進行安裝:
yum install -y mariadb
安裝完畢以後使用以下的命令開啟資料庫服務:
systemctl start mariadb.service #啟動MariaDB
systemctl stop mariadb.service #停止MariaDB
systemctl restart mariadb.service #重新啟動MariaDB
systemctl enable mariadb.service #設定開機啟動
三、安裝PHP。

使用以下的命令能夠安裝PHP:
yum -y install php
使用以下的命令安裝php對Mariadb的支援:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
使用以下的命令重新啟動Mariadb和httpd服務:
systemctl restart mariadb.service #重新啟動MariaDB
systemctl restart httpd.service #重新啟動apache
四、安裝nginx。

  這裡使用的是nginx做反向 Proxy,將其client通過80port請求的.php內容代理到apacheserver上。


使用以下命令安裝nginx:
yum install -y nginx
要想使用nginx做反向 Proxy,須要改動Apache的httpd和nginx的設定檔,使其監聽不同的port。這裡我們使用nginx監聽80port,使用Apache監聽8080port,這裡我們分別配置Apache和nginx的設定檔,改動結果例如以下:
(1)Apache設定檔:/etc/httpd/conf/httpd.conf

(2)nginx配置例如以下:

    這樣。當使用者在瀏覽器中訪問該server有關.php結尾的檔案都會代理到監聽8080port的Apacheserver。示比例如以下:
(1)不指定8080port訪問:

(2)指定訪問8080port。

CentOS7 安裝LNMP(Linux+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.