在centos6.5上編譯安裝LAMP
LAMP組合的編譯安裝
基於centos6.5實現
httpd+php
modules把php編譯成httpd的DSO物件
prefork:libphp5
event,worker:libphp5-zts
cgi
fastcgifpm:php作為獨立的服務
httpd對fastcgi協議的支援
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預設安裝目錄
#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
將上如中的引數修改如下
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
解決辦法
hash -r
service httpd start
ss -tnl
ps aux|grep httpd驗證是否執行event程序
檢視80埠是否被佔用ss -tnl
關閉selinux
如果訪問不了清空一下訪問規則
iptables -L -n
iptables -F
setenforce 0
service httpd start
httpd -M 檢視裝載的模組
cd /etc/httpd24目錄
vim httpd.conf下啟用或禁用某一模組
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
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chkconfig --add mysqld
#service mysqld start
#ss -tnl
#/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
make && make install
用-z多啟用幾個執行緒
說明
這裡為了支援apache的worker或event這兩個MPM編譯時使用了--enable-maintainer-zts選項。
如果視訊PHP5.3以上版本為了連線MySQL資料庫可以指定mysqlnd這樣在本機就不需要先安裝MySQL或MySQL開發包了。mysqlnd從php5.3開始可用可以編譯時繫結到它而不用和具體的MySQL客戶端繫結形成依賴但從PHP5.4開始它就是預設設定了。
為php提供配置檔案
cp php.ini-production /etc/php.ini
問題service httpd24 reload
Reloadinghttpd: [FAILED]
解決辦法
修改httpd.pid的位置
vim /etc/rc.d/init.d/httpd24
改為
3.編輯apache配置檔案httpd.conf,以apache支援php
cd /etc/httpd24
cp httpd.conf{,.bak}
vim httpd.conf.bak
首先確保
其次新增如下兩行
AddType application/x-httpd-php.php
AddType application/x-httpd-php-spurce.phps
定位至DirectoryIndex index.html
修改為:
DirectoryIndexindex.phpindex.html
而後重新啟動httpd或讓其重新載入配置檔案即可測試php是否已經可以正常使用。
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();
?>
轉載於:https://blog.51cto.com/654057524/1867465