Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習 Linux

CentOS 7.2 用 yum 快速架出 LAMP 環境

一、前置準備

先安裝 CentOS 7.2 並確認能連上網路、取得 yum 源。網路設定檔路徑依網卡名稱而異:

vim /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
NAME=eno16777736
UUID=a90b6241-89da-450a-9742-d5b186a17084
DEVICE=eno16777736
ONBOOT=yes
IPADDR0=192.168.0.228
PREFIXO0=24
GATEWAY0=192.168.0.1
DNS1=192.168.0.1

重啟網路並驗證:

systemctl restart network.service
ping www.baidu.com

改用 iptables 並放行 80、3306

CentOS 7 預設使用 firewalld,這裡換成 iptables:

systemctl stop firewalld.service
systemctl disable firewalld.service
yum install iptables-services
vi /etc/sysconfig/iptables

在 COMMIT 之前加入兩行,位置務必對應正確:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
systemctl restart iptables.service
systemctl enable iptables.service

關閉 SELinux

vi /etc/selinux/config
# 將 SELINUX=enforcing 與 SELINUXTYPE=targeted 註解掉
SELINUX=disabled
setenforce 0

二、安裝 LAMP

1. Apache

yum install httpd
systemctl start httpd.service     # 啟動
systemctl stop httpd.service      # 停止
systemctl restart httpd.service   # 重啟
systemctl enable httpd.service    # 開機自啟

重啟服務後瀏覽器輸入 localhost,看到預設測試頁即代表成功。

CentOS 7.2 用 yum 快速架出 LAMP 環境

2. MySQL

yum 預設源沒有 mysql-server,需先加入官方 repo:

wget https://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
systemctl restart mysqld.service

首次安裝 root 尚無密碼:

mysql -u root
set password for 'root'@'localhost' = password('123456');
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;

3. PHP

yum install php
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
systemctl restart mysqld.service
systemctl restart httpd.service

可寫一支 phpinfo.php 放到網站根目錄驗證解析是否正常,測完記得刪除,避免暴露環境資訊。另外,範例中的 123456 與 root@'%' 只適合實驗室,正式環境請改用強密碼並限制來源網段。

參考:https://www.centoscn.com/CentosServer/www/2016/0331/6964.html

Copyright © Linux教程網 All Rights Reserved