码迷,mamicode.com
首页 > 数据库 > 详细

Linux命令:nginx及php和mysql安装使用

时间:2017-08-12 22:28:16      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:nginx   php   mysql   


首先下载mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz


lftp test@10.109.134.247:/> get mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 

314592758 bytes transferred in 28 seconds (10.66M/s)                                              

lftp test@10.109.134.247:/> quit

[root@lamp ~]# ls

anaconda-ks.cfg  Downloads      Music     Pictures   Videos   install.log     mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz   nginx-1.4.1      Templates

[root@lamp ~]# du -lh mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz 

301Mmysql-5.6.30-linux-glibc2.5-x86_64.tar.gz

[root@lamp ~]# tar xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local 

#解压缩,-C指定解压缩目录

[root@lamp ~]# ls /usr/local/

bin  games    lib     mysql-5.6.30-linux-glibc2.5-x86_64  share

etc  include  lib64  lost+found  sbin                               

[root@lamp ~]# mkdir /mydata/data -pv  #-pv递归创建/mydata/data目录

mkdir: created directory `/mydata‘

mkdir: created directory `/mydata/data‘

[root@lamp ~]# useradd -r mysql  #新增mysql用户,-r指定创建的为系统用户,不作为登录用户

[root@lamp ~]# chown -R mysql.mysql /mydata/data  #更改属主和属组 -R指目录下的所有子文件

都一同更改属主和属组。

[root@lamp ~]# cd /usr/local

[root@lamp local]# ln -sv mysql-5.6.30-linux-glibc2.5-x86_64 mysql  #创建软链接

`mysql‘ -> `mysql-5.6.30-linux-glibc2.5-x86_64‘

[root@lamp local]# cd mysql

[root@lamp mysql]# ll

total 68

drwxr-xr-x.  2 root root   4096 Apr 16 15:23 bin

-rw-r--r--.  1 7161 wheel 17987 Mar  3  2016 COPYING

drwxr-xr-x.  3 root root   4096 Apr 16 15:24 data

drwxr-xr-x.  2 root root   4096 Apr 16 15:24 docs

drwxr-xr-x.  3 root root   4096 Apr 16 15:23 include

drwxr-xr-x.  3 root root   4096 Apr 16 15:24 lib

drwxr-xr-x.  4 root root   4096 Apr 16 15:24 man

drwxr-xr-x. 10 root root   4096 Apr 16 15:24 mysql-test

-rw-r--r--.  1 7161 wheel  2496 Mar  3  2016 README

drwxr-xr-x.  2 root root   4096 Apr 16 15:24 scripts

drwxr-xr-x. 28 root root   4096 Apr 16 15:24 share

drwxr-xr-x.  4 root root   4096 Apr 16 15:24 sql-bench

drwxr-xr-x.  2 root root   4096 Apr 16 15:24 support-files

[root@lamp mysql]# chown -R root.mysql ./*  #-R递归更改属主和属组

[root@lamp mysql]# ll

total 68

drwxr-xr-x.  2 root mysql  4096 Apr 16 15:23 bin

-rw-r--r--.  1 root mysql 17987 Mar  3  2016 COPYING

drwxr-xr-x.  3 root mysql  4096 Apr 16 15:24 data

drwxr-xr-x.  2 root mysql  4096 Apr 16 15:24 docs

drwxr-xr-x.  3 root mysql  4096 Apr 16 15:23 include

drwxr-xr-x.  3 root mysql  4096 Apr 16 15:24 lib

drwxr-xr-x.  4 root mysql  4096 Apr 16 15:24 man

drwxr-xr-x. 10 root mysql  4096 Apr 16 15:24 mysql-test

-rw-r--r--.  1 root mysql  2496 Mar  3  2016 README

drwxr-xr-x.  2 root mysql  4096 Apr 16 15:24 scripts

drwxr-xr-x. 28 root mysql  4096 Apr 16 15:24 share

drwxr-xr-x.  4 root mysql  4096 Apr 16 15:24 sql-bench

drwxr-xr-x.  2 root mysql  4096 Apr 16 15:24 support-files

[root@lamp mysql]# scripts/mysql_install_db  --user=mysql --datadir=/mydata/data

#初始化数据库,指定数据库用户--user=mysql,指定数据目录--datadir=/mydata/data

Installing MySQL system tables...2017-04-16 16:01:37 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-04-16 16:01:37 0 [Note] ./bin/mysqld (mysqld 5.6.30) starting as process 11891 ...

2017-04-16 16:01:37 11891 [Note] InnoDB: Using atomics to ref count buffer pool pages

2017-04-16 16:01:37 11891 [Note] InnoDB: The InnoDB memory heap is disabled

2017-04-16 16:01:37 11891 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

....................................

Filling help tables...2017-04-16 16:01:42 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2017-04-16 16:01:42 0 [Note] ./bin/mysqld (mysqld 5.6.30) starting as process 11913 ...

2017-04-16 16:01:42 11913 [Note] InnoDB: Using atomics to ref count buffer pool pages

2017-04-16 16:01:42 11913 [Note] InnoDB: The InnoDB memory heap is disabled

2017-04-16 16:01:42 11913 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2017-04-16 16:01:42 11913 [Note] InnoDB: Memory barrier is not used

2017-04-16 16:01:42 11913 [Note] InnoDB: Compressed tables use zlib 1.2.3

2017-04-16 16:01:42 11913 [Note] InnoDB: Using Linux native AIO

..........................................

WARNING: Default config file /etc/my.cnf exists on the system

This file will be read by default by the MySQL server

If you do not want to use this, either remove it, or use the

--defaults-file argument to mysqld_safe when starting the server  #初始化完成

[root@lamp mysql]# vim my.cnf #编辑配置文件,在文档最后增加如下红色框内容

技术分享

[root@lamp mysql]# cp support-files/mysql.server /etc/init.d/mysqld 

复制mysqld启动脚本至/etc/init.d路径中

[root@lamp mysql]# chkconfig --add mysqld

[root@lamp mysql]# chkconfig --list mysqld

mysqld         0:off1:off2:off3:off4:off5:off6:off

[root@lamp mysql]# chkconfig mysqld on

[root@lamp mysql]# chkconfig --list mysqld

mysqld         0:off1:off2:on3:on4:on5:on6:off

[root@lamp mysql]# service mysqld start  #启用mysqld服务

Starting MySQL....                             [  OK  ] 

[root@lamp mysql]# netstat -tlnp  #查看监听的端口

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address    Foreign Address    State   PID/Program name 

tcp   0   0 0.0.0.0:111    0.0.0.0:*       LISTEN      1369/rpcbind        

tcp   0   0 0.0.0.0:80     0.0.0.0:*       LISTEN      7277/nginx.conf     

tcp   0   0 0.0.0.0:59282   0.0.0.0:*       LISTEN      1436/rpc.statd      

tcp   0   0 0.0.0.0:22     0.0.0.0:*       LISTEN      1659/sshd           

tcp   0   0 127.0.0.1:631   0.0.0.0:*       LISTEN      1532/cupsd          

tcp   0   0 127.0.0.1:25   0.0.0.0:*       LISTEN      1735/master         

tcp   0   0 :::3306         :::*       LISTEN      12224/mysqld        

tcp   0   0 :::111         :::*        LISTEN     1369/rpcbind        

tcp   0   0 :::22         :::*         LISTEN      1659/sshd           

tcp   0   0 ::1:631        :::*        LISTEN      1532/cupsd          

tcp   0   0 :::35043       :::*         LISTEN      1436/rpc.statd   

[root@lamp mysql]# /usr/local/mysql/bin/mysql  #启动mysql客户端

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)  #提示mysql.sock出错,解决方法如下图,在配置文档中定义sock文件路径

[root@lamp mysql]# pwd

/usr/local/mysql

[root@lamp mysql]# vim my.cnf 

技术分享

[root@lamp mysql]# service mysqld restart

Shutting down MySQL..                                 [  OK  ]

Starting MySQL.                                     [  OK  ]

[root@lamp mysql]# /usr/local/mysql/bin/mysql #再次启动mysql客户端,正常开启。

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.30-log MySQL Community Server (GPL)

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.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> 

mysql> \q

[root@lamp ~]# vim /etc/ld.so.conf.d/mysql.conf #新建mysql库路径文件,使得系统能够识别到

 /usr/local/mysql/lib       #新增该行内容

[root@lamp ~]# ldconfig -v   #通知系统重新读取库文件,-v显示重读过程

............

libxklavier.so.15 -> libxklavier.so.15.0.0

liblcms.so.1 -> liblcms.so.1.0.19

/lib64/tls: (hwcap: 0x8000000000000000)

/usr/lib64/sse2: (hwcap: 0x0000000004000000)

/usr/lib64/tls: (hwcap: 0x8000000000000000)

[root@lamp ~]# ln -sv /usr/local/mysql/include /usr/include/mysql #创建mysql的头文件目录链接,

使得可以直接输出头文件

"/usr/include/mysql" -> "/usr/local/mysql/include"

[root@lamp ~]# ls /usr/include/mysql/

decimal.h   my_attribute.h  my_global.h   mysqld_ername.h  my_sys.h             

my_alloc.h  my_getopt.h     mysql_com.h   mysql_version.h  sql_common.h

------------------------------------------------------------------------------

至此MySQL已经安装配置完成。

首先下载安装PHP-5.4.13

[root@lamp mysql]# lftp test@10.109.134.247

Password: 

lftp test@10.109.134.247:/> get php-5.4.13.tar.bz2 

11545777 bytes transferred                              

lftp test@10.109.134.247:/> quit

[root@lamp ~]# ls

anaconda-ks.cfg  install.log  nginx-1.4.1  Templates

Desktop   install.log.syslog   php-5.4.13.tar.bz2  Videos

[root@lamp ~]# tar xf php-5.4.13.tar.bz2

[root@lamp ~]# cd php-5.4.13

[root@lamp php-5.4.13]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl

#编译php,指定php安装目录--prefix=/usr/local/php 关联mysql安装的目录--with-mysql=/usr/local/mysql等支持各种功能。

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking for a sed that does not truncate output... /bin/sed

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

checking for cc... cc

.......................

+--------------------------------------------------------------------+

| License:                                                           |

| This software is subject to the PHP License, available in this     |

| distribution in the file LICENSE.  By continuing this installation |

| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |

| the installation process at this point.                            |

+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/fpm/php-fpm.conf

config.status: creating sapi/fpm/init.d.php-fpm

config.status: creating sapi/fpm/php-fpm.service

config.status: creating sapi/fpm/php-fpm.8

config.status: creating sapi/fpm/status.html

config.status: creating main/php_config.h

config.status: executing default commands

[root@lamp php-5.4.13]# make && make install  #编译安装

Installing PHP CLI binary:        /usr/local/php/bin/

Installing PHP CLI man page:      /usr/local/php/php/man/man1/

Installing PHP FPM binary:        /usr/local/php/sbin/

Installing PHP FPM config:        /usr/local/php/etc/

Installing PHP FPM man page:      /usr/local/php/php/man/man8/

Installing PHP FPM status page:      /usr/local/php/php/fpm/

Installing PHP CGI binary:        /usr/local/php/bin/

Installing build environment:     /usr/local/php/lib/php/build/

Installing header files:          /usr/local/php/include/php/

Installing helper programs:       /usr/local/php/bin/

  program: phpize

  program: php-config

Installing man pages:             /usr/local/php/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment:      /usr/local/php/lib/php/

[PEAR] Archive_Tar    - installed: 1.3.7

[PEAR] Console_Getopt - installed: 1.3.0

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util       - installed: 1.2.1

[PEAR] PEAR           - installed: 1.9.4

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf

You may want to add: /usr/local/php/lib/php to your php.ini include_path

/root/php-5.4.13/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar

Installing PDO headers:          /usr/local/php/include/php/ext/pdo/

[root@lamp php-5.4.13]# cp php.ini-production /etc/php.ini #为php提供配置文件

[root@lamp php-5.4.13]# cd /usr/local/php/etc/

[root@lamp etc]# ls

pear.conf  php-fpm.conf.default

[root@lamp etc]# cp php-fpm.conf.default php-fpm.conf  #为php-fpm提供配置文件

[root@lamp etc]# vim php-fpm.conf  #编辑配置文件,修改内容如图:

技术分享[root@lamp etc]# cd -  #进入上一次所在目录

/root/php-5.4.13 

[root@lamp php-5.4.13]# pwd

/root/php-5.4.13

[root@lamp php-5.4.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  #复制启动脚本

至/etc/init.d路径下

[root@lamp php-5.4.13]# chmod +x /etc/init.d/php-fpm #给执行权限


[root@lamp php-5.4.13]# chkconfig --add php-fpm  #把服务添加至开机启动列表

[root@lamp php-5.4.13]# chkconfig --list php-fpm  #查看php-fpm服务是否开机自动启动

php-fpm         0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@lamp php-5.4.13]# service php-fpm start  #启动php-fpm服务

Starting php-fpm  done

[root@lamp php-5.4.13]# netstat -tlnp  #查看监听端口

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address   Foreign Address   State     PID/Program name   

tcp   0    0 127.0.0.1:9000       0.0.0.0:*     LISTEN    23060/php-fpm.conf) 

tcp   0    0 0.0.0.0:111         0.0.0.0:*     LISTEN    1369/rpcbind       tcp   0    0 0.0.0.0:80         0.0.0.0:*     LISTEN     7277/nginx.conf     

tcp   0   0 0.0.0.0:59282        0.0.0.0:*     LISTEN      1436/rpc.statd    

tcp   0   0 0.0.0.0:22          0.0.0.0:*     LISTEN      1659/sshd     

tcp   0   0 :::3306             :::*       LISTEN      13345/mysqld  

tcp   0   0 :::22              :::*       LISTEN      1659/sshd    

[root@lamp php-5.4.13]# cd /etc/nginx

[root@lamp nginx]# ls

fastcgi.conf   koi-utf    nginx.conf    uwsgi_params

fastcgi.conf.default    koi-win    nginx.conf.default   uwsgi_params.default

fastcgi_params     mime.types     scgi_params      win-utf

fastcgi_params.default  mime.types.default  scgi_params.default

[root@lamp nginx]# ps aux  #查看系统进程,php-fpm是否一启动就开启了8个子进程

(php-fpm配置文档中设置一启动php-fpm进程就启动8个子进程)

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

postfix  23030  0.0  0.1  62052  2680 ? S    08:36   0:00 pickup -l -t fifo -u

root    23060  0.0  0.2 107460  4564 ? Ss   08:45   0:00 php-fpm: master process (/usr/local/php/e

nobody   23061  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www

nobody   23062  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www   

nobody   23063  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www  

nobody   23064  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www  

nobody   23065  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www

nobody   23066  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www 

nobody  23067  0.0  0.1 107460  3728 ?  S   08:45   0:00 php-fpm: pool www      

nobody   23068  0.0  0.1 107460  3728 ?  S  08:45   0:00 php-fpm: pool www   

[root@lamp nginx]# vim nginx.conf  #编辑nginx配置文件,启用php功能,如下图:

技术分享

[root@lamp nginx]# vim fastcgi_params  #编辑fastcgi配置文档,删除该文档之前的内容

技术分享

新增以下内容,保存并退出:

  fastcgi_param   GATEWAY_INTERFACE     CGI/1.1;

  fastcgi_param   SERVER_SOFTWARE      nginx;

  fastcgi_param   QUERY_STRING        $query_string;

  fastcgi_param   REQUEST_METHOD       $request_method;

  fastcgi_param   CONTENT_TYPE        $content_type;

  fastcgi_param   CONTENT_LENGTH       $content_length;

  fastcgi_param   SCRIPT_FILENAME      $document_root$fastcgi_script_name;

  fastcgi_param   SCRIPT_NAME         $fastcgi_script_name;

  fastcgi_param   REQUEST_URI         $request_uri;

  fastcgi_param   DOCUMENT_URI        $document_uri;

  fastcgi_param   DOCUMENT_ROOT      $document_root;

  fastcgi_param   SERVER_PROTOCOL      $server_protocol;

  fastcgi_param   REMOTE_ADDR         $remote_addr;

  fastcgi_param   REMOTE_PORT         $remote_port;

  fastcgi_param   SERVER_ADDR         $server_addr;

  fastcgi_param   SERVER_PORT         $server_port;

  fastcgi_param   SERVER_NAME         $server_name;

[root@lamp nginx]# nginx -t  #检测nginx配置文档是否有语法错误

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@lamp nginx]# service nginx reload  #重新加载nginx服务

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

Reloading nginx:                                [  OK  ]

[root@lamp nginx]# cd /usr/html

[root@lamp html]# ls

50x.html  index.html

[root@lamp html]# mv index.html index.back  #修改默认网页文件名称

[root@lamp html]# vim index.php  #新建.php网页文件,内容如下:

<?php

phpinfo();

?>

[root@lamp html]# vim /etc/nginx/nginx.conf #把index.php默认主页的格式加入到配置文档

技术分享

在浏览器中输入IP访问测试如下:

技术分享

必须给nginx安装xcache缓存加速



mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz下载地址:https://pan.baidu.com/s/1skJOITZ

php-5.4.13.tar.bz2下载地址:http://us3.php.net/distributions/php-5.4.13.tar.bz2

本文出自 “学linux历程” 博客,请务必保留此出处http://woyaoxuelinux.blog.51cto.com/5663865/1955685

Linux命令:nginx及php和mysql安装使用

标签:nginx   php   mysql   

原文地址:http://woyaoxuelinux.blog.51cto.com/5663865/1955685

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!