虛擬機器下安裝Centos7並配置Apache+PHP+Mysql+phpmyadmin+wordpress

來源:互聯網
上載者:User

標籤:config   完成後   string   ldap   get   auth   退出   php   sam   

一、安裝Apache

yum install httpd

安裝成功後,Apache操作命令:

systemctl start httpd      //啟動apachesystemctl stop httpd       //停止apachesystemctl restart httpd    //重啟apachesystemctl enable httpd     //設定apache開機啟動

訪問伺服器Apache可能需要如下操作:
(1)在防火牆中開放80連接埠
需要將 http 服務加入防火牆以允許外部存取,

firewall-cmd --add-service=http --permanent

–permanent 參數表示這是一條永久防火牆規則,如果不加則重啟系統後就沒有這條規則了。

而對於自訂的連接埠(如81),也需要添加防火牆規則,

firewall-cmd --zone=public --add-port=81/tcp --permanent

 

重啟 Firewalld 使該規則生效,

systemctl restart firewalld

 

二、 安裝MariaDB (MySQL的一個開源分支)

yum install mariadb mariadb-server

MariaDB安裝成功後,需要配置MySQL的root密碼,此外,備忘一下啟動關閉MariaDB的常用命令

systemctl start mariadb     //啟動MariaDBsystemctl stop mariadb      //停止MariaDBsystemctl restart mariadb   //重啟MariaDBsystemctl enable mariadb    //設定開機啟動

設定root賬戶密碼

mysql_secure_installation

Enter current password for root (enter for none):
Set root password? [Y/n]

點擊斷行符號然後提示是否設定root帳號密碼,輸入y

New password:
Re-enter new password:
Password updated successfully!

提示輸入新密碼和重複輸入新密碼,重複輸入兩次後,出現更新密碼成功提示。

然後一路輸入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!

設定root密碼後,重啟MariaDB生效

systemctl restart mariadb.service

測試訪問資料庫:

mysql -uroot -p

輸入如下命令,查看資料庫伺服器的資料庫

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伺服器

systemctl restart httpd.service

測試PHP安裝結果

vi /var/www/html/index.php 

輸入如下內容

<?php  phpinfo();?>

輸入

:wq! 

儲存退出


在瀏覽器中輸入伺服器位址,查看是否成功安裝

 

四、安裝phpmyadmin

先安裝Remi源,

yum install epel-releaserpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

再使用yum安裝phpmyadmin

yum install phpmyadmin php-mcrypt
phpMyAdmin 的預設安裝目錄是 /usr/share/phpMyAdmin,同時會在 Apache 的設定檔目錄中自動建立虛擬機器主機設定檔 /etc/httpd/conf.d/phpMyAdmin.conf(區分大小寫)。預設情況下,CentOS 7上的phpMyAdmin只允許從迴環地址(127.0.0.1)訪問。為了能遠端連線,你需要改動它的配置。 
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伺服器

systemctl restart httpd

然後就可以通過瀏覽器訪問http://伺服器ip地址/phpmyadmin訪問

 

四、安裝wordpress

安裝wget:

yum install wget

下載wordpress

wget http://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip

安裝:unzip

yum install unzip

使用 unzip 來解壓檔案:

unzip wordpress-4.9.1-zh_CN.zip

在 Mysql 中建立資料庫

mysql -u root -p

通過上面的命令進入資料庫,然後輸入密碼:password

然後建立一個叫 wordpress 的資料庫

create database wordpress;

cd 進入wordpress 目錄

修改wordpress設定檔wp-config.php

p.s.1:預設這個檔案沒有,需重新命名wp-config-sample.php

mv wp-config-sample.php wp-config.php

根據伺服器資訊修改以下幾處內容

/** MySQL資料庫名:wordpress */define(‘DB_NAME‘, ‘wordpress‘); /** MySQL資料庫使用者名稱 :root*/define(‘DB_USER‘, ‘root‘); /** MySQL資料庫密碼 :password*/define(‘DB_PASSWORD‘, ‘password‘);/** MySQL主機(不用修改) */define(‘DB_HOST‘, ‘localhost‘);

修改完成後,

把檔案複製到 /var/www/html 目錄下

cp -rf wordpress/* /var/www/html/

然後輸入伺服器位址訪問wordpress進行安裝

 

p.s.2:安裝完wordpress,後台管理外掛程式時,需要輸入FTP問題

解決方案:

chown -R apache:apache /var/www/html

 

虛擬機器下安裝Centos7並配置Apache+PHP+Mysql+phpmyadmin+wordpress

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.