一钝计、前言
最近學習了LAMP的相關(guān)知識恋博,為了鞏固知識以及方便回顧,特意編寫此文記錄LAMP搭建的步驟及相關(guān)要點私恬。
此處搭建實驗將把Lamp安裝在同一個Centos7服務器上债沮。其邏輯圖類似如下:
二、LAMP的搭建
1疫衩、安裝httpd服務
[root@localhost ~]# yum install -y httpd
2、安裝mysql服務:
[root@localhost ~]# yum install -y mariadb-server
3荣德、安裝php服務
[root@localhost ~]# yum install -y php php-mysql
其中php-mysql用于讓php連接mysql數(shù)據(jù)庫。
安裝完成后命爬,在/etc/httpd/conf.d/目錄下會生成一個php.conf文件曹傀,此文件為httpd服務的php模塊的配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/php.conf
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$> #匹配以.php結(jié)尾的文件
SetHandler application/x-httpd-php #調(diào)用php模塊
</FilesMatch>
#
# Allow php to handle Multiviews
#
#添加支持的文件類型
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php #設置默認首頁為index.php
#建議注釋掉/etc/httpd/conf/httpd.conf文件中DirectoryIndex index.html ,以免對顯示產(chǎn)生影響饲宛;
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#匹配以.phps結(jié)尾的文件
#<FilesMatch \.phps$>
# SetHandler application/x-httpd-php-source #調(diào)用php的源代碼模塊
#</FilesMatch>
#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
php_value session.save_handler "files"
php_value session.save_path "/var/lib/php/session"
4皆愉、在/var/www/html 目錄下編輯生成index.php文件
[root@localhost ~]# vim /var/www/html/index.php
<html>
<title>This is a PHP page.</title>
<body>
<h1>PHP Info Page</h1>
<?php
phpinfo();
?>
</body>
</html
5、啟動httpd服務并訪問相應的頁面
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl stop firewalld #停止firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0 #設置selinux為permissive
如上圖所示能正常打開相應的php信息頁面艇抠,說明php平臺已經(jīng)正常啟動幕庐;如果在頁面中能找到mysql、mysqli的信息內(nèi)容家淤,說明對php平臺能正常訪問mysql和mysqli接口异剥,如下圖:
6、啟動mysql服務
[root@localhost ~]# systemctl start mariadb
7絮重、測試php與mysql的連接性
在/var/www/html目錄下編輯創(chuàng)建mysql.php文件:
<?php
$conn = mysql_connect('127.0.0.1','root','');
if ($conn)
echo "Connected to mysql.";
else
echo "Fail";
?>
然后訪問相應的測試頁面:
停用mysql后冤寿,在訪問相應的頁面:
三歹苦、搭建wordpress
1、在鏈接:https://cn.wordpress.org/ 找到相應的wordpress下載鏈接督怜,并通過wget命令下載到本地服務器主機并解壓縮
[root@localhost ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
[root@localhost ~]# tar xf wordpress-4.9.4-zh_CN.tar.gz
[root@localhost ~]# ll -d wordpress*
drwxr-xr-x. 5 nobody 65534 4096 Feb 7 23:53 wordpress
2殴瘦、隨后復制解壓縮的wordpress目錄到/var/www/html目錄下:
[root@localhost ~]# cp wordpress /var/www/html/
3、此時通過訪問URL:http://IP-ADDRESS/wordpress 即可進行到wordpress的配置頁面:
4号杠、為了能讓wordpress正常運行蚪腋,在數(shù)據(jù)庫中創(chuàng)建wordpress數(shù)據(jù)庫以及創(chuàng)建相應的賬號。
[root@localhost ~]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database wordpress; #創(chuàng)建wordpress數(shù)據(jù)庫
Query OK, 1 row affected (0.01 sec)
#創(chuàng)建wordpressuser作為wordpress訪問數(shù)據(jù)庫的賬號
MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wordpressuser'@'192.168.%.%' IDENTIFIED BY "magedu";
Query OK, 0 rows affected (0.00 sec)
為了保證能正常登陸姨蟋,建議修改/etc/my.conf文件添加下面語句并重啟mariadb服務:
[root@localhost ~]# vim /etc/my.cnf
skip-name-resolve=ON #跳過域名解析屉凯,此方法僅適用于centos7;
[root@localhost ~]# systemctl restart mariadb
5眼溶、返回頁面悠砚,繼續(xù)完成wordpress的初始化操作。
用戶也可以通過參考/var/www/html/wordpress/wp-config-sample.php文件來在命令行創(chuàng)建對應的wp-config.php文件偷仿。
6哩簿、手動創(chuàng)建wp-config.php文件
[root@localhost ~]# vim /var/www/html/wordpress/wp-config.php
<?php
/**
* WordPress基礎(chǔ)配置文件。
*
* 這個文件被安裝程序用于自動生成wp-config.php配置文件酝静,
* 您可以不使用網(wǎng)站,您需要手動復制這個文件羡玛,
* 并重命名為“wp-config.php”别智,然后填入相關(guān)信息。
*
* 本文件包含以下配置選項:
*
* * MySQL設置
* * 密鑰
* * 數(shù)據(jù)庫表名前綴
* * ABSPATH
*
* @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
*
* @package WordPress
*/
// ** MySQL 設置 - 具體信息來自您正在使用的主機 ** //
/** WordPress數(shù)據(jù)庫的名稱 */
define('DB_NAME', 'wordpress');
/** MySQL數(shù)據(jù)庫用戶名 */
define('DB_USER', 'wordpressuser');
/** MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD', 'magedu');
/** MySQL主機 */
define('DB_HOST', '192.168.0.118');
/** 創(chuàng)建數(shù)據(jù)表時默認的文字編碼 */
define('DB_CHARSET', 'utf8mb4');
/** 數(shù)據(jù)庫整理類型稼稿。如不確定請勿更改 */
define('DB_COLLATE', '');
/**#@+
* 身份認證密鑰與鹽薄榛。
*
* 修改為任意獨一無二的字串!
* 或者直接訪問{@link https://api.wordpress.org/secret-key/1.1/salt/
* WordPress.org密鑰生成服務}
* 任何修改都會導致所有cookies失效让歼,所有用戶將必須重新登錄敞恋。
*
* @since 2.6.0
*/
define('AUTH_KEY', '!;#@OR03j87T7qH/WrceNVH%B~>MR/y><8CbXsVG#@GG:l|<0BYx%VD8.+0*m1BA');
define('SECURE_AUTH_KEY', 'BSrmHuvZOZ}Dce&Kb6PzfLVbbs$sU,SG&4/=L}A#|Kv&{k|c@S8]_5p EUoPG%dn');
define('LOGGED_IN_KEY', 'UUVB~DZseI@mF,wJ~Y(vI^m pa-iz)M+I+CKqZzZ((5Q<_/18tz=teL3*5SNGc=*');
define('NONCE_KEY', 's-|wCdb-lE)hW2B~^<S8cczFb{A-5?Vaxwvz$kzt!KqweJ-dDcbAf:r%|}mZM{<]');
define('AUTH_SALT', '| NrJ[5KSpfn|)x@XG^.@Nj6r9Rcj*#GadpN~o_E1^4<]>Nhh[|cZSM8ddlBMSTd');
define('SECURE_AUTH_SALT', 'y;n.E#%[7$!qX1;]Q;u@H_s=A+XpJ[i>u*XLT1!b6)b?spS!finRl@#DRZ<XWYV=');
define('LOGGED_IN_SALT', '%x)I>ZQf)Dwp-!ZeW=}b69f^JLheG;5JGhJNS)t#2YgHf#HX,K:2[D~e3uh,g_(@');
define('NONCE_SALT', 'ZYs]r20xvwor2|3:jgZ@95ZF%eC3P49.V)7{21h9Z?{$eFWFtbN#-(I!y%/*$;%e');
/**#@-*/
/**
* WordPress數(shù)據(jù)表前綴。
*
* 如果您有在同一數(shù)據(jù)庫內(nèi)安裝多個WordPress的需求谋右,請為每個WordPress設置
* 不同的數(shù)據(jù)表前綴硬猫。前綴名只能為數(shù)字、字母加下劃線改执。
*/
$table_prefix = 'wp_';
/**
* 開發(fā)者專用:WordPress調(diào)試模式啸蜜。
*
* 將這個值改為true,WordPress將顯示所有用于開發(fā)的提示辈挂。
* 強烈建議插件開發(fā)者在開發(fā)環(huán)境中啟用WP_DEBUG衬横。
*
* 要獲取其他能用于調(diào)試的信息,請訪問Codex终蒂。
*
* @link https://codex.wordpress.org/Debugging_in_WordPress
*/
define('WP_DEBUG', false);
/**
* zh_CN本地化設置:啟用ICP備案號顯示
*
* 可在設置→常規(guī)中修改蜂林。
* 如需禁用遥诉,請移除或注釋掉本行。
*/
define('WP_ZH_CN_ICP_NUM', true);
/* 好了噪叙!請不要再繼續(xù)編輯矮锈。請保存本文件剔交。使用愉快也拜! */
/** WordPress目錄的絕對路徑烟阐。 */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** 設置WordPress變量和包含文件纵势。 */
require_once(ABSPATH . 'wp-settings.php');
創(chuàng)建完成后返回頁面點擊現(xiàn)在安裝跟压。
7寂汇、隨后會彈出下列界面麻养,按照圖片信息填寫完成后举塔,點擊安裝wordpress壹店。
8猜丹、安裝完成后,用戶可通過訪問地址http://IPaddress/wordpress來訪問博客網(wǎng)站或者訪問http://IPaddress/wordpress/wp-login.php來登錄網(wǎng)站后臺硅卢。
至此射窒,wordpress就安裝完成了,我們就可按照自己的喜好編輯創(chuàng)建自己的博客将塑,發(fā)表文章了脉顿。