1. 程式人生 > 實用技巧 >在centos6.5上編譯安裝LAMP

在centos6.5上編譯安裝LAMP

LAMP組合的編譯安裝

基於centos6.5實現

httpd+php

modulesphp編譯成httpdDSO物件

prefork:libphp5

event,worker:libphp5-zts

cgi

fastcgifpm:php作為獨立的服務

httpdfastcgi協議的支援

httpd-2.2需要額外安裝fcgi模組

httpd-2.4自帶fcgi模組

安裝次序

httpdMariadbphp

安裝開發環境httpd安裝依賴pcre因此要安裝pcre-devel

1.yum groupinstall "Development Tools" "Server Platform Development" -y

yum install pcre-devel -y

2.安裝新版apr

#tar xf apr-1.5.0.tar.bz2

#cd apr-1.5.0

#ls

#./configure --prefix=/usr/local/apr為了防止覆蓋系統已安裝的版本

#make && make install

安裝新版apr-util

#tar xf apr-util-1.5.3.tar.bz2

#cd apr-util-1.5.3

#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

#make && make install

httpd的編譯安裝

#tar xf httpd-2.4.9.tar.bz2

#cd httpd-2.4.9

#groupadd -r apache新增系統組

#useradd -r -g apache apache新增系統使用者

#id apache

注意首先安裝pcre-devel

yum -y install pcre-devel

#./configure --help|less

#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event

注意--sysconfdir=/etc/httpd24預設配置檔案目錄

--prefix=/usr/local/apache預設安裝目錄

wKiom1gWBESyeM4fAATIgnoFefQ062.png

#make && make install

#cd /etc/rc.d/init.d/

發現/etc/rc.d/init.d/下沒有httpd這個檔案執行rpm -q httpd命令提示package httpd is not installed即需要安裝httpd包執行yum install httpd* -y

#cp httpd httpd24

#vim httpd24

wKioL1gWBG_CtQ81AADbQcZgKF8284.png

將上如中的引數修改如下

wKioL1gWBHyyO3FpAADx6tCmTq8462.png

chkconfig --add httpd24

chkconfig --list httpd24

chkconfig httpd24 on

啟動服務

/usr/local/apache/bin/apachectl

提示錯誤

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message

解決辦法

如果想使用apachectl啟動服務需要

vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH

./etc/profile.d/httpd.sh重讀配置檔案

echo $PATH

httpd -t

提示錯誤httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName

Syntax OK

解決辦法

wKiom1gWBIuDN2WBAAATdzfhgfY383.png

hash -r

service httpd start

ss -tnl

ps aux|grep httpd驗證是否執行event程序

wKioL1gWBJ6QUIKdAAAXvp1G9iU597.png

檢視80埠是否被佔用ss -tnl

關閉selinux

如果訪問不了清空一下訪問規則

iptables -L -n

iptables -F

setenforce 0

service httpd start

httpd -M 檢視裝載的模組

cd /etc/httpd24目錄

vim httpd.conf下啟用或禁用某一模組

wKioL1gWBLDSGwckAAKV3zwOh-0332.png

wKiom1gWBLzSGjcAAABFvoypByk667.png

3.安裝mariadbl

#tar xf mariadb-5.5.36-linux-i686.tar.gz -C /usr/local

#mkdir -pv /mydata/data

#useradd -r mysql

#chown -R mysql.mysql /mydata/data/

#cd /usr/local

# ln -sv mariadb-5.5.36-linux-i686 mysql

#cd mysql

#chown -R root.mysql ./*

#

#[[email protected] mysql]#scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql 初始化操作

提示錯誤-bash: scripts/mysql_install_db: No such file or directory

解決辦法

發現先前安裝的mariadb版本為mariadb-10.0.13.tar換包。

#mkdir /etc/mysql

#cp support-files/my-large.cnf /etc/mysql/my.cnf

#vim /etc/mysql/my.cnf

wKiom1gWBMnh8GErAADwsZjmyhY800.png

#cp support-files/mysql.server /etc/rc.d/init.d/mysqld

#chkconfig --add mysqld

#service mysqld start

wKioL1gWBNeRVfenAAAJJB9NvhA688.png

#ss -tnl

wKioL1gWBOTwzYxsAAAd6XNuCdI060.png

#/usr/local/mysql/bin/mysql

# mysql_secure_installation安全初始化(方法)

提示-bash: mysql_secure_installation: command not found

解決辦法

#yum install mysql* -y

再次執行mysql_secure_installation

4.安裝phpl

#cd /mnt

#tar xf php-5.4.26.tar.bz2

# cd php-5.4.26

解決依賴關係

請配置好yum源系統安裝源及epel源後執行如下命令

yum -y groupinstall Desktop Platform Development

yum -y install bzip2-devel libmcrypt-devel libxml2-devel

編譯安裝php-5.4.26

首先下載原始碼包至本地目錄

tar xf php-5.4.26

cd php-5.4.26

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysql=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freeytpe-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts

報錯

configure: error: xml2-config not found. Please check your libxml2 installation.

解決辦法yum install libxml2-devel -y

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解決辦法yum install libmcrypt libmcrypt-devel mcrypt mhash -y

configure: error: Cannot find MySQL header files under /usr/local/mysql/bin/mysql_config

Note that the MySQL client library is not bundled anymore!

解決辦法

--with-mysql=/usr/local/mysql/bin/mysql_config改為--with-mysql

wKiom1gWBQrwEvRdAABGlOfF-rE635.png

make && make install

-z多啟用幾個執行緒

說明

這裡為了支援apacheworkerevent這兩個MPM編譯時使用了--enable-maintainer-zts選項。

如果視訊PHP5.3以上版本為了連線MySQL資料庫可以指定mysqlnd這樣在本機就不需要先安裝MySQLMySQL開發包了。mysqlndphp5.3開始可用可以編譯時繫結到它而不用和具體的MySQL客戶端繫結形成依賴但從PHP5.4開始它就是預設設定了。

php提供配置檔案

cp php.ini-production /etc/php.ini

wKiom1gWBRii3aRqAABbjWkYD0Y337.png

問題service httpd24 reload

Reloadinghttpd: [FAILED]

解決辦法

修改httpd.pid的位置

wKioL1gWBSzwddpoAAAMSCZ1LH0857.png

vim /etc/rc.d/init.d/httpd24

wKioL1gWBTjx49xCAAAey9EsofE888.png

改為

wKiom1gWBULxvu09AAAfUNF5nj8790.png

3.編輯apache配置檔案httpd.conf,apache支援php

cd /etc/httpd24

cp httpd.conf{,.bak}

vim httpd.conf.bak

首先確保

wKioL1gWBUvh8iNCAAArVX_YQUA893.png

其次新增如下兩行

AddType application/x-httpd-php.php

AddType application/x-httpd-php-spurce.phps

定位至DirectoryIndex index.html

修改為:

DirectoryIndexindex.phpindex.html

而後重新啟動httpd或讓其重新載入配置檔案即可測試php是否已經可以正常使用。

wKioL1gWBVbw6ArRAAAldo_If8o726.png

cd /usr/local/apache/

cd htdocs/

mv index.html index.php

vim index.php

測試頁面index.php示例如下

<?php

$conn = mysql_connect('127.0.0.1','root','beijing');

if($conn)

echo "ok";

else

echo "Failure";

mysql_close();

phpinfo();

?>

wKiom1gWBWTCwUGCAACcKxjRAkM139.png


轉載於:https://blog.51cto.com/654057524/1867465