1、安裝編譯工具和依賴包
php
[root@www src]# yum -y install gc gcc-c++ pcre-devel ncurses-devel openssl-devel libpng-devel libtool libxslt-devel libxml2-devel libXpm-devel curl-devel
html
2、安裝PHP和MySQL所須要的軟件
mysql
一、安裝cmake
c++
[root@www cmake-2.8.10.2]# ./bootstrap
[root@www cmake-2.8.10.2]# make && make
二、安裝freetypesql
[root@www freetype-2.4.0]# ./configure --prefix=/usr/local/freetype
[root@www freetype-2.4.0]# make
三、安裝libmcrypt數據庫
[root@www libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@www libmcrypt-2.5.8]# make
四、安裝libiconvapache
[root@www libiconv-1.14]# ./configure --prefix=/usr/local/libiconv
[root@www libiconv-1.14]# make install
五、安裝jpeg-6bbootstrap
[root@www src]# cd jpeg-6b/
[root@www jpeg-6b]# mkdir /usr/local/jpeg6
[root@www jpeg-6b]# mkdir /usr/local/jpeg6/bin
[root@www jpeg-6b]# mkdir /usr/local/jpeg6/lib
[root@www jpeg-6b]# mkdir /usr/local/jpeg6/include
[root@www jpeg-6b]# mkdir /usr/local/jpeg6/man/man1 -pvim
[root@www jpeg-6b]# cp /usr/share/libtool/config/config.sub .
cp: overwrite `./config.sub'? y
[root@www jpeg-6b]# cp /usr/share/libtool/config/config.guess .
cp: overwrite `./config.guess'? y
[root@www jpeg-6b]# ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
[root@www jpeg-6b]# make
六、安裝gd2bash
[root@www libgd-2.1.1]# ./configure --prefix=/usr/local/libgd2 --with-zlib --with-jpeg=/usr/local/jpeg6 --with-png --with-freetype=/usr/local/freetype
3、安裝mysql
一、建立mysql用戶
[root@www mysql-5.6.27]# groupadd mysql
[root@www mysql-5.6.27]# useradd -r -g mysql mysql
二、編譯安裝mysql
[root@www mysql-5.6.27]# cmake . \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_DATADIR=/var/lib/mysql \
> -DSYSCONFDIR=/etc \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
> -DMYSQL_TCP_PORT=3306 \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DEXTRA_CHARSETS=all \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_MEMORY_STORAGE_ENGINE
WITH_READLINE
-- Build files have been written to: /usr/local/src/mysql-5.6.27
[root@www mysql-5.6.27]# gmake
[root@www mysql-5.6.27]# gmake install
三、修改/usr/local/mysql文件權限
[root@www mysql-5.6.27]# chown -R mysql:mysql /usr/local/mysql
[root@www mysql-5.6.27]# ll -d /usr/local/mysql
drwxr-xr-x 13 mysql mysql 4096 Dec 14 12:08 /usr/local/mysql
四、建立數據庫存儲目錄
[root@www mysql-5.6.27]# mkdir /var/lib/mysql
[root@www mysql-5.6.27]# chown mysql. /var/lib/mysql
五、安裝系統數據庫
[root@www scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/var/lib/mysql --no-defaults --user=mysql
[root@www scripts]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
六、複製配置文件
[root@www scripts]# cd /usr/local/mysql/support-files/
[root@www support-files]# ls
binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@www support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@www support-files]# vim /etc/my.cnf //修改配置
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
# server_id = .....
socket = /var/lib/mysql/mysql.sock
七、添加啓動腳本並設置開機啓動
[root@www support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
[root@www support-files]# chmod +x /etc/rc.d/init.d/mysqld
[root@www support-files]# service mysqld start
Starting MySQL.. SUCCESS!
[root@www support-files]# chkconfig --add mysqld
[root@www support-files]# chkconfig mysqld on
八、登陸mysql
[root@www support-files]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.27 Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
九、設置mysql環境變量
[root@www www]# vim /etc/profile.d/path.sh
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
[root@www www]# source /etc/profile.d/path.sh
[root@www www]# which mysqld
/usr/local/mysql/bin/mysqld
4、安裝apache2
一、安裝apr和apr-util
[root@www apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@www apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
二、編譯安裝apache2
[root@www httpd-2.2.31]# ./configure \
--prefix=/usr/local/apache2 \
--sysconfdir=/etc/httpd \
--with-included-apr \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre \
--enable-mem-cache \
--enable-cache \
--enable-static-support \
--with-z
[root@www httpd-2.2.31]# make
[root@www httpd-2.2.31]# make install
make[1]: Leaving directory `/usr/local/src/httpd-2.2.31'
[root@www httpd-2.2.31]# echo $?
0
[root@www ~]# ls /usr/local/apache2/
bin build cgi-bin error htdocs icons include lib logs man manual modules
[root@www httpd-2.2.31]# /usr/local/apache2/bin/apachectl start
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
[root@www httpd-2.2.31]# netstat -tnlp | grep 80
tcp 0 0 :::80 :::* LISTEN 2112/httpd
[root@www ~]# rm -rf /usr/local/apache2
[root@www src]# rm -rf httpd-2.2.31
[root@www src]# rm -rf /etc/httpd
reboot
[root@www ~]# netstat -tnlp | grep 80
[root@www httpd-2.2.31]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-included-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre --enable-mem-cache --enable-cache --enable-static-support --with-z
[root@www httpd-2.2.31]# /usr/local/apache2/bin/apachectl start
[root@www httpd-2.2.31]# netstat -tnlp | grep 80
tcp 0 0 :::80 :::* LISTEN 50223/httpd
[root@www httpd-2.2.31]# /usr/local/apache2/bin/apachectl -t
Syntax OK
三、建立啓動腳本
[root@www src]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
5、安裝PHP
一、編譯安裝php
[root@www php-5.6.14]# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-gd=/usr/local/libgd2 \
--with-jpeg-dir=/usr/local/jpeg6 \
--with-freetype-dir=/usr/local/freetype \
--with-mcrypt=/usr/local/libmcrypt \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-libxml-dir \
--with-zlib-dir \
--with-png-dir \
--with-iconv-dir=/usr/local/libiconv \
--with-openssl \
--with-curl \
--enable-soap \
--enable-gd-native-ttf \
--enable-mbstring \
--enable-sockets \
--enable-exif \
--disable-ipv6 \
--enable-ftp \
--with-mhash \
--with-pcre-dir=/usr/bin/pcre-config \
--enable-zip \
--with-bz2
報錯:
configure: error: Please reinstall the BZip2 distribution
[root@www php-5.6.14]# yum install -y bzip2 bzip2-devel
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.14/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
[root@www php-5.6.14]# echo $?
0
[root@www php-5.6.14]# ls /usr/local/php/
bin etc include lib php
二、測試php
[root@www php-5.6.14]# ls /usr/local/apache2/htdocs/index.html
/usr/local/apache2/htdocs/index.html
[root@www php-5.6.14]# cat !$
cat /usr/local/apache2/htdocs/index.html
<html><body><h1>It works!</h1></body></html>[root@www php-5.6.14]#
[root@www php-5.6.14]# vim /etc/httpd/httpd.conf //修改配置
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml
建立測試頁面
[root@www php-5.6.14]# vim /usr/local/apache2/htdocs/index.php
<?php
phpinfo();
?>
[root@www php-5.6.14]# cp php.ini-production /usr/local/php/etc/php.ini
從新加載php配置:[root@www php-5.6.14]# /usr/local/apache2/bin/apachectl graceful