Linux命令:nginx及php和mysql安装使用
首先下载mysql-5.6.30-linux-glibc2.5-x86_64.tar.gzlftp 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
# ls
anaconda-ks.cfgDownloads Music Pictures Videos install.log mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz nginx-1.4.1 Templates
# du -lh mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
301Mmysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
# tar xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local
#解压缩,-C指定解压缩目录
# ls /usr/local/
bingames lib mysql-5.6.30-linux-glibc2.5-x86_64share
etcincludelib64lost+foundsbin
# mkdir /mydata/data -pv#-pv递归创建/mydata/data目录
mkdir: created directory `/mydata'
mkdir: created directory `/mydata/data'
# useradd -r mysql#新增mysql用户,-r指定创建的为系统用户,不作为登录用户
# chown -R mysql.mysql /mydata/data#更改属主和属组 -R指目录下的所有子文件
都一同更改属主和属组。
# cd /usr/local
# ln -sv mysql-5.6.30-linux-glibc2.5-x86_64 mysql#创建软链接
`mysql' -> `mysql-5.6.30-linux-glibc2.5-x86_64'
# cd mysql
# ll
total 68
drwxr-xr-x.2 root root 4096 Apr 16 15:23 bin
-rw-r--r--.1 7161 wheel 17987 Mar32016 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 wheel2496 Mar32016 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
# chown -R root.mysql ./*#-R递归更改属主和属组
# ll
total 68
drwxr-xr-x.2 root mysql4096 Apr 16 15:23 bin
-rw-r--r--.1 root mysql 17987 Mar32016 COPYING
drwxr-xr-x.3 root mysql4096 Apr 16 15:24 data
drwxr-xr-x.2 root mysql4096 Apr 16 15:24 docs
drwxr-xr-x.3 root mysql4096 Apr 16 15:23 include
drwxr-xr-x.3 root mysql4096 Apr 16 15:24 lib
drwxr-xr-x.4 root mysql4096 Apr 16 15:24 man
drwxr-xr-x. 10 root mysql4096 Apr 16 15:24 mysql-test
-rw-r--r--.1 root mysql2496 Mar32016 README
drwxr-xr-x.2 root mysql4096 Apr 16 15:24 scripts
drwxr-xr-x. 28 root mysql4096 Apr 16 15:24 share
drwxr-xr-x.4 root mysql4096 Apr 16 15:24 sql-bench
drwxr-xr-x.2 root mysql4096 Apr 16 15:24 support-files
# 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 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 ./bin/mysqld (mysqld 5.6.30) starting as process 11891 ...
2017-04-16 16:01:37 11891 InnoDB: Using atomics to ref count buffer pool pages
2017-04-16 16:01:37 11891 InnoDB: The InnoDB memory heap is disabled
2017-04-16 16:01:37 11891 InnoDB: Mutexes and rw_locks use GCC atomic builtins
....................................
Filling help tables...2017-04-16 16:01:42 0 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 ./bin/mysqld (mysqld 5.6.30) starting as process 11913 ...
2017-04-16 16:01:42 11913 InnoDB: Using atomics to ref count buffer pool pages
2017-04-16 16:01:42 11913 InnoDB: The InnoDB memory heap is disabled
2017-04-16 16:01:42 11913 InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-04-16 16:01:42 11913 InnoDB: Memory barrier is not used
2017-04-16 16:01:42 11913 InnoDB: Compressed tables use zlib 1.2.3
2017-04-16 16:01:42 11913 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#初始化完成
# vim my.cnf #编辑配置文件,在文档最后增加如下红色框内容
# cp support-files/mysql.server /etc/init.d/mysqld
复制mysqld启动脚本至/etc/init.d路径中
# chkconfig --add mysqld
# chkconfig --list mysqld
mysqld 0:off1:off2:off3:off4:off5:off6:off
# chkconfig mysqld on
# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
# service mysqld start#启用mysqld服务
Starting 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
# /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文件路径
# pwd
/usr/local/mysql
# vim my.cnf
# service mysqld restart
Shutting down MySQL..
Starting MySQL.
# /usr/local/mysql/bin/mysql #再次启动mysql客户端,正常开启。
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection> 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
# vim /etc/ld.so.conf.d/mysql.conf #新建mysql库路径文件,使得系统能够识别到
/usr/local/mysql/lib #新增该行内容
# 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)
# ln -sv /usr/local/mysql/include /usr/include/mysql #创建mysql的头文件目录链接,
使得可以直接输出头文件
"/usr/include/mysql" -> "/usr/local/mysql/include"
# ls /usr/include/mysql/
decimal.h my_attribute.hmy_global.h mysqld_ername.hmy_sys.h
my_alloc.hmy_getopt.h mysql_com.h mysql_version.hsql_common.h
------------------------------------------------------------------------------
至此MySQL已经安装配置完成。
首先下载安装PHP-5.4.13
# 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
# ls
anaconda-ks.cfginstall.lognginx-1.4.1Templates
Desktop install.log.syslog php-5.4.13.tar.bz2Videos
# tar xf php-5.4.13.tar.bz2
# cd 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
# 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/
Archive_Tar - installed: 1.3.7
Console_Getopt - installed: 1.3.0
Structures_Graph- installed: 1.0.4
XML_Util - installed: 1.2.1
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/
# cp php.ini-production /etc/php.ini #为php提供配置文件
# cd /usr/local/php/etc/
# ls
pear.confphp-fpm.conf.default
# cp php-fpm.conf.default php-fpm.conf#为php-fpm提供配置文件
# vim php-fpm.conf#编辑配置文件,修改内容如图:
# cd -#进入上一次所在目录
/root/php-5.4.13
# pwd
/root/php-5.4.13
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm#复制启动脚本
至/etc/init.d路径下
# chmod +x /etc/init.d/php-fpm #给执行权限
# chkconfig --add php-fpm#把服务添加至开机启动列表
# chkconfig --list php-fpm#查看php-fpm服务是否开机自动启动
php-fpm 0:off1:off2:on3:on4:on5:on6:off
# service php-fpm start#启动php-fpm服务
Starting php-fpmdone
# 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
# cd /etc/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.defaultmime.types.defaultscgi_params.default
# ps aux#查看系统进程,php-fpm是否一启动就开启了8个子进程
(php-fpm配置文档中设置一启动php-fpm进程就启动8个子进程)
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postfix230300.00.1620522680 ? S 08:36 0:00 pickup -l -t fifo -u
root 230600.00.2 1074604564 ? Ss 08:45 0:00 php-fpm: master process (/usr/local/php/e
nobody 230610.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
nobody 230620.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
nobody 230630.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
nobody 230640.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
nobody 230650.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
nobody 230660.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
nobody230670.00.1 1074603728 ?S 08:45 0:00 php-fpm: pool www
nobody 230680.00.1 1074603728 ?S08:45 0:00 php-fpm: pool www
# vim nginx.conf#编辑nginx配置文件,启用php功能,如下图:
# 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;
# nginx -t#检测nginx配置文档是否有语法错误
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# service nginx> nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reloading nginx:
# cd /usr/html
# ls
50x.htmlindex.html
# mv index.html index.back#修改默认网页文件名称
# vim index.php#新建.php网页文件,内容如下:
# 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
页:
[1]