在 CentOS 7 平台上以原始碼方式完成 LAMP 環境的編譯安裝。
yum groupinstall "Development Tools" "Server Platform Development"
yum install -y pcre-devel openssl-devel
依賴關係必須按序安裝。先 apr:
tar -xf apr-1.5.0.tar.bz2 cd apr-1.5.0/ ./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/ ./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=prefork make && make install
參數說明:--prefix 指定安裝路徑;--sysconfdir 指定設定檔位置;--enable-so 允許執行期載入 DSO 模組;--enable-ssl 提供 SSL/TLS 加密傳輸;--enable-cgi 支援 CGI;--enable-rewrite 支援 URL 重寫;--with-zlib/--with-pcre 連結壓縮與正則表達式庫;--enable-modules=most 啟用多數常用模組;--enable-mpms-shared=all 編出所有 MPM;--with-mpm=prefork 設預設 MPM。
因為是編譯安裝,啟動需指定完整路徑:
/usr/local/apache/bin/apachectl start
設定開機自啟:
vim /etc/profile.d/httpd.sh export PATH=/usr/local/apache/bin:$PATH . /etc/profile.d/httpd.sh apachectl start


mkdir /mysqldata useradd -r mysql # 建立系統帳號,降低被入侵的風險 chown mysql.mysql /mysqldata/



tar -xf mariadb-5.5.43-linux-x86_64.tar.gz # 必須展開於此目錄 ln -sv mariadb-5.5.43-linux-x86_64 mysql # 必須連結為 mysql cd mysql/ chown -R root.mysql ./*

scripts/mysql_install_db --user=mysql --datadir=/mysqldata cp support-files/my-large.cnf /etc/my.cnf vim /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysqld chkconfig --add /etc/init.d/mysqld systemctl start mysqld


yum install -y libxml2-devel libmcrypt-devel bzip2-devel openssl-devel cd /usr/local tar -xf php-5.4.26.tar.bz2 cd php-5.4.26/
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql \ --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config \ --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-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 make -j 4 && make install
完成後於 Apache 設定中載入 PHP 模組並重啟服務,LAMP 環境即可使用。