安装环境:
Linux:CENTOS 6.6
NGINX:nginx-1.8.1
PHP:5.5.31
MYSQL:mysql-5.7.11
安装注意:先安装nginx和mysql,最后安装php
安装前准备工作:
yum install gcc-c++ libtool -y
一,Nginx编译安装
wget http://nginx.org/download/nginx-1.8.1.tar.gz
依赖包安装:
需先安装pcre 、zlib、 openssl三个库(源码安装、yum安装或者apt-get都可以)
pcre 编译安装 (ubuntu: sudo apt-get install libpcre3 libpcre3-dev )
zlib、zlib-devel (Ubuntu 里安装zlib1g,zlib1g-dev这2个包)
openssl (ubuntu : sudo apt-get install openssl libssl-dev、)
注意:如果编译安装前确保安装了:libtool和gcc-c++
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
编译安装Nginx:
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx
make && make install
nginx目录默认下有conf html logs sbin四个目录
启动:/usr/local/nginx/sbin/nginx
查看编译情况:/usr/local/nginx/sbin/nginx -V
二,安装mysql
登录后:
show variables; 可查看所有Mysql环境变量
编译安装
mysql-5.7.11
安装之前需要先安装cmake、
ncurses、
bison个软件包
yum install -y cmake ncurses bison
tar -zxvf mysql-5.7.11.tar.gz
cd mysql-5.7.11
1,使用cmake源码安装mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/var/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/root/tools/boost_1_59_0 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
2,cmake结束后开始编译源码
# make
注:如果cmake正常,而make出错,可以rm -rf CMakeCache.txt,重新cmake,再次make
3、安装编译好的程序
# make install
注意:如果需要重装mysql,在/usr/local/src/mysql-5.7.11在执行下make install就可以了,不需要再cmake和make
4、清除安装临时文件
# make clean
5、修改目录拥有者
# chown -Rf mysql:mysql /usr/local/mysql
# chown -Rf mysql:mysql /var/mysql
6、执行初始化配置脚本
# /usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/var/mysql
如果提示错误,则rm -rf /var/mysql 执行下面命令
# /usr/local/mysql/bin/mysqld --initialize --datadir=/var/mysql
初始化完成后,系统会随机生成一个强密码
[Note] A temporary password is generated for root@localhost: Xe>VsFkw0dem
登录是需要用到这个密码,(注:但登录什么都不能操作,只能重设密码后才能正常操作)
登录后:set password=password('111111');重设密码后,就可以正常操作了
登录
出错
时:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
此时,修改/etc/my.cnf中socket = /tmp/mysql.sock 再重启mysql即可解决
配置脚本my.cnf
# cp /源码解压路径/support-files/my-default.cnf /etc/my.cnf
注:如果编译后,/etc/my.cnf已经存在,上步可省略
7、复制服务启动脚本
启动MySQL服务
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
8、启动MySQL服务
# service mysql start
或/usr/local/mysql/bin/mysqld_safe --user=mysql
9、设置开机自动启动服务
# chkconfig mysql on 默认就是--level 2345
查看启动级别
# chkconfig --list mysql
10、登录并修改MySQL用户root的密码
# mysql -u root
mysql> set password=password('123456');
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
mysql> update user set Password = password('123456') where User='root';
mysql> flush privileges;
mysql> exit;
三,安装php
查询库是否安装
rpm -qa zlib-devel libxml2-devel libjpeg-turbo-devel libpng-devel gd-devel libiconv-devel freetype-devel libcurl-devel libxslt-devel openssl-devel readline-devel
安装库
yum install -y zlib-devel libxml2-devel libjpeg-turbo-devel libpng-devel gd-devel libiconv-devel freetype-devel libcurl-devel libxslt-devel openssl-devel readline-devel
有2个包的名字变更了:
libjpeg-devel =====> libjpeg-turbo-devel
curl-devel =====> libcurl-devel
安装yum源里默认没有的包:
安装libiconv-devel:
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
安装libmcrypt-devel、mhash加密扩展,mcrypt加密扩展,
使用第三方epel源快速安装(yum官方源没有软件包)
:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install -y libmcrypt-devel mhash mhash-devel mcrypt mcrypt-devel
编译安装PHP:
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-mysqlnd \
--with-freetype-dir=/usr \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-openssl \
--with-curl \
--with-libxml-dir \
--with-iconv-dir=/usr/local/libiconv \
--with-mcrypt \
--with-mhash \
--with-xmlrpc \
--with-xsl \
--enable-xml \
--disable-rpath \
--enable-safe-mod \
--enable-bcmath \
--with-readline \
--with-gc \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-mbregex \
--enable-fpm \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-zip \
--enable-pcntl \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-ftp
编译
make
安装
make install
配置文件php.ini,
把解压的源代码中的
cp php.ini-production /usr/local/php/lib/php.ini
php-fpm配置文件
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
启动php-fpm
/usr/local/php/sbin/php-fpm
多行命令一起执行:
make
make install
cp php.ini-production /usr/local/php/lib/php.ini
cd /usr/local/php/etc/
cp -f php-fpm.conf.default php-fpm.conf
/usr/local/php/sbin/php-fpm
注:readline-devel 主要命令行的交互模式