LAMP(Linux + Apache + MySQL + PHP)是經典開源 Web 棧。本文記錄在 CentOS/RHEL 類系統上從源碼編譯安裝全過程,含關鍵配置參數、SELinux 處理、環境變數註冊與 WordPress 部署驗證。
setenforce 0(永久修改 /etc/selinux/config)yum groupinstall "Development Tools"yum install openssl-devel pcre-devel libxml2-devel bzip2-devel curl-devel libpng-devel libjpeg-devel freetype-develtar jxf httpd-2.2.17.tar.bz2
cd httpd-2.2.17
./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd \
--enable-so \
--enable-modules=most \
--enable-mods-shared=most \
--enable-rewrite \
--enable-ssl
make && make install
關鍵參數:--enable-so 載入動態模組(PHP 需用),--enable-ssl 支援 HTTPS。
註冊系統服務:
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd chmod +x /etc/init.d/httpd chkconfig --add httpd chkconfig httpd on
環境變數與庫路徑:
echo 'export PATH=$PATH:/usr/local/apache/bin' >> /etc/profile source /etc/profile ln -sv /usr/local/apache/include /usr/include/httpd echo '/usr/local/apache/lib' > /etc/ld.so.conf.d/httpd.conf ldconfig -v
tar zxf mysql-5.1.50-linux-i686-glibc23.tar.gz -C /usr/local/ cd /usr/local ln -s mysql-5.1.50-linux-i686-glibc23 mysql groupadd mysql useradd -g mysql mysql cd mysql chown -R mysql . chgrp -R mysql . scripts/mysql_install_db --user=mysql chown -R root . chown -R mysql data bin/mysqld_safe --user=mysql &
同樣註冊 PATH、include、lib、man 至系統。
tar jxf php-5.3.5.tar.bz2
cd php-5.3.5
./configure --prefix=/usr/local/php5 \
--sysconfdir=/etc/php5 \
--with-mysql=/usr/local/mysql \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-mbstring=all \
--with-xml \
--with-png \
--with-jpeg \
--with-freetype \
--with-zlib \
--with-curl \
--enable-sockets
make && make test && make install
cp php.ini-production /usr/local/php5/lib/php.ini
編輯 /etc/httpd/httpd.conf:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps DirectoryIndex index.php index.html index.htm AddHandler php5-script .php
重啟 Apache:service httpd restart
echo '' > /usr/local/apache/htdocs/index.php # 瀏覽器訪問 https://server_ip/ 應顯示 PHP 資訊頁
WordPress 部署:
cd /usr/local/apache/htdocs unzip wordpress-3.0.4-zh_CN.zip mv wordpress wp cd wp cp wp-config-sample.php wp-config.php # 編輯 wp-config.php 設定 DB_NAME, DB_USER, DB_PASSWORD
Apache 虛擬主機配置:
DocumentRoot "/usr/local/apache/htdocs/wp" ServerName blog.example.com AllowOverride All Require all granted
apxs)。libphp5.so 未正確載入 → 檢查 LoadModule php5_module modules/libphp5.so。