一、安裝php,mysql
二、相關配置文件
三、啓動httpd,測試php連接
四、測試php連接mysql
五、安裝wordpress
生產環境需要編譯安裝,下次博客再更新
一、安裝php,mysql
yum install -y php
如果沒有安裝httpd,使用yum源安裝php時會一併安裝
安裝mysql服務端和客戶端,另外mysql與php通信,需要安裝php-mysql程序包
[root@test3 html]# yum install -y mysql mysql-server php-mysql [root@test3 html]# chkconfig --list mysqld mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@test3 html]# chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@test3 html]# chkconfig mysqld on [root@test3 html]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
二、相關配置文件
1、php
安裝完成後其主配置文件爲/etc/php.ini
和apache結合起來工作,配置文件/etc/httpd/conf.d/php.conf
2、httpd
主配置文件/etc/httpd/conf/httpd.conf
三、啓動httpd,測試php連接
1、啓動httpd服務
[root@test3 vsftpd]# service httpd start Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 211.139.136.73 for ServerName [ OK ]
如果有上述提示,則在/etc/httpd/conf/httpd.conf中添加一行
ServerName localhost:80 #這裏的localhost可以是主機名和IP
2、配置文件
(1)、編輯/etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html index.html.var 添加index.php
(2)、在/var/www/html/下新建index.php文件,編輯index.php,內容如下
<h1>host1</h1> <?php phpinfo(); ?>
在瀏覽器中輸入主機地址,此時訪問成功
四、測試php連接mysql
1、mysql相關
服務文件:/etc/init.d/mysqld
啓動服務:service mysqld start 或/etc/init.d/mysqld start,第一次啓動會初始化,mysql監聽在tcp/3306端口
客戶端執行程序:mysql
默認用戶:root,密碼爲空
2、基礎命令:
(1)、服務端命令,命令末尾需要分號
SHOW DATABASES:顯示有權限訪問的所有數據庫
SELECT DATABASE():顯示當前默認數據庫
CREATE DATABASE DB_NAME:創建名爲DB_NAME的數據庫,創建的數據庫文件目錄在/var/lib/mysql/
DROP DATABASE DB_NAME:刪除名爲DB_NAME的數據庫
(2)、客戶端命令,命令末尾不需要分號
USE DB_NAME:設置DB_NAME爲默認數據庫
3、測試php連接mysql
編輯/var/www/html/index.php,內容如下,保存退出後,重載httpd
<h1>host1</h1> <?php $link=mysql_connect(localhost,root,''); #執行函數返回值mysql_connect(localhost,"root",)存儲在變量$link中 if ($link) echo "Sueccess."; else echo "Failure."; ?>
瀏覽器地址欄輸入主機地址,顯示如下信息則說明php成功連接mysql
關掉mysqld服務,再次測試
五、安裝wordpress
LAMP環境,常見開源應用:
wordpress,discuz,phpwind,phpbb,drupal,joomla
這裏我們安裝wordpress
1、下載wordpress
[root@test3 ~]# wget https://cn.wordpress.org/wordpress-4.2-zh_CN.zip [root@test3 ~]# ls anaconda-ks.cfg install.log.syslog wordpress-4.2-zh_CN.zip install.log
2、將wordpress所有文件放到httpd工作目錄
[root@test3 ~]# ls anaconda-ks.cfg install.log.syslog wordpress install.log wordpress-4.2-zh_CN [root@test3 ~]# tar -cf html.tar /var/www/html/* #有需要可以先備份下站點目錄中的文件 tar: Removing leading `/' from member names [root@test3 ~]# ls anaconda-ks.cfg install.log wordpress-4.2-zh_CN.ziphtml.tar install.log.syslog wordpress [root@test3 ~]# tar -tvf html.tar #查看歸檔文件內容 -rw-r--r-- root/root 85 2015-05-16 18:00 var/www/html/index.html -rw-r--r-- root/root 122 2015-05-17 23:20 var/www/html/index.php [root@test3 ~]# rm /var/www/html/* –f #清空站點目錄中的內容 [root@test3 ~]# ls /var/www/html/ [root@test3 ~]# mv wordpress/* /var/www/html/ #將wordpress中的文件移到站點目錄 [root@test3 ~]# ls /var/www/html/ index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
然後可以使用瀏覽器連接,連接成功,會提示我們需要做些準備工作
3、完成簡單的準備工作
(1)、連上mysql,創建數據庫
mysql> CREATE DATABASE wpdb; Query OK, 1 row affected (0.00 sec)
(2)、修改配置文件
[root@test3 html]# cp wp-config-sample.php wp-config.php [root@test3 html]# vim wp-config.php #編輯配置文件 // ** MySQL 設置 - 具體信息來自您正在使用的主機 ** // /** WordPress數據庫的名稱 */ define('DB_NAME', 'wpdb'); /** MySQL數據庫用戶名 */ define('DB_USER', 'root'); /** MySQL數據庫密碼 */ define('DB_PASSWORD', ''); /** MySQL主機 */ define('DB_HOST', 'localhost'); /** 創建數據表時默認的文字編碼 */ define('DB_CHARSET', 'utf8'); /** 數據庫整理類型。如不確定請勿更改 */ define('DB_COLLATE', '');
再次刷新瀏覽器,出現下圖信息,說明已經成功在LAMP環境下安裝了wordpress