道者编程


php5.5 nginx mysql linux安装

一:nginx安装

nginx有三个版本:

Mainline version:Nginx 目前主力在做的版本,开发版
Stable version:最新稳定版,生产环境上建议使用
Legacy versions:遗留的老版本的稳定版,因为用的人多还在维护,长远看会放弃

1:安装安装相应的编译工具

# yum -y install gcc gcc-c++ autoconf automake
# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
 2:编译安装:
  
# tar -zxf nginx-1.6.3.tar.gz 
# cd nginx-1.6.3
# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
# make
# make install
 3:启动
# /usr/local/nginx/sbin/nginx
# /usr/local/nginx/sbin/nginx -s reload //重启
 

client_max_body_size 100M;    #允许客户端请求的最大单文件字节数

client_body_buffer_size 128k;  #缓冲区代理缓冲用户端请求的最大字节数, 


二:编译安装mysql5.6

1:如果是编译需要先安装工具包: 

# yum install cmake

2:先检查服务器是否有mysql存在

#rpm -qa | grep mariadb #mysql也查一下
mariadb-libs-5.5.52-1.el7.x86_64 
 卸载掉:

rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
 

3:这里采用RPM安装

# cd mysql5.6
# rpm -ivh *rpm  //安装所有mysql安装包

 如果提示没有perl执行:

yum install -y perl-Module-Install.noarch perl-JSON.noarch
 如果安装不上,可以单独安装,一般安装MySQL-server和MySQL-client即可,安装必须要100%

4::修改文件配置信息

[root@localhost MySQL-5.6.24]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf 

5:启动mysql

systemctl start mysql #Centos7用这个
service mysql start

6:初始化设置密码

   
 [root@localhost MySQL-5.6.24]# /usr/bin/mysql_install_db
 
7: 查看root密码
  
[root@localhost MySQL-5.6.24]# cat /root/.mysql_secret
# The random password set for the root user at Fri 
May 29 16:09:16 2015 (local time): QjFwdkcq6CNdvenI

 8:设置密码

先启动mysql,注意以前启动命令是service mysql start ,centos7用systemctl  代替了iptables,所以应该用:systemctl  start mysql

[root@localhost MySQL-5.6.24]# mysql -uroot -p
mysql> set password=password('123');
Query OK, 0 rows affected (0.00 sec)


如果忘记密码,找到my.cnf,在里面添加skip-grant-tables,然后进入mysql控制台,无密码直接回车

usr mysql; //选择mysql数据库
update user set password=password("123") where user="root";

 成功后再执行:

set password=password('123');
 

三:编译PHP 5.5

1:编译安装

  
yum install libxm12 libxml2-devel BZip2-devel bzip2-devel curl curl-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel -y
 

 

# tar -xvf php-5.5.25.tar.gz
# cd php-5.5.25
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --enable-bcmath --enable-soap --enable-zip --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-ipv6 --with-zlib --with-curl --with-pdo-mysql --with-openssl --enable-fpm --with-mysql --with-mysqli
 

注意:如果mysql是源安装,那么--with-mysql=/usr/local/mysql 指定安装路径 如果是rpm安装 则--with-mysql即可,--with-mysqli=/usr/local/mysql/bin/mysql_config

其中 fpm是必须安装的,nginx通过fpm解析php

# make
# make install
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp php.ini-production /usr/local/php/etc/php.ini
 设置php.ini

short_open_tag = On 开启短标签
error_reporting =E_ALL & ~E_NOTICE & ~E_DEPRECATED  
display_errors = On 
date.timezone="asia/shanghai" 设置时间
upload_max_filesize = 2M //文件上传大小
post_max_size = 8M //POST最大字节数
max_execution_time=30 //每个PHP页面运行的最大时间值(秒),默认30秒
max_input_time = 60 //每个PHP页面接收数据所需的最大时间,默认60秒
memory_limit = 128m //每个PHP页面所吃掉的最大内存
 

启动fpm 

# /usr/local/php/sbin/php-fpm
 

配置nginx解析PHP:

nginx默认以nodoby运行,查看php-fpm.conf的user和 group,均可以改为nobody。然后把nginx下的fastcgi_temp目录递归改为 nobody。:

# chown nobody:nobody -R /fastcgi_temp

#user  nobody; 默认以nobody;root为最高权限
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    client_max_body_size 100M;    #允许客户端请求的最大单文件字节数
    client_body_buffer_size 128k;  #缓冲区代理缓冲用户端请求的最大字节数,

    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name 127.0.0.1;
        index index.php index.html index.htm;
        root /usr/local/www;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/www/;
            index  index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
		
		location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
	
	
	 server {
        listen 80;
        server_name www.xx.cn;
        index index.php index.html index.htm;
        root /usr/local/www/zg;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
($document_root 为root目录,php的目录)


最新评论:
我要评论:

看不清楚


链接