一却桶、安裝Apache
yum install httpd
安裝成功后甫煞,Apache操作命令:
systemctl start httpd //啟動(dòng)apache
systemctl stop httpd //停止apache
systemctl restart httpd //重啟apache
systemctl enable httpd //設(shè)置apache開(kāi)機(jī)啟動(dòng)
異常處理
我再阿里云上配置并出現(xiàn)啟動(dòng)Apache后無(wú)法訪問(wèn)的問(wèn)題铛嘱,但是一般服務(wù)器訪問(wèn)Apache可能需要如下操作:
(1)在防火墻中開(kāi)放80端口
現(xiàn)在需要將 http 服務(wù)加入防火墻以允許外部訪問(wèn)骤公,
firewall-cmd --add-service=http --permanent
–permanent 參數(shù)表示這是一條永久防火墻規(guī)則坏瞄,如果不加則重啟系統(tǒng)后就沒(méi)有這條規(guī)則了。
而對(duì)于自定義的端口(如81),也需要添加防火墻規(guī)則倦卖,
firewall-cmd --zone=public --add-port=81/tcp --permanent
重啟 Firewalld 使該規(guī)則生效洒擦,
systemctl restart firewalld
(2)關(guān)閉SELINUX
vi /etc/selinux/config
注釋掉如下兩句,添加最后一項(xiàng)
\#SELINUX=enforcing #注釋掉
\#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq!
保存退出
輸入如下命令
setenforce 0 #使配置立即生效
二怕膛、 安裝MariaDB (MySQL的一個(gè)開(kāi)源分支)
yum install mariadb mariadb-server
MariaDB安裝成功后熟嫩,需要配置MySQL的root密碼,此外褐捻,備注一下啟動(dòng)關(guān)閉MariaDB的常用命令
systemctl start mariadb //啟動(dòng)MariaDB
systemctl stop mariadb //停止MariaDB
systemctl restart mariadb //重啟MariaDB
systemctl enable mariadb //設(shè)置開(kāi)機(jī)啟動(dòng)
設(shè)置root賬戶密碼
mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]
點(diǎn)擊回車(chē)然后提示是否設(shè)置root賬號(hào)密碼掸茅,輸入y
New password:
Re-enter new password:
Password updated successfully!
提示輸入新密碼和重復(fù)輸入新密碼,重復(fù)輸入兩次后柠逞,出現(xiàn)更新密碼成功提示昧狮。
然后一路輸入y就可以。
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y
... Success!
Thanks for using MariaDB!
設(shè)置root密碼后板壮,重啟MariaDB生效
systemctl restart mariadb.service
測(cè)試訪問(wèn)數(shù)據(jù)庫(kù):
mysql -uroot -p
然后輸入密碼,登錄成功后顯示如下:
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
輸入如下命令逗鸣,查看數(shù)據(jù)庫(kù)服務(wù)器的數(shù)據(jù)庫(kù)
show databases;
退出命令:
exit;
三、安裝PHP以及PHP拓展
yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
安裝完成后绰精,重啟Apache服務(wù)器
systemctl restart httpd.service
測(cè)試PHP安裝結(jié)果
vi /var/www/html/index.php
輸入如下內(nèi)容
<?php
phpinfo();
?>
輸入:wq!
保存退出
在瀏覽器中輸入服務(wù)器地址撒璧,查看是否可以看到:
四、安裝phpmyadmin
使用yum安裝phpmyadmin
yum install phpmyadmin php-mcrypt
phpMyAdmin 的默認(rèn)安裝目錄是 /usr/share/phpMyAdmin笨使,同時(shí)會(huì)在 Apache 的配置文件目錄中自動(dòng)創(chuàng)建虛擬主機(jī)配置文件 /etc/httpd/conf.d/phpMyAdmin.conf(區(qū)分大小寫(xiě))卿樱。默認(rèn)情況下,CentOS 7上的phpMyAdmin只允許從回環(huán)地址(127.0.0.1)訪問(wèn)硫椰。為了能遠(yuǎn)程連接殿如,你需要改動(dòng)它的配置。
vi /etc/httpd/conf.d/phpMyAdmin.conf
修改配置文件最爬,如下:
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
# Require ip 127.0.0.1 #注釋掉
# Require ip ::1 #注釋掉
Require all granted #新添加
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
#Require ip 127.0.0.1 #注釋掉
#Require ip ::1 #注釋掉
Require all granted #新添加
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
然后重啟Apache服務(wù)器
systemctl restart httpd
然后就可以通過(guò)瀏覽器訪問(wèn)http://服務(wù)器ip地址/phpmyadmin訪問(wèn)