LAMP架构下,而后搭建LNMP架构 1.首先查看mysql是否启动 ps aux |grep mysql 2.删除目录 rm -rf /usr/local/mysql/ 3.删除启动的脚本 rm -rf /etc/init.d/mysqld 4.而后其余步骤相同
[root@hanfeng ~]# cd /usr/local/src [root@hanfeng src]#
[root@hanfeng src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@hanfeng src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
[root@hanfeng src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql [root@hanfeng src]#
[root@hanfeng src]# ls /usr/local/mysql bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench [root@hanfeng src]#
[root@hanfeng src]# cd /usr/local/mysql [root@hanfeng mysql]#
[root@hanfeng mysql]# useradd mysql [root@hanfeng mysql]# mkdir /data/ [root@hanfeng mysql]#
[root@hanfeng mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
yum install -y perl-Data-Dumper
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio
[root@hanfeng mysql]# echo $? 0 [root@hanfeng mysql]#
[root@hanfeng mysql]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
拷贝后php
[root@hanfeng mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@hanfeng mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@hanfeng mysql]# vim /etc/init.d/mysqld 在文件中配置 basedir=/usr/local/mysql datadir=/data/mysql 而后保存退出
[root@hanfeng mysql]# /etc/init.d/mysqld start Starting MySQL.Logging to '/data/mysql/hanfeng.err'. . SUCCESS! [root@hanfeng mysql]#
[root@hanfeng mysql]# ps aux |grep mysql root 2295 0.0 0.1 113252 1608 pts/0 S 22:41 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/hanfeng.pid mysql 2403 1.9 44.6 973512 451180 pts/0 Sl 22:41 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/hanfeng.err --pid-file=/data/mysql/hanfeng.pid root 2429 0.0 0.0 112656 992 pts/0 R+ 22:41 0:00 grep --color=auto mysql [root@hanfeng mysql]#
[root@hanfeng mysql]# chkconfig --add mysqld [root@hanfeng mysql]# chkconfig mysqld on [root@hanfeng mysql]#
[root@hanfeng mysql]# service mysqld stop Shutting down MySQL.. SUCCESS! [root@hanfeng mysql]# service mysqld start Starting MySQL. SUCCESS!
[root@hanfeng ~]# cd /usr/local/src/ [root@hanfeng src]#
[root@hanfeng src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
[root@hanfeng src]# tar zxf php-5.6.30.tar.gz [root@hanfeng src]# ls mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz php-5.6.30 php-5.6.30.tar.gz [root@hanfeng src]#
[root@hanfeng src]# useradd -s /sbin/nologin php-fpm [root@hanfeng src]#
[root@hanfeng ~]# cd /usr/local/src/php-5.6.30 [root@hanfeng php-5.6.30]#
[root@hanfeng php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
checking for cc... no checking for gcc... no configure: error: in `/usr/local/src/php-5.6.30': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
yum install -y gcc
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@hanfeng php-5.6.30]# yum install -y libxml2-devel
configure: error: Cannot find OpenSSL's <evp.h>
yum install -y openssl-devel
configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
yum install -y libcurl-devel 或 yum install -y curl curl-devel
configure: error: jpeglib.h not found.
yum install -y libjpeg-devel
configure: error: png.h not found.
yum install -y libpng yum install -y libpng-devel
configure: error: freetype-config not found.
yum install -y freetype-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install -y epel-release yum install -y libmcrypt-devel
[root@hanfeng php-5.6.30]# echo $? 0 [root@hanfeng php-5.6.30]#
[root@hanfeng php-5.6.30]# make && make instal
[root@hanfeng php-5.6.30]# echo $? 0 [root@hanfeng php-5.6.30]#
[root@hanfeng php-5.6.30]# ls /usr/local/php-fpm/ bin etc include lib php sbin var [root@hanfeng php-5.6.30]# ls /usr/local/php-fpm/sbin/ //在sbin目录下有一个php-fpm文件,就是用来启动php-fpm的 php-fpm [root@hanfeng php-5.6.30]# ls /usr/local/php-fpm/var/ //在var目录下有 log 和 run 文件,log文件存放日志的,run存放pid的,日志和pid路径都是能够指定的 log run [root@hanfeng php-5.6.30]#
/usr/local/php-fpm/sbin/php-fpm -m 查看模块 /usr/local/php-fpm/sbin/php-fpm -i /usr/local/php-fpm/sbin/php-fpm -t 测试配置文件文件语法
[root@hanfeng php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t [03-Jan-2018 00:10:44] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2) [03-Jan-2018 00:10:44] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf' [03-Jan-2018 00:10:44] ERROR: FPM initialization failed [root@hanfeng php-5.6.30]#
[root@hanfeng php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini [root@hanfeng php-5.6.30]#
[root@hanfeng php-5.6.30]# cd /usr/local/php-fpm/etc/ [root@hanfeng etc]# ls pear.conf php-fpm.conf.default php.ini [root@hanfeng etc]#
[root@hanfeng etc]# vim php-fpm.conf 去https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf拷贝样例 拷贝到文件中 [global] //全局配置 pid = /usr/local/php-fpm/var/run/php-fpm.pid //定义PID error_log = /usr/local/php-fpm/var/log/php-fpm.log //错误日志 [www] //模块名字,启动服务的时候就能看到 listen = /tmp/php-fcgi.sock //监听的地址 listen.mode = 666 //当监听的是sock的时候,这个语句才会生效,这个语句用来定义sock文件权限的 user = php-fpm //用户,定义是哪一个用户启动的 group = php-fpm // 组,定义是哪一个组启动的 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 而后保存退出
linsten 能够监听sock、tcp 能够写成 linsten = 127.0.0.1:9000(默认端口就是9000,可自定义),通常监听的到是“127.0.0.1 ”IP,由于php-fpm这个服务是针对内部使用的、在本机上用的,也就是说Nginx和php一般是在一台机器上,二者之间通讯直接使用内部网络就能够了;在这块选择的linsten配置不一样,到以后的配置Nginx配置,也就是告诉Nginx到哪里找php的配置语句也是不一样css
[root@hanfeng etc]# cd /usr/local/src/php-5.6.30/ [root@hanfeng php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@hanfeng php-5.6.30]#
[root@hanfeng php-5.6.30]# chmod 755 /etc/init.d/php-fpm [root@hanfeng php-5.6.30]# chkconfig --add php-fpm [root@hanfeng php-5.6.30]# chkconfig php-fpm on [root@hanfeng php-5.6.30]# service php-fpm start Starting php-fpm done [root@hanfeng php-5.6.30]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 若是您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。 mysqld 0:关 1:关 2:开 3:开 4:开 5:开 6:关 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 php-fpm 0:关 1:关 2:开 3:开 4:开 5:开 6:关 [root@hf-01 php-5.6.30]#
[root@hanfeng php-5.6.30]# ps aux |grep php-fpm root 2386 0.0 0.4 124184 4936 ? Ss 17:04 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 2387 0.0 0.4 124184 4700 ? S 17:04 0:00 php-fpm: pool www php-fpm 2388 0.0 0.4 124184 4700 ? S 17:04 0:00 php-fpm: pool www php-fpm 2389 0.0 0.4 124184 4700 ? S 17:04 0:00 php-fpm: pool www php-fpm 2390 0.0 0.4 124184 4700 ? S 17:04 0:00 php-fpm: pool www php-fpm 2391 0.0 0.4 124184 4704 ? S 17:04 0:00 php-fpm: pool www php-fpm 2392 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2393 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2394 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2395 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2396 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2397 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2398 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2399 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2400 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2401 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2402 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2403 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2404 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2405 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www php-fpm 2406 0.0 0.4 124184 4708 ? S 17:04 0:00 php-fpm: pool www root 2408 0.0 0.0 112676 988 pts/0 R+ 17:04 0:00 grep --color=auto php-fpm [root@hanfeng php-5.6.30]#
apache和nginx工做原理比较mysql
概念了解git