参考官方文档:http://nginx.org/en/linux_pac...php
官当提供了利用yum来安装、升级nginx的方法
在/etc/yum.repos.d/目录下建立nginx.repo文件,输入如下代码:html
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/OSRELEASE/$basearch/ gpgcheck=0 enabled=1
将OSRELEASE替换为'5'、'6','7'或者'5.x'、'6.x'、'7.x',根据当前centos的系统版本替换便可。
设置好nginx.repo文件以后,开始用yum安装nginxmysql
# sudo yum install -y nginx
yum提示安装完成,则代表安装成功
到此nginx安装完成了。等咱们安装完php,再对nginx进行设置!linux
# wget http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror
建议安装以前先看看安装帮助文件INSTALLnginx
# tar zxvf php-7.0.0.tar.gz # cd php-7.0.0
首先查看安装帮助sql
# ./configure --help
开始预编译数据库
# ./configure --prefix=/usr/local/php \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip
若是配置错误,须要安装须要的模块,直接yum一并安装依赖库vim
# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
# make && make install
# cp php.ini-development /usr/local/php/lib/php.ini # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf # cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
须要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,若是你修改默认的9000端口号需在这里改,再改nginx的配置windows
# /etc/init.d/php-fpm
查看phpinfo()centos
注意:这一点是额外的,能够根据自身需求而定,我我的以为每次用/etc/init.d/php-fpm 启动很不方便!
编辑php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
把pid 改为 /run/php-fpm.pid
pid = /run/php-fpm.pid
加php-fpm管理器到systemctl中
# vim /usr/lib/systemd/system/php-fpm.service
按i写入如下内容
[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target
启动php-fpm
systemctl start php-fpm.service
添加到开机启动
systemctl enable php-fpm.service
若是设置成功,能够将以前添加到/etc/init.d/php-fpm删除
# vim /usr/local/php/etc/php-fpm.d/www.conf
查看listen的值,默认是 listen=127.0.0.1:9000
# cd /etc/nginx/conf.d # vim default.conf
看到相似内容
server { 2 listen 80; 3 server_name localhost; 4 5 #charset koi8-r; 6 #access_log /var/log/nginx/log/host.access.log main; 7 8 location / { 9 root /usr/share/nginx/html; 10 index index.html index.htm; 11 } 12 13 #error_page 404 /404.html; 14 15 # redirect server error pages to the static page /50x.html 16 # 17 error_page 500 502 503 504 /50x.html; 18 location = /50x.html { 19 root /usr/share/nginx/html; 20 } 21 22 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 23 # 24 #location ~ \.php$ { 25 # proxy_pass http://127.0.0.1; 26 #} 27 28 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 29 # 30 location ~ \.php$ { 31 root /usr/share/nginx/html; 32 fastcgi_pass 127.0.0.1:9000; 33 fastcgi_index index.php; 34 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 35 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 36 include fastcgi_params; 37 } 38 39 # deny access to .htaccess files, if Apache's document root 40 # concurs with nginx's one 41 # 42 #location ~ /\.ht { 43 # deny all; 44 #} 45 }
去掉30行至37行的注释,将root修改成19行的路径(默认localhost域名访问的文件路径)
考虑到国内的网速较慢,mysql文件包较大,使用yum安装不太现实,源码编译耗时较久,在此咱们采用rpm包安装!
能够参考官方文档:
http://dev.mysql.com/doc/refm...
按照官方文档,咱们须要逐一下载各个rpm包,然而官方文档也说了有打包好的rar供咱们下载,咱们须要作的只是按照本身的系统版本,下载对应的rar包
下表列出了各个系统对应mysql的rar包名,当前个人系统个版本是centOS7.1 64位,故我选择下载mysql-5.7.10-1.el7.x86_64.rpm-bundle.tar,带-bundle.tar的表明是全部rpm包的集合包!
注意:考虑到国内下载mysql官网mysql包可能较慢,特此提供国内的一个镜像:http://mirrors.sohu.com/mysql...
找到mysql-5.7.10-1.el7.x86_64.rpm-bundle.tar这个包,下载下来
下载的rar包能够在windows下用rar软件解压,而后搬到centos中,因为本人使用的是vagrant,因此直接将解压好的文件夹放到了共享目录,供虚拟机访问
进入解压好的mysql包文件夹
# cd mysql-5.7.10-1.el7.x86_64.rpm-bundle
使用yum进行安装(也可使用rpm命令安装,不过可能会遇到依赖性的错误,使用yum安装,最大好处就是不用解决软件包之间的依赖性!yum使用本地下载好的软件包安装起来也比较方便)
# sudo yum install mysql-community-{server,client,common,libs}-* mysql-5.*
看到相似如下输出
Dependencies Resolved ========================================================================================================================= Package Arch Version Repository Size ========================================================================================================================= Installing: mysql-community-client x86_64 5.7.10-1.el7 /mysql-community-client-5.7.10-1.el7.x86_64 109 M mysql-community-common x86_64 5.7.10-1.el7 /mysql-community-common-5.7.10-1.el7.x86_64 2.5 M mysql-community-libs x86_64 5.7.10-1.el7 /mysql-community-libs-5.7.10-1.el7.x86_64 9.8 M replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0 mysql-community-libs-compat x86_64 5.7.10-1.el7 /mysql-community-libs-compat-5.7.10-1.el7.x86_64 9.2 M replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0 Transaction Summary ========================================================================================================================= Install 4 Packages Total size: 130 M Is this ok [y/d/N]:
这里输入y。看到相似如下输出:
Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : mysql-community-common-5.7.10-1.el7.x86_64 1/5 Installing : mysql-community-libs-5.7.10-1.el7.x86_64 2/5 Installing : mysql-community-client-5.7.10-1.el7.x86_64 3/5 Installing : mysql-community-libs-compat-5.7.10-1.el7.x86_64 4/5 Erasing : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 5/5 warning: file /etc/my.cnf: remove failed: No such file or directory Verifying : mysql-community-common-5.7.10-1.el7.x86_64 1/5 Verifying : mysql-community-libs-5.7.10-1.el7.x86_64 2/5 Verifying : mysql-community-client-5.7.10-1.el7.x86_64 3/5 Verifying : mysql-community-libs-compat-5.7.10-1.el7.x86_64 4/5 Verifying : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 5/5 Installed: mysql-community-client.x86_64 0:5.7.10-1.el7 mysql-community-common.x86_64 0:5.7.10-1.el7 mysql-community-libs.x86_64 0:5.7.10-1.el7 mysql-community-libs-compat.x86_64 0:5.7.10-1.el7
本人测试过程当中发现没装上mysql-community-server.x86_64 0:5.7.10-1.el7
因而再次安装
# sudo yum install mysql-community-server-5.7.10-1.el7.x86_64.rpm
到此一共安装了六个软件包
启动mysql:
# sudo service mysqld start
验证是否启动成功:
# ps -aux | grep mysql
若是看到mysql进程则说明启动成功!
注意:新版mysql考虑到安全问题,root默认密码再也不是root,有些说法认为,新版mysql会在root家目录下生成一个".mysql_secret"文件,本人并未查看到该文件。
首先修改mysql配置文件
# sudo vim /etc/my.cnf
在[mysqld]下面添加"skip-grant-tables",表示禁用受权,这样用户能够直接登陆mysql!
重启mysql
# sudo service mysqld restart
登陆mysql
# mysq
进入到mysql客户端界面
mysql >use mysql; mysql >UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root'; mysql >FLUSH PRIVILEGES; mysql >quit;
注意:authentication_string=PASSWORD("NEWPASSWORD")中的PASSWORD是mysql的加密函数,用于生成加密字符串,因此不要漏掉这个函数!另外列名是User,而不是user。
注释配置文件中的免受权登陆代码
# sudo vim /etc/my.cnf
重启mysql:
# sudo service mysqld restart
重启登陆mysql客户端:
# mysql -uroot -p
输入密码,便可进行操做,若是仍是报1820的错,则说明以前你设置的密码不符合密码规则,为了安全 ,新版mysql密码规则有所变化,设置的密码需包含大写、小写字母、数字、特殊符号。
到此mysql安装、设置基本完成,为了方便后期开发,我选择新建一个超级用户,若是你也有该需求,能够参考
使用mysql自带客户端添加可远程登录的用户,首先使用root用户登录本地的mysql,执行如下命令:
mysq> GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY "你的密码" WITH GRANT OPTION;
上句代码新增了一个admin用户能够经过密码访问本机mysql数据库。
执行如下代码
mysq> GRANT ALL PRIVILEGES ON *.* TO admin@'%' IDENTIFIED BY "123456" WITH GRANT OPTION;
这一句代码则是授予用户admin用户经过任意主机访问mysql数据库
若是进行以上设置,依然没法远程链接,能够考虑有多是iptables的问题
退出mysql客户端
mysql> exit;
CentOS 7.0默认使用的是firewall做为防火墙,这里改成iptables防火墙。
关闭firewall:
# systemctl stop firewalld.service #中止firewall
# systemctl disable firewalld.service #禁止firewall开机启动