当前位置:8090社团 >环境搭建 > 查看文章
阿里云优惠码
软件版本如下

MySQL-5.7.15-linux-glibc2.5-i686.tar.gz 二进制包

php 7.1.0.

Nginx 1.10.2

 


一、安装MySQL
1、下载安装包
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.15-linux-glibc2.5-i686.tar

 

 

2.检查库文件是否存在,如有删除。

 [root@localhost Desktop]$ rpm -qa | grep mysql mysql-libs-5.1.52-1.el6_0.1.x86_64

[root@localhost ~]# rpm -e mysql-libs-5.1.52.x86_64 --nodeps 

3.检查mysql组和用户是否存在,如无创建。

[root@test4 src]# grep 'mysql' /etc/passwd mysql:x:500:500::/home/mysql:/sbin/nologin

以上为默认存在的情况,如无,执行添加命令:

[root@test4 src]#useradd -S /sbin/nologin mysql -M // useradd -S 指定Shell -M 不创建家目录 

4.解压TAR包,更改所属的组和用户

 [root@test4 src]#tar zvxf mysql-5.7.15-linux-glibc2.5-i686.tar.gz
 [root@test4 src]#mv mysql-5.7.15-linux-glibc2.5-i686 /usr/local/mysql
 [root@test4 src]#cd /usr/local/mysql
 [root@test4 mysql]#mkdir /opt/mysql #创建数据库存放目录
 [root@test4 mysql]#chown mysql.mysql /opt/mysql    

5.安装和初始化数据库

 [root@test4 mysql]# ./bin/mysqld --initialize --user=mysql \
 --datadir=/opt/mysql --basedir=/usr/local/mysql
 ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory    

[root@test4 mysql]# yum install libaio-devel -y
 [root@test4 mysql5.7]# ./bin/mysqld --initialize --user=mysql \
 --datadir=/opt/mysql --basedir=/usr/local/mysql

2016-03-17T09:01:34.422954Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use
 --explicit_defaults_for_timestamp server option (see documentation for more details).
 2016-03-17T09:01:34.423437Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
 2016-03-17T09:01:34.439826Z 0 [ERROR] Error message file '/usr/local/mysql/share/english/errmsg.sys'
 had only 886 error messages, but it should contain at least 1080 error messages. Check that the above file is
 the right version for this program! mysqld: Can't create/write to file '/tmp/ibbawRse' (Errcode: 13 - Permission denied)
 2016-03-17T09:01:34.517823Z 0 [ERROR] InnoDB: Unable to create temporary file; errno: 13
 2016-03-17T09:01:34.517842Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
 2016-03-17T09:01:34.517854Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
 2016-03-17T09:01:34.517861Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
 2016-03-17T09:01:34.517868Z 0 [ERROR] Failed to initialize plugins.
 2016-03-17T09:01:34.517873Z 0 [ERROR] Aborting    

[root@test4 mysql5.7]# chmod 777 /tmp/
 [root@test4 mysql5.7]# ./bin/mysqld --initialize --user=mysql --datadir=/opt/mysql \
 --basedir=/usr/local/mysql
 2016-03-17T09:05:53.394688Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use
 --explicit_defaults_for_timestamp server option (see documentation for more details).
 2016-03-17T09:05:53.394770Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
 2016-03-17T09:05:56.355967Z 0 [Warning] InnoDB: New log files created, LSN=45790
 2016-03-17T09:05:56.962608Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
 2016-03-17T09:05:57.030890Z 0 [Warning] No existing UUID has been found, so we assume that this is the first
 time that this server has been started. Generating a new UUID: 75de3ec0-ec1f-11e5-8bdd-000c294dd782.
 2016-03-17T09:05:57.034888Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
 2016-03-17T09:05:57.035944Z 1 [Note] A temporary password is generated for root@localhost: 2PviOLY#Zksa    

7.拷贝配置文件

 [root@test4 mysql]# cp support-files/my-default.cnf /etc/my.cnf
 [root@test4 mysql]# cp support-files/mysql.server /etc/init.d/mysqld

如果改变默认安装路径,则需要

 1)/etc/my.cnf、/etc/init.d/mysqld中修改 basedir='/usr/local/mysql' datadir='/opt/mysql'
 [root@test4 mysql]#chkconfig --add mysqld #加入系统服务
 [root@test4 mysql]# chkconfig --level 35 mysqld on #设为开机启动

8.初始化密码 mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。

 [root@test4 ~]# cat /root/.mysql_history   # Password set for user 'root@localhost' at 2016-06-01 15:23:25 2PviOLY#Zksa  

9.启动MySQL

[root@test4 ~]# service mysqld start Starting MySQL...... SUCCESS!
 //设置系统环境变量
 [root@test4 local]# vim /etc/profile   export PATH=$PATH:/usr/local/mysql/bin/
 [root@test4 local]# source !$ source /etc/profile
 [root@test4 local]# mysql -V mysql Ver 14.14 Distrib 5.7.15, for linux-glibc2.5 (i686) using EditLine wrapper  

//修改MySQL密码

 [root@test4 local]# mysql -uroot -p2PviOLY#Zksa   mysql: [Warning] Using a password on the command line interface
 can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2
 Server version: 5.7.15   Copyright (c) 2000, 2016, 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.   T
 ype 'help;' or '\h' for help. Type '\c' to clear the current input statement.  

mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)    

忘记密码时用以下语句

update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';  

10.添加远程访问权限

 mysql> use mysql;
 Reading table information for completion of table and column names You can turn off this feature to
 get a quicker startup with -A   Database changed

mysql> update user set host = '%' where user = 'root';
 Query OK, 1 row affected (0.18 sec) Rows matched: 1 Changed: 1 Warnings: 0
 mysql> select host, user from user;
 +-----------+-----------+
 | host | user |
 +-----------+-----------+
 | % | root |
 | localhost | mysql.sys |
 +-----------+-----------+
 2 rows in set (0.00 sec)
 mysql> quit  

重启生效 /etc/init.d/mysqld restart

[root@test4 local]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

二、安装php
针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,
可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。
php官方下载地址: http://www.php.net/downloads.php

1、下载php

[root@test4 src] wget http://cn.php.net/distributions/php-7.1.0.tar.gz 

2、解压php

[root@test4 src]# tar zvxf php-7.1.0.tar.gz

3、创建相关账户

[root@test4 src] useradd -s /sbin/nologin php-fpm -M
4、配置编译参数
[root@test4 src]# cd php-7.1.0
[root@test4 php-7.1.0]# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-pdo-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-jpeg-dir \
--with-xmlrpc \
--with-xsl \
--enable-bcmath \
--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

错误信息:
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

解决办法:

[root@test4 php-7.1.0]# yum install libxslt-devel -y

collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

[root@test php-5.2.13]# vi Makefile

在安裝 PHP 到系统中时要是发生「undefined reference to libiconv_open’」之类的错误信息,
那表示在「./configure 」沒抓好一些环境变数值。错误发生点在建立「-o sapi/cli/php」是出错,没給到要 link 的 iconv 函式库参数。
解决方法:编辑Makefile 大约77 行左右的地方: EXTRA_LIBS = ….. -lcrypt 在最后加上 -liconv,
例如: EXTRA_LIBS = ….. -lcrypt -liconv 然后重新再次 make 即可。

或者用另一种办法

make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/

5、编译php

[root@test4 php-7.1.0]# make

以上每一个步骤,如果没有完全执行正确,那么下一步是无法进行的,
判断执行是否正确的方法使用 echo $? 看结果是否为 “0” , 如果不是,就是没有执行正确。

6、安装php

[root@test4 php-7.1.0]# make install

7、修改配置文件

[root@test4 php-7.1.0]# cp php.ini-production /usr/local/php/etc/php.ini
[root@test4 php-7.1.0]# vim /usr/local/php/etc/php-fpm.conf

把如下内容写入该文件:

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.group = www
listen.owner = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

保存配置文件后,检验配置是否正确的方法为:

/usr/local/php/sbin/php-fpm -t

如果出现诸如 “test is successful” 字样,说明配置没有问题。

8、启动php-fpm

[root@test4 php-7.1.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@test4 php-7.1.0]# chmod 755 /etc/init.d/php-fpm
[root@test4 php-7.1.0]# chkconfig --add php-fpm

如果想让它开机启动,执行:

[root@test4 php-7.1.0]# chkconfig php-fpm on
[root@test4 php-7.1.0]# service php-fpm start

检测是否启动:

ps aux |grep php-fpm

看看是不是有很多个进程(大概20多个)。

三、安装Nginx
Nginx官方网站(http://nginx.org)

1.下载nginx

[root@test4 src]# useradd -s /sbin/nologin www -M
[root@test4 ~]# cd /usr/local/src/
[root@test4 src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz

2.解压nginx

[root@test4 src]# tar zxvf nginx-1.10.2.tar.gz
[root@test4 src]# cd nginx-1.10.2

3.配置编译参数

[root@test4 nginx-1.10.2]# ./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_realip_module \
--with-http_v2_module \
--with-ipv6 \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-stream

4.编译nginx

[root@test4 nginx-1.10.2]# make

5.安装nginx

[root@test4 nginx-1.10.2]# make install

6.编写nginx启动脚本,并加入系统服务

[root@test4 nginx-1.10.2]#vim /etc/init.d/nginx

写入如下内容:

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}

 
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}

 
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}

 
restart(){
stop
start
}


configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}

 
case "$1" in
start)
start
;;
stop)
stop
;;

reload)
reload
;;

restart)
restart
;;

configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL  

保存后,更改权限:

[root@test4 nginx-1.10.2]#chmod 755 /etc/init.d/nginx 
[root@test4 nginx-1.10.2]#chkconfig --add nginx

如果想开机启动,请执行:

[root@test4 nginx-1.10.2]#chkconfig nginx on

7.更改nginx配置
首先把原来的配置文件清空:

[root@test4 nginx-1.10.2]#> /usr/local/nginx/conf/nginx.conf

“>” 为重定向的意思,单独用它,可以把一个文本文档快速清空。

[root@test4 nginx-1.10.2]#vim /usr/local/nginx/conf/nginx.conf

写入如下内容:

user www www;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}

 
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;

 


server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;


location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
#fastcgi_pass 10.162.85.187:9000;
fastcgi_index index.php;
fastcgi_read_timeout 1000;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;

}

include vhost/*.conf;
}
}

保存配置后,先检验一下配置文件是否有错误存在:

/usr/local/nginx/sbin/nginx -t

如果显示内容如下,则配置正确,否则需要根据错误提示修改配置文件:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx:

service nginx start

如果不能启动,请查看 “/usr/local/nginx/logs/error.log” 文件,检查nginx是否启动:

ps aux |grep nginx
看是否有进程。

测试是否解析php文件
创建测试文件:

[root@test4 nginx-1.10.2]# vim /usr/local/nginx/html/2.php

内容如下:

<?php echo "测试php是否解析"; ?>

测试:

[root@test4 nginx-1.10.2]# curl localhost/2.php
测试php是否解析

显示成这样,才说明php解析正确。

相关文章
为您推荐
各种观点
暂时还木有人评论,坐等沙发!
发表评论

快捷键:Ctrl+Enter