軟件版本:
php
apache 2.2.31版本下載:http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gzhtml
mysql 5.1.72版本下載:http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gzmysql
php 5.3.28版本下載:http://mirrors.sohu.com/php/php-5.3.28.tar.gzlinux
安裝LAMP以前必備安裝包c++
yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel
編譯安裝mysqlsql
解壓並移動;
數據庫
# tar zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz # mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql
建立數據庫用戶、目錄、更改屬主;apache
# useradd -s /sbin/nologin mysql # mkdir -p /data/mysql # chown -R mysql:mysql /data/mysql
初始化數據庫;vim
# cd /usr/local/mysql # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
拷貝配置文件,修改my.cnf;app
# cp support-files/my-large.cnf /etc/my.cnf # vim /etc/init.d/mysqld [mysqld] user=mysql datadir=/data/mysql
編輯mysqld啓動腳本,找到basedir和datadir添加路徑;
# vi /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql
拷貝啓動文件、添加開機啓動;
# cp support-files/mysql.server /etc/init.d/mysqld # chmod 755 /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on
啓動mysql;
service mysqld start
編譯安裝apache
·/usr/local/apache2/bin/apachectl -M:查看安裝了哪些模塊 ·/usr/local/apache2/bin/apachectl -t:檢查語法錯誤 ·/usr/local/apache2/bin/apachectl -l:查看安裝的庫文件 ·/usr/local/apache2/bin/apachectl graceful:從新加載配置 ·/usr/local/apache2/htcocs 主頁存放目錄 ·/usr/local/apache2/bin/apachectl 啓動文件目錄 ·/usr/local/apache2/conf 配置文件路徑
Centos6 yum安裝的apr版本已經不適用httpd-2.4版本了。因此,須要源碼編譯安裝apr以及apr-util
# cd /usr/local/src/ # wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz # wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
編譯apr
[root@localhost src]# tar zxf apr-1.5.2.tar.gz [root@localhost src]# cd apr-1.5.2 [root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@localhost apr-1.5.2]# make && make install
編譯apr-util
[root@localhost src]# tar zxf apr-util-1.5.4.tar.gz [root@localhost src]# cd apr-util-1.5.4 [root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@localhost apr-util-1.5.4]# make && make install
編譯安裝apache
[root@localhost src]# tar zxf httpd-2.4.12.tar.gz [root@localhost src]# cd httpd-2.4.12 [root@localhost httpd-2.4.12]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most --enable-so
編譯安裝php
[root@localhost src]# tar zxvf php-5.3.28.tar.gz [root@localhost src]# cd php-5.3.28 [root@localhost php-5.6.8]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 [root@localhost php-5.6.8]# make && make install
拷貝php配置文件
[root@localhost php-5.3.28]# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini
配置apache解析php
找到:AddType application/x-gzip .gz .tgz 在該行下面添加:AddType application/x-httpd-php .php 找到: <IfModule dir_module> DirectoryIndex index.html </IfModule> 將該行改成: <IfModule dir_module> DirectoryIndex index.html index.htm index.php </IfModule> 找到:#ServerName www.example.com:80 修改成:ServerName localhost:80
測試apache解析php
[root@localhost ]# cat /usr/local/apache2/htdocs/test.php <?php echo "PHP解析正常\n"; ?> [root@localhost htdocs]# /usr/local/apache2/bin/apachectl start [root@localhost htdocs]# curl localhost/test.php 出現:PHP解析正常