阿里云centos7.2 lamp搭建 -- 總結(jié)

準備

檢查當前系統(tǒng)版本 確定自己是否要更新

# cat /etc/redhat-release

檢查當前系統(tǒng)是否已安裝 apache 和 mysql

# yum list installed | grep httpd

# yum list installed |grep httpd

如果已經(jīng)存在,請先執(zhí)行卸載命令,不同的安裝方式使用不同的卸載方式,例:

# yum remove httpd

添加apache和mysql用戶

useradd -s /sbin/nologin -M apache
useradd -s /sbin/nologin -M mysql

CentOS 7.0 默認使用的是firewall作為防火墻,修改為iptables防火墻
1.關閉firewall
停止firewall

# systemctl stop firewalld.service

禁止firewall開機啟動

# systemctl disable firewalld.service

安裝iptables防火墻

# yum install iptables-services

編輯防火墻配置文件

# vi /etc/sysconfig/iptables

編輯 iptables 文件內(nèi)容

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-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
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

新增內(nèi)容

-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

編輯 config 文件內(nèi)容

#SELINUX=enforcing
#SELINUXTYPE=targeted
SELINUX=disabled

使配置立即生效

# setenforce 0

開始安裝

安裝軟件時,根據(jù)提示,輸入Y安裝即可成功安裝

安裝Apache

# yum install httpd

啟動apache

# systemctl start httpd.service

停止apache

# systemctl stop httpd.service

重啟apache

# systemctl restart httpd.service

設置apache開機啟動

# systemctl enable httpd.service

在客戶端瀏覽器中打開服務器IP地址,會出現(xiàn)apache默認界面,即apache安裝成功
若不能打開默認界面 安裝也沒有問題則:
設置阿里云的安全組:
1、進入阿里云的云服務管理控制臺,在管理實例中選擇本實例安全組,選擇配置規(guī)則。
2、點擊快速創(chuàng)建規(guī)則
3、添加安全組規(guī)則如下:
網(wǎng)卡類型:如果是經(jīng)典網(wǎng)絡,選擇 公網(wǎng)。如果是 VPC (專有)網(wǎng)絡,不需要選擇。
規(guī)則方向:入方向。
授權策略:允許。
協(xié)議類型 和 端口范圍:選擇 HTTP 服務的 TCP 80 端口,HTTPS 的 443 端口,或者自定義 TCP 8080 端口(如圖所示)。
授權對象:0.0.0.0/0,表示允許所有地址訪問。
優(yōu)先級:1,表示安全規(guī)則中優(yōu)先級最高,數(shù)字越小優(yōu)先級越高。
嘗試
若還不能訪問查看httpd.conf 文件中將 AllowOverride None 改為AllowOverride All
再嘗試。

安裝mysql

CentOS 7的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包

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

安裝這個包后,會獲得兩個mysql的yum repo源:

# /etc/yum.repos.d/mysql-community.repo
# /etc/yum.repos.d/mysql-community-source.repo

安裝mysql

# yum install mysql-server

根據(jù)步驟安裝,到目前為止還沒有設置數(shù)據(jù)庫的密碼
重置密碼
重置密碼前,首先要登錄

# mysql -u root

登錄時有可能報這樣的錯誤:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的訪問權限問題。

重啟 mysql 服務

# systemctl restart mysqld.service

重置密碼

# mysql -u root
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;

安裝PHP

# yum install php

安裝PHP組件,使PHP支持 mysql

# yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

配置環(huán)境

Apache配置
編輯 httpd.conf 文件內(nèi)容

# vi /etc/httpd/conf/httpd.conf
//添加ServerSignature On (在錯誤頁中顯示Apache的版本) 
ServerSignature On
//允許服務器執(zhí)行CGI及SSI,禁止列出目錄
Options Indexes FollowSymLinks #修改為:Options Includes ExecCGI FollowSymLinks
//允許.htaccess
AllowOverride None #修改為:AllowOverride All
//設置不在瀏覽器上顯示樹狀目錄結(jié)構(gòu)
#Options Indexes FollowSymLinks #修改為 Options FollowSymLinks
//設置默認首頁文件,增加index.php
DirectoryIndex index.html#修改為:DirectoryIndex index.html index.htm index.php
//添加MaxKeepAliveRequests 500 (增加同時連接數(shù))
MaxKeepAliveRequests 500
刪除默認測試頁
# rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html

php配置
編輯 php.ini 文件內(nèi)容

# vi /etc/php.ini
//設置時區(qū),把前面的分號去掉
date.timezone = PRC
//禁止顯示php版本的信息
expose_php = Off
//支持php短標簽
short_open_tag = ON

重啟apache

# systemctl restart httpd.service

測試服務

# cd /var/www/html
# vi index.php

輸入下面內(nèi)容

<?php
phpinfo();
?>

注:apache 默認的程序目錄是/var/www/html
權限設置:chown apache.apache -R /var/www/html
權限設置:chown mysql.mysql -R /var/lib/mysql

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容