編譯安裝LAMP
(centos7 基于模塊化)
編譯安裝所需版本
Httpd 2.4,PHP 5.4,MariaDB 5.5通用二進制格式(綠色安裝包)
MAriDB5.5 綠色安裝
1、#mkdir lamp :創建一個文件夾,存放軟件的版本
2、從官網上下載httpd2.4 mariaDb 5.5 PHP 5.4到該文件夾下
3、# tar xvf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
[root@centos7 local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql (創建一個軟連接,后期更新版本直接下載一個新的版本放在該目錄下,直接把軟連接(mysql)對應新的版本。直接升級
#新建MySQL用戶,
#useradd -s /sbin/nogin -M mysql
# cd /usr/local/mysql/
[root@centos7 mysql]# chown -R root:mysql ./*(點/*) 更改屬主 輸組
#新建存放數據的目錄
[root@centos7 mysql]# mkdir -pv /data/mysql
[root@centos7 mysql]# chown -R mysql:mysql /data/mysql/
[root@centos7 mysql]# mkdir /etc/mysql
[root@centos7 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
#添加以下配置文件
vim /etc/mysql/my.cnf
在這個位置下面進行添加

datadir = /data/mysql
skip_name_resolve = ON
innodb_file_per_table = ON
[root@centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld 拷貝啟動腳本到/etc下
[root@centos7 mysql]# ll /etc/init.d/mysqld
-rwxr-xr-x. 1 root root 12196 Nov 8 09:36 /etc/init.d/mysqld
[root@centos7 mysql]# chkconfig –add mysqld (加入開機啟動,設置與不設置都無所謂)
[root@centos7 mysql]# mv /etc/my.cnf /etc/my.cnf.bak(之前安裝過mysql需要修改,第一次安裝不需要做任何修改)
必須在當前mysql目錄下
[root@centos7 scripts]# ./scripts/mysql_install_db –user=mysql –datadir=/data/mysql/ (對數據初始化)
啟動MySQL
# systemctl mysqld start
提示顯示正確Starting MySQL.. SUCCESS!
[root@centos7 mysql]# netstat -antlp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 18586/mysqld
安裝httpd
準備工作
安裝開發組包及相應的工具包
[root@www ~]# yum groupinstall “Development Tools” “Server Platform Development” –y
安裝PCRE
[root@www httpd-2.4.10]# yum install pcre-devel –y
安裝apr-devel apr-util-devel openssl-devel
yum install apr-devel
yum install apr-util-devel
yum install openssl-devel
也可以編譯安裝apr和apr-util
(1)apr
#./configure –prefix=/usr/locaapr
#make && make install
(2) apr-util
#./configure –prefix=/usr/local/apr-util –with=/usr/local/apr
#make && make install
編譯安裝Httpd
#cd / lamp
#tar xvf httpd-2.4………..
#cd httpd 2.4
[root@www httpd-2.4.10]# ./configure –prefix=/usr/local/apache24(安裝路徑,sysconf配置文件路徑) –enable-so –enable-ssl –enable-rewrite –with-zlib –with-pcre –with-apr=/usr
–with-apr-util=/usr –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork
也可以直接直接輸入 ./configure –prefix=/usr/local/apache24
(默認是Mod模塊化安裝也可以使用enable/factcgi的方式 –enable-ssl 后面添加–enable– cgi)
[root@www httpd-2.4.10]# make -j 2&& make install
啟動Httpd 2.4
[root@www apache24]# /usr/local/apache24/bin/apachectl start
[root@www apache24]# netstat -antlp | grep 80
tcp 0 0 :::80 :::* LISTEN 42294/httpd
在配置文件里面添加配置識別PHP (配置文件的尾部進行編譯 注:在編譯完php再操作)
#vim /usr/local/apache24/conf/httpd.d
AddType application/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.html index.php (添加一個首頁)
</IfModule>
新建phpinfo頁面
#vim /usr/local/apache24/htdocs/test.php
<?php
phpinfo();
?>
重啟下apache
# /usr/local/apache24/bin/apachectl start
#編譯安裝PHP 5.4.40
[root@centos7 lamp]# tar xvf php-5.4.40.tar.bz2
#安裝依賴包
[root@centos7 lamp]# yum install libxml2-devel libmcrypt-devel(該包需要elep源才能安裝) bzip2-devel curl-devel (需安裝這個幾個httpd自帶開發包)
#./configure — help (查看需要編譯的程序,生產中自定義安裝)
]#./configure –prefix=/usr/local/php
–with-mysql=/usr/local/mysql –with-openssl –with-mysqli=/usr/local/mysql/bin/mysql_config
–enable-mbstring –with-freetype-dir –with-jpeg-dir –with-png-dir
–with-zlib –with-libxml-dir=/usr –enable-xml
–enable-sockets –with-apxs2=/usr/local/apache24/bin/apxs
–with-mcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d
–with-bz2 –enable-maintainer-zts –with-curl
這里為了支持apache的worker或event這兩個MPM,編譯時使用了–enable-maintainer-zts選項。
[root@centos7 lamp]#make -j 4 && make install
#此種模式是編譯成httpd模塊的形式,所以編譯完畢并不需要啟動php服務,只需要httpd能識別到即可
編譯安裝LAMP正式完成了 可以通過本主機IP/test.php測試下,可以看到php的頁面了
#wget 后面跟路徑:可以直接下載到主機中
原創文章,作者:fujunlong,如若轉載,請注明出處:http://www.www58058.com/76011