1. 程式人生 > >阿里雲|Centos7及以上|LAMP(LINUX+APACHE+MYSQL+PHP) 安裝教程

阿里雲|Centos7及以上|LAMP(LINUX+APACHE+MYSQL+PHP) 安裝教程

一、配置防火牆,開啟80埠、3306埠CentOS 7.0預設使用的是firewall作為防火牆,這裡改為iptables防火牆。
1、關閉firewall:
a)停止firewall服務
systemctl stop firewalld.service
b)禁止firewall開機啟動
systemctl disable firewalld.service
2、安裝iptables防火牆
a)安裝
yum install iptables-services
b)編輯防火牆配置檔案
vi /etc/sysconfig/iptables
配置文字資訊
# 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
c)儲存退出
wq! #儲存退出
d) 最後重啟防火牆使配置生效
systemctl restart iptables.service
設定防火牆開機啟動
systemctl enable iptables.service
3關閉SELINUX


a)修改配置檔案
vi /etc/selinux/config
SELINUX=enforcing #註釋掉
SELINUXTYPE=targeted #註釋掉
SELINUX=disabled #增加
wq! #儲存退出
b)使配置立即生效
setenforce 0
二.安裝apache
1、 yum install httpd
可能會用到的:
systemctl start httpd.service #啟動apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重啟apache
systemctl enable httpd.service #設定apache開機啟動
restart一下,然後輸入IP
出現如圖所示之後代表已經安裝上去了。

這裡寫圖片描述
三.安裝php
1、yum install php
2、安裝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
3、重啟對應服務
systemctl restart mysqld.service
systemctl restart httpd.service
四、yum安裝mysql


1、centos7下yum安裝mysql與解除安裝mysqlCentOS 7的yum源中貌似沒有正常安裝mysql時的mysql-sever檔案,需要去官網上下載
wget http://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
2、成功安裝之後重啟mysql服務
service mysqld restart
3、初次安裝mysql是root賬戶是沒有密碼的(設定密碼)
mysql -uroot
mysql> set password for ‘root’@‘localhost’ = password(‘mypasswd’);
mysql> exit
搞定!