一、安装编译工具和依赖包
[[email protected] src]# yum -y install gc gcc-c++ pcre-devel ncurses-devel openssl-devel libpng-devel libtool libxslt-devel libxml2-devel libXpm-devel curl-devel
二、安装PHP和MySQL所需要的软件
1、安装cmake
[[email protected] cmake-2.8.10.2]# ./bootstrap
[[email protected] cmake-2.8.10.2]# make && make
2、安装freetype
[[email protected] freetype-2.4.0]# ./configure --prefix=/usr/local/freetype
[[email protected] freetype-2.4.0]# make
3、安装libmcrypt
[[email protected] libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[[email protected] libmcrypt-2.5.8]# make
4、安装libiconv
[[email protected] libiconv-1.14]# ./configure --prefix=/usr/local/libiconv
[[email protected] libiconv-1.14]# make install
5、安装jpeg-6b
[[email protected] src]# cd jpeg-6b/
[[email protected] jpeg-6b]# mkdir /usr/local/jpeg6
[[email protected] jpeg-6b]# mkdir /usr/local/jpeg6/bin
[[email protected] jpeg-6b]# mkdir /usr/local/jpeg6/lib
[[email protected] jpeg-6b]# mkdir /usr/local/jpeg6/include
[[email protected] jpeg-6b]# mkdir /usr/local/jpeg6/man/man1 -p
[[email protected] jpeg-6b]# cp /usr/share/libtool/config/config.sub .
cp: overwrite `./config.sub‘? y
[[email protected] jpeg-6b]# cp /usr/share/libtool/config/config.guess .
cp: overwrite `./config.guess‘? y
[[email protected] jpeg-6b]# ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
[[email protected] jpeg-6b]# make
6、安装gd2
[[email protected] libgd-2.1.1]# ./configure --prefix=/usr/local/libgd2 --with-zlib --with-jpeg=/usr/local/jpeg6 --with-png --with-freetype=/usr/local/freetype
三、安装mysql
1、创建mysql用户
[[email protected] mysql-5.6.27]# groupadd mysql
[[email protected] mysql-5.6.27]# useradd -r -g mysql mysql
2、编译安装mysql
[[email protected] 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
[[email protected] mysql-5.6.27]# gmake
[[email protected] mysql-5.6.27]# gmake install
3、修改/usr/local/mysql文件权限
[[email protected] mysql-5.6.27]# chown -R mysql:mysql /usr/local/mysql
[[email protected] mysql-5.6.27]# ll -d /usr/local/mysql
drwxr-xr-x 13 mysql mysql 4096 Dec 14 12:08 /usr/local/mysql
4、创建数据库存储目录
[[email protected] mysql-5.6.27]# mkdir /var/lib/mysql
[[email protected] mysql-5.6.27]# chown mysql. /var/lib/mysql
5、安装系统数据库
[[email protected] scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/var/lib/mysql --no-defaults --user=mysql
[[email protected] scripts]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
6、复制配置文件
[[email protected] scripts]# cd /usr/local/mysql/support-files/
[[email protected] support-files]# ls
binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[[email protected] support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf‘? y
[[email protected] support-files]# vim /etc/my.cnf //修改配置
basedir = /usr/local/mysql
datadir = /var/lib/mysql
port = 3306
# server_id = .....
socket = /var/lib/mysql/mysql.sock
7、添加启动脚本并设置开机启动
[[email protected] support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
[[email protected] support-files]# chmod +x /etc/rc.d/init.d/mysqld
[[email protected] support-files]# service mysqld start
Starting MySQL.. SUCCESS!
[[email protected] support-files]# chkconfig --add mysqld
[[email protected] support-files]# chkconfig mysqld on
8、登录mysql
[[email protected] 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>
四、安装apache2
1、安装apr和apr-util
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr
[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
2、编译安装apache2
[[email protected] 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
[[email protected] httpd-2.2.31]# make
[[email protected] httpd-2.2.31]# make install
make[1]: Leaving directory `/usr/local/src/httpd-2.2.31‘
[[email protected] httpd-2.2.31]# echo $?
0
[[email protected] ~]# ls /usr/local/apache2/
bin build cgi-bin error htdocs icons include lib logs man manual modules
[[email protected] 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
[[email protected] httpd-2.2.31]# netstat -tnlp | grep 80
tcp 0 0 :::80 :::* LISTEN 2112/httpd
[[email protected] ~]# rm -rf /usr/local/apache2
[[email protected] src]# rm -rf httpd-2.2.31
[[email protected] src]# rm -rf /etc/httpd
reboot
[[email protected] ~]# netstat -tnlp | grep 80
[[email protected] 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
[[email protected] httpd-2.2.31]# /usr/local/apache2/bin/apachectl start
[[email protected] httpd-2.2.31]# netstat -tnlp | grep 80
tcp 0 0 :::80 :::* LISTEN 50223/httpd
[[email protected] httpd-2.2.31]# /usr/local/apache2/bin/apachectl -t
Syntax OK
3、创建启动脚本
[[email protected] src]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
五、安装PHP
1、编译安装php
[[email protected] 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
[[email protected] 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/
[[email protected] php-5.6.14]# echo $?
0
[[email protected] php-5.6.14]# ls /usr/local/php/
bin etc include lib php
2、测试php
[[email protected] php-5.6.14]# ls /usr/local/apache2/htdocs/index.html
/usr/local/apache2/htdocs/index.html
[[email protected] php-5.6.14]# cat !$
cat /usr/local/apache2/htdocs/index.html
<html><body><h1>It works!</h1></body></html>[[email protected] php-5.6.14]#
[[email protected] 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
创建测试页面
[[email protected] php-5.6.14]# vim /usr/local/apache2/htdocs/index.php
<?php
phpinfo();
?>
[[email protected] php-5.6.14]# cp php.ini-production /usr/local/php/etc/php.ini
重新加载php配置:
[[email protected] php-5.6.14]# /usr/local/apache2/bin/apachectl graceful