准备工作
1.关闭SELINUX
# vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! #保存退出
# setenforce 0 #使配置立即生效
2.下载需要的源代码包(这是我自己收藏的,需要最新的自己去官网下载)
链接: https://pan.baidu.com/s/1o7AMang 密码: w9nz
约定源代码包都解压在/usr/local/src/目录下
安装路径在/usr/loca/下
安装
yum install -y gcc gcc-c++ ncurses-devel perl
开始安装
一、安装nginx
1、安装pcre
# mkdir /usr/local/pcre
# tar zxvf pcre-8.35.tar.gz
# cd pcre-8.35
# ./configure –prefix=/usr/loca/pcre/
# make && make install
2、安装openssl
// 如果系统有就直接安装
// 没有则下载源代码包编译安装
# mkdir /usr/local/openssl
# tar zxvf openssl-openssl-1.0.2g.tar.gz(注意:要找跟nginx对应的版本否在编译nginx时会报错)
# cd openssl-1.0.1h
# ./config –prefix=/usr/local/openssl
# make
# make install
# vi /etc/profile // 最后一行添加
export PATH=$PATH:/usr/local/openssl/bin
# source /etc/profile
3、安装zlib
# mkdir /usr/local/zlib
# tar -zxvf zlib-1.2.8.tar.gz -C /usr/local/src/
# cd /usr/local/src/zlib-1.2.8
# ./configure –prefix=/usr/local/zlib/
# make
# make install
4、安装nginx
// 新建用户跟用户组
# groupadd www
// 不能登录
# useradd -g www www -s /bin/false
# mkdir /usr/local/nginx
# tar -zxvf nginx-1.9.12.tar.gz -C /usr/local/src/
# cd /usr/local/src/nginx-1.9.12
# ./configure –prefix=/usr/local/nginx/ –without-http_memcached_module –user=www –group=www –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-openssl=/usr/local/src/openssl-1.0.2g –with-zlib=/usr/local/src/zlib-1.2.8 –with-pcre=/usr/local/src/pcre-8.36
# make
# make install
二、安装mysql
1、安装cmake
# tar -zxvf cmake-2.8.10.2.tar.gz -C /usr/local/src/
# cd /usr/local/src/cmake-2.8.10.2
# ./configure
# make
# make install
2、安装mysql
# groupadd mysql //添加mysql组
# useradd -g mysql mysql -s /bin/false //创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
# mkdir -p /data/mysql //创建MySQL数据库存放目录
# mkdir -p /usr/local/mysql //创建MySQL安装目录
# tar -zxvf mysql-5.6.15.tar.gz -C /usr/local/src/
# cd /usr/local/src/mysql-5.6.15
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
# make && make install
# cd /usr/local/mysql //进入MySQL安装目录
# ./scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql
报错:Can't locate Data/Dumper.pm
yum -y install cpan
// 生成mysql系统数据库
# ln -s /usr/local/mysql/my.cnf /etc/my.cnf //添加到/etc目录的软连接
把Mysql加入系统启动(centos)
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/init.d/mysqld //增加执行权限
# chkconfig mysqld on //加入开机启动
ubuntu
# cp ./support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# cd /etc/init.d
# update-rc.d mysqld defaults 95 //95是执行顺序
# vi /etc/rc.d/init.d/mysqld //编辑
basedir=/usr/local/mysql #MySQL程序安装路径
datadir=/data/mysql #MySQl数据库存放目录
:wq! #保存退出
# service mysqld start //启动
# vi /etc/profile //把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin
:wq! #保存退出
# source /etc/profile //使配置立刻生效
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
# mkdir /var/lib/mysql //创建目录
# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock //添加软链接
设置密码
# mysql_secure_installation //设置Mysql密码,根据提示按Y 回车输入2次密码
三、安装php
1、安装libpng
# mkdir /usr/local/libpng
# cd /usr/local/src/libpng-1.2.40/
# ./configure –prefix=/usr/local/libpng –enable-shared
# make && make inatall
编译过程中报错:png.h:497:18: fatal error: zlib.h
原因是我编译安装zlib时自定义了路径,安装libpng时寻找zlib的默认路径为/usr/include /lib/libz.so。解决方法如下:
# ln -s /usr/local/zlib/lib/libz.so.1.2.8 /lib/libz.so
# ln -s /usr/local/zlib/include/* /usr/include
2、安装freetype
# mkdir /usr/loca/freetype
# tar -jxvf freetype-2.7.1.tar.bz2 -C /usr/local/src/
# cd /usr/local/src/freetype-2.7.1/
# ./configure –prefix=/usr/local/freetype –enable-shared
# make && make install
3、安装jpeg
# mkdir /usr/local/jpeg
# tar -zxvf libjpeg-6b.tar.gz -C /usr/local/src/
# cd /usr/local/src/jpeg-6b/
# ./configure –prefix=/usr/local/jpeg/ –enable-shared
# make && make install
报错:Makefile:143: recipe for target 'jcapimin.lo' failed(liunx版本不同可能报错信信息有偏差)
解决方法查看是否安装了libtool,如果安装了则然后进入jpeg-6b的源码目录,然后执行以下步骤
(在目录/usr/share/libtool/把 libtool里面的两个配置文件拿来覆盖掉jpeg-6b目录下的对应文件)
# cp /usr/share/libtool/config/config.sub .
# cp /usr/share/libtool/config/config.guess .
make clean (切记。make clean)再重新configure
没有权限的时候先建立对应的文件夹
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib
mkdir /usr/local/jpeg/inculde
mkdir /usr/local/jpeg/man
mkdir -p /usr/local/jpeg/man/man1
,再次make install就行了
安装路径:/usr/local/jpeg/lib
如果其他软件需要使用这个库则需要指定路径 -LLIBDIR /usr/local/jpeg/lib
4、安装libgd
# mkdir /usr/local/libgd
# tar -zxvf gd-2.0.33.tar.gz -C /usr/local/src/
# cd /usr/local/src/gd-2.0.33/
# ./configure –prefix=/usr/local/libgd/ –enable-shared –with-jpeg=/usr/local/jpeg –with-png=/usr/local/libpng –with-freetype=/usr/local/freetype –with-fontconfig=/usr/local/freetype
# make && make install
报错
gd_png.c:15:53: fatal error: png.h: No such file or directory
vim gd_png.c
在gd_png.c中找到png.h的地方,有一个include<png.h>,改变成你的png的具体位置就可以了(我的位置是/usr/local/libpng/include/png.h)
5、安装Libmcrypt
# tar -zxvf libmcrypt-2.5.8.tar.gz -C /usr/local/src/
# cd /usr/local/src/libmcrypt-2.5.8
# ./configure
# make && make install
默认安装在/usr/local/lib
# export LD_LIBRARY_PATH=/usr/local/lib
6、安装mhash
# tar -zxvf mhash-0.9.9.9.tar.gz -C /usr/local/src/
# cd /usr/local/src/mhash-0.9.9.9
# ./configure
# make && make install
默认安装在/usr/local/lib
# export LD_LIBRARY_PATH=/usr/local/lib
7、安装mcrypt
# tar -zxvf mcrypt-2.6.8.tar.gz -C /usr/local/src/
# cd /usr/local/src/mcrypt-2.6.8/
# export LD_LIBRARY_PATH=/usr/local/lib //看情况执行
# ./configure && make && make install
8、安装libiconv(最好不要指定安装目录,否则编译安装php时会报错)
# mkdir /usr/local/libiconv
# tar -zxvf libiconv-1.13.1.tar.gz -C /usr/local/src/
# cd /usr/local/src/libiconv-1.13.1
# ./configure //不指定路径时默认安装路径/usr/local/lib
# make && make install
9、安装PHP
# mkdir /usr/local/php
# tar -zxvf php-7.0.5.tar.gz -C /usr/local/src/
# ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –enable-mysqlnd –with-mysqli=/usr/local/mysql/bin/mysql_config -with-fpm-user=www –with-fpm-group=www –with-iconv –with-mysql-sock=/tmp/mysql.sock –with-pdo-mysql=/usr/local/mysql –with-gd –with-png-dir=/usr/local/libpng –with-jpeg-dir=/usr/local/jpeg –with-freetype-dir=/usr/local/freetype –with-zlib-dir=/usr/local/zlib –enable-libxml –enable-xml –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –enable-opcache –enable-mbregex –enable-fpm –enable-mbstring –enable-ftp –enable-gd-native-ttf –with-openssl=/usr/local/openssl –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –without-pear –with-gettext –enable-session –with-mcrypt –with-curl –enable-ctype
# make
# make install
报错:recipe for target 'sapi/cli/php' failed
解决方法:编辑Makefile : EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然后重新再次 make 即可。
报错:/usr/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
Makefile:292: recipe for target 'sapi/cli/php' failed
解决方法:编译安装libiconv不要指定路径
报错:configure: error: xml2-config not found. Please check your libxml2 installation
重新安装libxml2和libxml2-devel包
yum install libxml2
yum install libxml2-devel -y
yum -y install curl-devel
#复制php配置文件到安装目录
# cp php.ini-production /usr/local/php/etc/php.ini
删除系统自带配置文件
# rm -rf /etc/php.ini
添加软链接到 /etc目录
# ln -s /usr/local/php/etc/php.ini /etc/php.ini
拷贝模板文件为php-fpm配置文件
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
添加软连接到 /etc目录
# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# vi /usr/local/php/etc/php-fpm.conf //编辑
pid = run/php-fpm.pid #取消前面的分号
设置 php-fpm开机启动
# cp /usr/local/src/php-7.0.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm (ubuntu)
# cp /usr/local/src/php-7.0.5/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm (centos)
# chmod +x /etc/rc.d/init.d/php-fpm //添加执行权限
设置开机启动
# update-rc.d php-fpm defaults (ubuntu)
# chkconfig php-fpm on (centos)
# vi /usr/local/php/etc/php.ini //编辑配置文件
找到:disable_functions
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,
proc_get_status,ini_alter,ini_alter,ini_restore,
dl,openlog,syslog,readlink,symlink,popepassthru,
stream_socket_server,escapeshellcmd,dll,popen,
disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,
disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,
posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,
posix_ttyname,posix_uname
列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = Off #禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持php短标签
找到opcache.enable=0
修改为opcache.enable=1 #php支持opcode缓存
找到:opcache.enable_cli=1
修改为:opcache.enable_cli=0
在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能
启动php
/usr/local/php/sbin/php-fpm
平滑重启
kill -USR2 cat /usr/local/php/var/run/php-fpm.pid
php安装扩展( 进入PHP源码包)
cd /usr/local/src/php-7.0.5
找到需要安装的扩展(以pdo为例)
cd ext/pdo
/usr/local/php/bin/phpiz
./configure –with-php-config=/usr/local/php/bin/php-config –enable-pdo=shared
make && make install
编辑php.ini把扩展加进去
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/pdo.so
四、安装redis
# tar -zxvf redis-3.0.7.tar.gz -C /usr/local/src/
# make
# make install
创建运行命令路径,和配置文件
# mkdir /usr/local/redis
# cp -rf ./src/redis-cli ./src/redis-server ./redis.conf /usr/local/redis/
# cd /usr/local/redis/
编辑redis.conf配置文件
daemonize yes
pidfile /var/run/redis.pid
port 6379
设置开机自启动命令
新建编辑 /etc/init.d/redis
#!/bin/sh
REDISPORT=6379
EXEC=/usr/local/redis/redis-server
CLIEXEC=/usr/local/redis/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
# chmod +x /etc/init.d/redis
# centos
# chkconfig –add redis
# chkconfig redis on
如果报错 service redis does not support chkconfig则在/etc/init.d/redis文件添加一些两行代码
\#!/bin/sh
\# chkconfig: 2345 90 10
\# description: redis is a persistent key-value database
# ubuntu
# update-rc.d redis defaults