Linux CentOS 6.5 + Apache + Mariadb + PHP环境搭建
Web自動(dòng)化測(cè)試-服務(wù)端測(cè)試環(huán)境部署
?
by:授客
目錄
一、???????? 安裝數(shù)據(jù)庫(kù)... 2
二、???????? 數(shù)據(jù)庫(kù)配置... 2
三、???????? 創(chuàng)建數(shù)據(jù)庫(kù)及數(shù)據(jù)表... 2
四、???????? 插入基礎(chǔ)數(shù)據(jù)... 5
五、???????? 安裝Apache. 5
六、???????? 配置與啟動(dòng)Apache. 6
七、???????? 安裝php. 7
八、???????? 配置php. 9
九、???????? 部署php代碼文件... 10
十、???????? 安裝及配置vsftpd服務(wù)器... 12
?
?
操作系統(tǒng)環(huán)境:CentOS 6.5-x86_64
下載地址:http://www.centoscn.com/CentosSoft/iso/2013/1205/2196.html
注:安裝時(shí)選擇以Basic Server的方式安裝
?
Mariadb下載地址
http://mirrors.opencas.cn/mariadb/mariadb-5.5.45/yum/centos6-amd64/rpms/
?
Apache下載地址
http://httpd.apache.org/download.cgi#apache24
?
pcre下載地址
http://pcre.org/
?
apr下載地址
http://mirrors.cnnic.cn/apache/apr/
?
apr-util下載地址
http://mirrors.cnnic.cn/apache/
?
libxml2下載地址
http://download.chinaunix.net/download/0007000/6095.shtml
?
php下載地址
http://php.net/downloads.php#v5.6.12
?
?
文件列表如下:
?
?
網(wǎng)盤統(tǒng)一下載地址:http://pan.baidu.com/s/1sj1Lzw5
?
?
一、安裝數(shù)據(jù)庫(kù)
安裝Mysql、Mariadb(筆者選擇安裝的是Mariadb 5.5.45
?
需要下載的rpm包如下
[root@localhost mnt]# ls | grep rpm
MariaDB-5.5.45-centos6-x86_64-client.rpm
MariaDB-5.5.45-centos6-x86_64-common.rpm
MariaDB-5.5.45-centos6-x86_64-compat.rpm
MariaDB-5.5.45-centos6-x86_64-devel.rpm
MariaDB-5.5.45-centos6-x86_64-server.rpm
MariaDB-5.5.45-centos6-x86_64-shared.rpm
MariaDB-5.5.45-centos6-x86_64-test.rpm
?
安裝Mariadb
[root@localhost mnt]# rpm -iUvh MariaDB-*.rpm
?
二、數(shù)據(jù)庫(kù)配置
?
參考文章“MariaDB?Centos7?下安裝MariaDB”
?
?
三、創(chuàng)建數(shù)據(jù)庫(kù)及數(shù)據(jù)表
建庫(kù):
CREATE DATABASE `1dcq`
?
建表:
CREATE TABLE `pagesobject` (
? `Id` int(11) NOT NULL AUTO_INCREMENT,
? `P_Id` int(11) DEFAULT NULL,
? `PageName` varchar(255) NOT NULL DEFAULT '',
? `Html_open` varchar(10) DEFAULT 'true',
? `PageDesc` varchar(100) DEFAULT NULL,
? `isParent` tinyint(2) DEFAULT NULL COMMENT '如果是0表示文件夾,是1表示1個(gè)頁(yè)面',
? PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=257 DEFAULT CHARSET=utf8
?
?
CREATE TABLE `page_elements` (
? `Id` int(11) NOT NULL AUTO_INCREMENT,
? `PageId` smallint(6) DEFAULT NULL,
? `FieldOrder` int(11) DEFAULT NULL,
? `ElementName` varchar(100) DEFAULT NULL,
? `ElementSelector` varchar(300) DEFAULT NULL,
? `ElementSelector02` varchar(300) DEFAULT NULL,
? PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8
?
CREATE TABLE `runtptask` (
? `runClientId` int(11) NOT NULL AUTO_INCREMENT,
? `tpid` varchar(11) DEFAULT NULL,
? `isRunning` int(11) unsigned zerofill DEFAULT '00000000000',
? `runClientPCName` varchar(100) DEFAULT NULL,
? `runClientPCIP` varchar(50) DEFAULT NULL,
? `lastRunTime` datetime DEFAULT NULL,
? PRIMARY KEY (`runClientId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
?
CREATE TABLE `testcases` (
? `id` int(11) NOT NULL AUTO_INCREMENT,
? `p_id` int(11) NOT NULL,
? `test_name` varchar(255) NOT NULL DEFAULT '',
? `Html_open` varchar(10) DEFAULT 'true',
? `checked` varchar(8) DEFAULT NULL,
? `testModule_name` varchar(255) NOT NULL DEFAULT '',
? `test_desc` varchar(255) DEFAULT NULL,
? `testdataParas` varchar(255) DEFAULT NULL,
? `testdata_isexist` varchar(10) DEFAULT NULL,
? `isTestCase` tinyint(1) DEFAULT '0',
? `compFolderid` int(11) DEFAULT NULL,
? PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
?
CREATE TABLE `testcases_steps` (
? `Id` int(11) NOT NULL AUTO_INCREMENT,
? `TestcaseID` varchar(100) DEFAULT NULL,
? `ElementId` varchar(50) DEFAULT NULL,
? `Command` varchar(255) DEFAULT NULL,
? `InParas` varchar(255) DEFAULT NULL,
? `OutParas` varchar(255) DEFAULT NULL,
? `StepOrder` int(11) DEFAULT NULL,
? `compFolderid` int(11) DEFAULT NULL COMMENT '測(cè)試步驟中插入的操作組件的父級(jí)id',
? `compid` int(11) DEFAULT NULL COMMENT '測(cè)試步驟中插入的操作組件的id',
? PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=679 DEFAULT CHARSET=utf8
?
CREATE TABLE `tc_ele_command` (
? `id` int(11) NOT NULL AUTO_INCREMENT,
? `commandName` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
? `commandPara` varchar(60) CHARACTER SET utf8 DEFAULT NULL,
? PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
?
CREATE TABLE `testcase_runround` (
? `id` int(255) NOT NULL AUTO_INCREMENT,
? `test_round_name` varchar(255) DEFAULT NULL,
? `testset_list` varchar(255) DEFAULT NULL,
? `tcfolder_tc_list` varchar(2000) DEFAULT NULL,
? `testcase_list` varchar(1000) DEFAULT NULL,
? `round_desc` varchar(25) DEFAULT NULL,
? `testplan_file` varchar(255) DEFAULT NULL,
? `runningTestPlanUrl` varchar(100) DEFAULT NULL,
? `browserRuningDrivers` varchar(20) DEFAULT NULL,
? `latelyRuningTime` datetime DEFAULT NULL,
? `onlyOneRuning_tc_list` varchar(255) DEFAULT NULL,
? `project_name` varchar(255) DEFAULT NULL,
? `project_version` varchar(255) DEFAULT NULL,
? `project_id` varchar(255) DEFAULT NULL,
? PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
?
?
CREATE TABLE `testreporter` (
? `Id` int(11) NOT NULL AUTO_INCREMENT,
? `testplanId` varchar(255) NOT NULL DEFAULT '',
? `testcaseList` varchar(255) DEFAULT NULL,
? `testcasedataGroup` tinyint(3) DEFAULT NULL COMMENT '--無(wú)用列',
? `tpRunedtcs` varchar(100) DEFAULT NULL COMMENT '此輪執(zhí)行的測(cè)試用例',
? `tpRunnedHistoryId` bigint(50) DEFAULT NULL COMMENT '運(yùn)行歷史id,后續(xù)自動(dòng)清除大于2天的報(bào)告',
? `onTime` datetime DEFAULT NULL COMMENT '發(fā)生的時(shí)間',
? PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
?
?
CREATE TABLE `tprunnedhistory` (
? `id` int(11) NOT NULL AUTO_INCREMENT,
? `tpId` varchar(255) DEFAULT NULL,
? `tpRunnedHistoryId` bigint(50) DEFAULT NULL,
? `willRunningTestcaseList` varchar(1000) DEFAULT NULL,
? `runPassedTc_count` int(11) DEFAULT '0',
? `runPassedTc` varchar(1000) DEFAULT '',
? `runFailedTc` varchar(1000) DEFAULT '',
? `tpRunnedHistoryNotes` varchar(100) DEFAULT NULL,
? `onTime` datetime DEFAULT NULL,
? PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
?
CREATE TABLE `tcrunnedhistory` (
? `id` int(11) NOT NULL AUTO_INCREMENT,
? `tpId` varchar(255) DEFAULT NULL,
? `tpRunnedHistoryId` bigint(50) DEFAULT NULL,
? `willRunningTestcaseList` varchar(1000) DEFAULT NULL,
? `runPassedTc_count` int(11) DEFAULT '0',
? `runPassedTc` varchar(1000) DEFAULT '',
? `runFailedTc` varchar(1000) DEFAULT '',
? `tpRunnedHistoryNotes` varchar(100) DEFAULT NULL,
? `onTime` datetime DEFAULT NULL,
? PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8
?
四、插入基礎(chǔ)數(shù)據(jù)
INSERT INTO `pagesobject`(P_id, test_name) VALUES(1, '根目錄');
?
INSERT INTO `testcases`(p_id, test_name) VALUES(0, '根目錄');
?
?
五、安裝Apache
安裝gcc-c++
[root@localhost mnt]# yum install gcc-c++
?
安裝apr
[root@localhost mnt]# tar -xvzf apr-1.5.2.tar.gz
[root@localhost mnt]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.5.2]# make && make install
?
安裝apr-util
[root@localhost mnt]# tar -xvzf apr-util-1.5.4.tar.gz
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.5.4]# make && make install
?
?
安裝pcre
[root@localhost mnt]# tar -xvzf pcre-8.36.tar.gz
[root@localhost mnt]# cd pcre-8.36
[root@localhost pcre-8.36]# ./configure --prefix=/usr/local/pcre
……
[root@localhost pcre-8.36]#make && make install
?
安裝Apache
[root@localhost tmp]# tar -xzvf httpd-2.4.16.tar.gz
[root@localhost tmp]# cd httpd-2.4.16
[root@localhost httpd-2.4.16]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr? --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
[root@localhost httpd-2.4.16]# make && make install
?
?
可在httpd.conf中進(jìn)行一些自定義配置
[root@localhost httpd-2.4.16]# vim /usr/local/apache/conf/httpd.conf
?
?
六、配置與啟動(dòng)Apache
編輯httpd.conf,設(shè)置'ServerName':把ServerName www.example.com:80改成自己需要的(可先注釋,然后新增一行
[root@localhost httpd-2.4.16]# vim /usr/local/apache/conf/httpd.conf
?
?
如果未配置,啟動(dòng)時(shí)會(huì)報(bào)如下錯(cuò)誤:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
?
啟動(dòng)
[root@localhost httpd-2.4.16]# /usr/local/apache/bin/apachectl -k start
?
注:停止Apache
[root@localhost httpd-2.4.16]# /usr/local/apache/bin/apachectl -k stop
?
防火墻開放80端口
[root@localhost tmp]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost tmp]# services iptables save
-bash: services: command not found
[root@localhost tmp]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[? OK? ]
[root@localhost tmp]# service iptables reload
iptables: Trying to reload firewall rules:???????????????? [? OK? ]
注意:不開放端口的話,訪問(wèn)http://192.168.30.80,可能會(huì)訪問(wèn)不了
?
瀏覽器訪問(wèn)http://192.168.30.80,可以訪問(wèn)了,OK
?
參考連接:
http://httpd.apache.org/docs/current/
?
七、安裝php
安裝函數(shù)依賴模塊
[root@localhost tmp]# rpm -iUvh php-common-5.3.3-40.el6_6.x86_64.rpm
warning: php-common-5.3.3-40.el6_6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...??????????????? ########################################### [100%]
?? 1:php-common???????????? ########################################### [100%]
[root@localhost tmp]# rpm -iUvh php-mbstring-5.3.3-40.el6_6.x86_64.rpm
warning: php-mbstring-5.3.3-40.el6_6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...??????????????? ########################################### [100%]
?? 1:php-mbstring?????????? ########################################### [100%]
[root@localhost tmp]#
?
安裝libxml2
[root@localhost mnt]# tar -xvzf libxml2-2.6.27.tar.gz
[root@localhost mnt]# cd libxml2-2.6.27
[root@localhost libxml2-2.6.27]# ./configure --prefix=/usr/local/libxml12
[root@localhost libxml2-2.6.27]# make && make install
?
注:
1.如果mysql是源碼包安裝的,加--with-mysql=mysql_installation_path
2.如果未安裝libxml2,可能報(bào)如下錯(cuò)誤:
configure: error: xml2-config not found. Please check your libxml2 installation.
?
安裝php
[root@localhost mnt]# tar -xvzf php-5.6.12.tar.gz
[root@localhost tmp]#cd php-5.6.12
[root@localhost php-5.6.12]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml12/ --with-mysql --enable-mbstring=all
?
注:
1、如果mysql是以rpm寶的形式安裝的,直接--with-mysql,如果是源碼包安裝的,--with-mysql=mysql_installation_path,,筆者實(shí)踐發(fā)現(xiàn),沒(méi)加--with-mysql,安裝后不能加載mysql.dll
2、帶--enable-mbstring=all是因?yàn)樘峁?/span>PHP框架需要使用該模塊
?
?
說(shuō)明:編譯php時(shí),可能還會(huì)遇到如下錯(cuò)誤
Sorry, I cannot run apxs. ***
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
?
解決方法:將apxs所在目錄(例中為/usr/local/apache/bin/)添加到PATH環(huán)境變量,并使環(huán)境變量生效即可。
?
?
八、配置php
[root@localhost php-5.6.12]# cp php.ini.dist /usr/local/php/lib/php.ini
注:如果沒(méi)有php.ini.dist 則把php.ini-development php.ini-production中的任何一個(gè)重命名為php.ini.dist即可
?
配置 httpd.conf 讓apache支持PHP
# vim /usr/local/apache/conf/httpd.conf
?
找到 AddType application/x-gzip .gz .tgz ,然后添加如下帶背景顏色的內(nèi)容(.前面有空格)
?
#################Added by laiyu##################
??? AddType application/x-httpd-php .php
??? AddType application/x-httpd-php-source .phps
??? #################################################
??? #AddType application/x-gzip .tgz
?
修改改配置文件php.ini?
首先要確保php.ini中extension_dir 為php擴(kuò)展所在目錄,然后找到如下內(nèi)容
;extension=php_mysql.dll
;extension=php_mysqli.dll
?
把前面的分號(hào)去掉,改成如下,保存,重啟Apache:
extension=php_mysql.dll
extension=php_mysqli.dll
?
注意:如果這里不修改,可能會(huì)導(dǎo)致無(wú)法連接mysql,類似如下,查看apahce日志,
[root@localhost logs]# cat error.log
[Sat Aug 22 01:11:50.502345 2015] [:error] [pid 28567:tid 140674563237632] [client 192.168.40.74:64189] PHP Fatal error:? Call to undefined function mysql_connect() in /usr/local/apache/htdocs/1dcq/connect.php on line 9, referer: http://192.168.40.80/1dcq/framework/pagesObject.php
?
?
找到如下代碼,去掉前面的分號(hào),即取消注釋,加載該模塊。
; extension=php_mbstring.dll
?
找到display_errors = On,修改為display_errors = Off
?
重啟Apache
[root@localhost php-5.6.12]# /usr/local/apache/bin/apachectl stop
[root@localhost php-5.6.12]# /usr/local/apache/bin/apachectl start
?
測(cè)試php是否成功安裝
寫一個(gè)php測(cè)試頁(yè)info.php,放到Apache的htdocs目錄下。
?
?
在瀏覽器中輸入:服務(wù)器地址/info.php,如:http://192.168.30.80/info.php
如果可看到php版本,系統(tǒng)等相關(guān)信息則表示成功了
?
?
?
參考連接:
http://php.net/manual/zh/install.unix.apache.php
?
九、部署php代碼文件
安裝好后,可以把PHP代碼“framework.zip”解壓源碼“framework.zip”解壓,放入到/usr/local/apache/htdocs/目錄下,編輯connect.php,進(jìn)行相關(guān)配置
[root@localhost tmp]# unzip framework.zip
[root@localhost tmp]# mv 1dcq/ /usr/local/apache/htdocs/
?
訪問(wèn)查看
?
轉(zhuǎn)載于:https://www.cnblogs.com/shouke/p/10157846.html
總結(jié)
以上是生活随笔為你收集整理的Linux CentOS 6.5 + Apache + Mariadb + PHP环境搭建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Repeater的使用
- 下一篇: 【Python web 开发】views