准备工做php
安装make yum -y install gcc automake autoconf libtool makehtml
安装g++ yum -y install gcc gcc-c++mysql
一、下载nginxlinux
http://nginx.org/download/nginx-1.10.1.tar.gznginx
二、下载phpc++
http://cn2.php.net/distributions/php-5.6.22.tar.gzgit
http://cn2.php.net/distributions/php-7.0.7.tar.gzweb
三、下载mysqlsql
http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz数据库
下载pcre,是Nginx的重写Rewrite,zlib为了网页Gzip压缩,openssl加密传输
https://sourceforge.net/projects/pcre/files/pcre/
下载:http://pilotfiber.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
①、首先看服务器是否已安装pcre
[root@localhost src]# rpm -qa pcre
pcre-8.32-15.el7.x86_64
上面查到了pcre已存在,可是不是最新版的,我要安装一个最新版的
②、编译安装pcre
[root@localhost src]# tar -zxf pcre-8.38.tar.gz
[root@localhost src]# cd pcre-8.38
[root@localhost pcre-8.38]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.38]# make
[root@localhost pcre-8.38]# make install
下载地址:http://zlib.net/zlib-1.2.8.tar.gz
[root@localhost src]# wget http://zlib.net/zlib-1.2.8.tar.gz
[root@localhost src]# tar -zxf zlib-1.2.8.tar.gz
[root@localhost src]# cd zlib-1.2.8
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[root@localhost zlib-1.2.8]# make && make install
下载地址:http://www.openssl.org/source/openssl-1.0.1t.tar.gz
[root@localhost src]# wget http://www.openssl.org/source/openssl-1.0.1t.tar.gz
[root@localhost src]# tar -zxf openssl-1.0.1t.tar.gz
[root@localhost src]# cd openssl-1.0.1t
[root@localhost openssl-1.0.1t]# ./config --prefix=/usr/local/openssl
[root@localhost openssl-1.0.1t]# make && make install
[root@localhost openssl-1.0.1t]# export PATH=$PATH:/usr/local/openssl/bin
[root@localhost openssl-1.0.1t]# source /etc/profile
注意,这里安装是用config不是configure哦~~编译相对比上面久一点
[root@localhost src]# yum -y install gd-devel
[root@localhost nginx-1.10.1]# groupadd nginx
[root@localhost nginx-1.10.1]# useradd -g nginx nginx -s /bin/false
[root@localhost nginx-1.10.1]# tar -zxf nginx-1.10.1.tar.gz
[root@localhost nginx-1.10.1]# cd nginx-1.10.1
[root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.38 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1t
[root@localhost nginx-1.10.1]# make && make install
小技巧:
./configure --help #能够查看编译选项,如上面的--with-http_ssl_module
【参考文献】http://tengine.taobao.org/book/appendix_c.html#nginxlinux
http://nginx.org/en/docs/configure.html
① 修改配置文件
[root@localhost nginx-1.6.2]# vi /usr/local/nginx/conf/nginx.conf
将http -> server -> server_name改成服务器的外网ip地址,或你的网站域名
② 启动Nginx
[root@localhost nginx-1.6.2]# /usr/local/nginx/sbin/nginx
Nginx安装完毕,这个是在虚拟机上面安装的,ip地址是192.168.1.202,这是咱们用浏览器访问192.168.1.202,访问失败,什么缘由,你应该很快想到是防火墙
③ 开机自启动
方法一:在/etc/rc.d/rc.local文件里面增长一行,以下
/usr/local/nginx/sbin/nginx
方法二:将nginx加入服务
在/etc/rc.d/init.d/下面增长一个脚本,名称 nginx,脚本内容查看这里
④ 防火墙配置
Centos6】
一、要么关闭防火墙 [root@localhost nginx-1.8.1]# service iptables stop
二、要么配置防火墙
[root@localhost202 nginx-1.8.1]# vim /etc/sysconfig/iptables
在里面添加一句-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
保存退出,
[root@localhost202 nginx-1.8.1]#service iptables restart
重启防火墙使配置生效
Centos7】
systemctl stop firewalld.service //中止firewall
systemctl disable firewalld.service //禁止firewall开机启动
yum -y install iptables-services
[root@localhost202 nginx-1.8.1]# vim /etc/sysconfig/iptables
在里面添加一句-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
systemctl restart iptables.service #重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
⑤加入环境变量
[root@localhost ~]# vim /etc/profile # 在文件末尾增长以下内容
#add by tomener ~ php mysql nginx openssl
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/openssl/bin:/usr/local/nginx/sbin:/usr/local/php/bin
[root@localhost ~]# source /etc/profile
下载地址:http://cn2.php.net/distributions/php-5.6.19.tar.gz
[root@localhost202 src]# yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \ zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \ ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \ krb5 krb5-devel libidn libidn-devel openssl openssl-devel
[root@localhost202 src]# wget http://cn2.php.net/distributions/php-5.6.19.tar.gz
[root@localhost202 src]# tar -zxf php-5.6.19.tar.gz
[root@localhost202 src]# cd php-5.6.19
[root@localhost202 php-5.6.19]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir --with-jpeg-dir --with-freetype-dir --with-xpm-dir=/usr/lib --with-zlib-dir=/usr/local/zlib --enable-bcmath --enable-shmop --enable-sysvsem --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-opcache --enable-pcntl --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-xmlrpc --enable-zip --enable-soap --without-pear --with-mcrypt --with-curl --with-mhash --with-openssl=/usr/local/openssl
-------------------------------------小插曲 Start---------------------------------------
编译时遇到一个错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
用rpm -qa|grep mcrypt 没有查到,
用yum -list installed | grep mcrypt,也没查到那咱们就来安装一下了,
能够用yum安装,也能够编译安装,
[root@localhost202 src]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
[root@localhost202 src]# tar -zxf libmcrypt-2.5.8.tar.gz
[root@localhost202 src]# cd libmcrypt-2.5.8
[root@localhost202 libmcrypt-2.5.8]#./configure
[root@localhost202 libmcrypt-2.5.8]# make && make install
-------------------------------------小插曲 End---------------------------------------
./configure 后看见这个就表示配置没问题了,开始下面的编译和安装
[root@localhost php-5.6.19]# make
编译完了,看上面有一句Don't forget to run 'make test'.
那咱们就make test一下了
[root@localhost php-5.6.19]# make test
测试了很久,是否是咱们不该该这么听话呢? 唉,慢慢等了~~~
[root@localhost php-5.6.19]# make install
PHP编译安装到此结束~~ , 下面咱们来配置php和php-fpm
一、php.ini配置
①查看php.ini配置文件的路径
[root@localhost php-5.6.19]# /usr/local/php/bin/php --ini
Configuration File (php.ini) Path: /usr/local/php/lib
显示在lib下面,全部咱们应该拷贝源码包里面配置文件到/usr/local/php/lib下面
[root@localhost php-5.6.19]# cp php.ini-production /usr/local/php/lib/php.ini
②配置php.ini
A.关闭在http头中显示php版本信息
expose_php = Off
B. 设置时区
date.timezone = PRC
更多配置请查看 PHP7配置文件设置
二、php-fpm配置
[root@localhost php-5.6.19]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php54/etc/php-fpm.conf
① 去掉25行 ;pid = run/php-fpm.pid 前面的分号,是之生效
② 第148行改成 user = nginx 设置php-fpm运行帐号为nginx,由于咱们安装nginx的时候用的是nginx这个用户,能够看上面的nginx安装那步。
③ 第149行改成 group = nginx #设置php-fpm运行组为nginx,和上面一个原理
④ 设置socket的监听
listen = /dev/shm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
三、设置php-fpm开机自启动
[root@localhost php-5.4.36]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.4.36]# chmod 0755 /etc/init.d/php-fpm
[root@localhost php-5.4.36]# chkconfig --level 35 php-fpm on
而后能够用chkconfig --list 来查看是否将php-fpm添加到了自启动
四、启动php-fpm
[root@localhost html]# /usr/local/php/sbin/php-fpm
固然,第3步咱们已经把php-fpm加入了开机自启动,也就是加入了服务,全部,我就能够用这样的命令来控制php-fpm了:
[root@localhost html]# service php-fpm start|restart|stop|reload|status|force-quit
五、配置nginx支持php脚本
修改哪里呢?这还问么,天然是nginx的配置文件了
[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf
①顶部的user那行设置为 user nginx nginx
②找到
location / {
root html;
index index.html index.htm
}
改成:
location / {
root /data/webroot;
index index.php index.html index.htm
}
③以下图:
Nginx + PHP-FPM设置虚拟主机 + 开启PATHINFO模式
六、重启nginx
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -s reload
七、修改web根目录的全部者所属组
[root@localhost nginx]# chown -R nginx:nginx /data/webroot
这步,先能够不作
八、测试php-fmp是否配置成功
[root@localhost nginx]# vim /usr/local/nginx/html/phpinfo.php
echo phpinfo();
:wq
http://localhost/phpinfo.php
--------------------------------------------------------------------------------------
小提示:php核心编译选项:http://php.net/manual/zh/configure.about.php
查看更多选项 ./configure --help 或者./configure --help >> /data/php-configure.txt 从定向到文件,拿到本地来慢慢研究
安装一些必要的软件:ncurses-devel、cmake
刚开始没装ncurses-devel,编译不成功,而后yum install ncurses-devel,后面编译就成功了。
MySQL从5.5开始使用cmake来编译安装了,
下载地址:http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz
[root@localhost src]# wget http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz
[root@localhost src]# tar -zxf cmake-3.1.0.tar.gz
[root@localhost src]# cd cmake-3.1.0
[root@localhost cmake-3.1.0]# ./configure --prefix=/usr/local/cmake
[root@localhost cmake-3.1.0]# make
[root@localhost cmake-3.1.0]# make install
[root@localhost cmake-3.1.0]# export PATH=$PATH:/usr/local/openssl/bin
[root@localhost cmake-3.1.0]# source /etc/profile
小提示:下载有点满,5.7M下了10多分钟~~,查看cmake是否安装:
which cmake 或者 whereis cmake
下载地址:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz
http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz
[root@localhost src]# wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.22.tar.gz
[root@localhost src]# tar -zxf mysql-5.6.22.tar.gz
[root@localhost src]# cd mysql-5.6.22
[root@localhost mysql-5.6.22]# groupadd mysql
[root@localhost mysql-5.6.22]# useradd -g mysql mysql -s /bin/false
[root@localhost mysql-5.6.22]# mkdir -p /usr/local/mysql
[root@localhost mysql-5.6.22]# mkdir -p /data/mysql
[root@localhost mysql-5.6.22]# chown -R mysql:mysql /data/mysql
[root@localhost mysql-5.6.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[root@localhost mysql-5.6.22]# make
[root@localhost mysql-5.6.22]# make install
[root@localhost mysql-5.6.22]# cd /usr/local/mysql
5.7版本在cmake的时候须要增长两个参数 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
小提示:若是cmake后出错,需删除mysql-5.6.22目录下面的CMakeCache.txt这个文件后再cmake,我就是开始cmake出错了,安装了ncurses-devel后再cmake
参考文献:http://my.oschina.net/looly/blog/297980
编译参数:
http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html
可能遇到问题:
一、Warning: Bison executable not found in PATH
解决: yum -y install bison
二、Could NOT find Git (missing: GIT_EXECUTABLE)
解决: yum -y install git
~~~~~~~~~~~~~MySQL安装完毕~~~~~~~~~~~
一、初始化mysql数据库
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb/ #生成mysql系统数据库
二、复制mysql服务启动配置文件
[root@localhost support-files]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
三、复制mysql服务启动脚本及加入PATH路径
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/profile #编辑profile添加环境变量
在profile最后加上:
# add by Tomener ~ mysql,openssl
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib:/usr/local/openssl/bin
保存退出
[root@localhost mysql]# source /etc/profile
四、启动MySQL
[root@localhost202 mysql]# service mysqld start
Starting MySQL... SUCCESS!
五、将MySQL加入开机自启动
[root@localhost202 mysql]# chkconfig --level 35 mysqld on
六、检查MySQL是否已启动
[root@localhost202 mysql]# netstat -ntpl | grep mysql
看见3306端口就表示启动了~~
七、用mysql客服端登陆
[root@localhost202 mysql]# mysql -u root -p
密码是空的,直接回车
八、修改MySQL的root密码
[root@localhost202 mysql]# mysql_secure_installation
这里能够设置root的密码(咱们设置为tomenr888),删除匿名用户,设置是否阻止root账号远程登陆,是否删除test库,是否重新加载权限表
第二种方法,通常安装完MySQL后root密码都为空,咱们能够mysql客服端里面修改
mysql> set password for root@localhost = password('tomener888');
Query OK, 0 rows affected (0.10 sec)
固然设置root的密码有不少方法,可自行百度
九、添加MySQL用户
首先进入mysql客服端
[root@localhost202 mysql]#mysql -u root -p
mysql>create user 'tomener'@'localhost' IDENTIFIED BY 'tomenr888';
更多关于MySQL用户知识,请看我以前的一篇文章:
http://blog.sina.com.cn/s/blog_75ad10100101o3hi.html
完毕~~
本文来自:http://blog.sina.com.cn/tomener
原文连接:http://blog.sina.com.cn/s/blog_75ad10100102vc14.html