nginx用来做反向代理的情况比较多
nginx的特长是处理静态请求效率非常强,擅长处理静态资源
apache更适合做动态处理
LNMP中,动态进程交给php中的fpm去处理
所以php需要额外安装fpm
[root@localhost ~]# yum install gcc gcc-c++ pcre* make cmake zlib-devel -y
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.254.10/linuxs /abc
Password for root@//192.168.254.10/linuxs:
[root@localhost ~]# cd /abc/L
LAMP-C7/ LNMP-C7/
[root@localhost ~]# cd /abc/LNMP-C7/LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz php-7.1.20.tar.bz2
mysql-boost-5.7.20.tar.gz php-5.6.11.tar.bz2 php-7.1.20.tar.gz
ncurses-5.6.tar.gz php-7.1.10.tar.bz2 zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]#
[root@localhost LNMP-C7]# tar xzvf nginx-1.12.2.tar.gz -C /opt
[root@localhost LNMP-C7]# useradd -M -s /sbin/nologin nginx
[root@localhost LNMP-C7]# id nginx
uid=1001(nginx) gid=1001(nginx) groups=1001(nginx)
[root@localhost LNMP-C7]# ls /home
gsy
[root@localhost LNMP-C7]# cd /opt/nginx-1.12.2/
[root@localhost nginx-1.12.2]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
。。。。。。
[root@localhost nginx-1.12.2]# make && make install
。。。。。。
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
[root@localhost nginx-1.12.2]# 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
[root@localhost nginx-1.12.2]# cd /lib/systemd/system
[root@localhost system]# vim nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost system]# chmod 754 nginx.service
[root@localhost system]# systemctl start nginx.service
[root@localhost system]# netstat -natp | grep "nginx"
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 120555/nginx: maste
[root@localhost system]# systemctl stop firewalld.service
[root@localhost system]# setenforce 0
此时nginx安装完毕
开始安装MySQL
ncurses 客户字符终端处理工具
bison 分析MYSQL语法,函数库
cmake 用来编译
[root@localhost system]# yum install ncurses* bison cmake -y
[root@localhost system]# useradd -s /sbin/nologin mysql
[root@localhost system]# id mysql
uid=1002(mysql) gid=1002(mysql) groups=1002(mysql)
[root@localhost system]# cd /abc/LNMP-C7/LNMP-C7
[root@localhost LNMP-C7]# tar xzvf mysql-boost-5.7.20.tar.gz -C /opt
[root@localhost LNMP-C7]# cd /opt
[root@localhost opt]# ls
mysql-5.7.20 nginx-1.12.2 rh
[root@localhost opt]# cd mysql-5.7.20/
[root@localhost mysql-5.7.20]# ls
boost configure.cmake INSTALL man README support-files
BUILD COPYING libbinlogevents mysql-test regex testclients
client dbug libbinlogstandalone mysys scripts unittest
cmake Docs libevent mysys_ssl sql VERSION
CMakeLists.txt Doxyfile-perfschema libmysql packaging sql-common vio
cmd-line-utils extra libmysqld plugin storage win
config.h.cmake include libservices rapid strings zlib
[root@localhost mysql-5.7.20]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //指定安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ //指定链接性文件
-DSYSCONFDIR=/etc \ //指定配置文件
-DSYSTEMD_PID_DIR=/usr/local/mysql \ //指定PID文件路径
-DDEFAULT_CHARSET=utf8 \ //指定字符集
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ //下面还有四个存储引擎,后面会讲,有的存储引擎是不支持事务处理过程和一些存储过程,有一些是支持事物存储过程的,根据需求,去针对选择
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \ //数据存放位置
-DWITH_BOOST=boost \ //底层要支持g++的运行库
-DWITH_SYSTEMD=1 //用来支持去做mysql后面为了去做主从复制的时候的序列号
等了一辈子,终于make好了,之后make install
[root@localhost mysql-5.7.20]# make
[100%] Built target my_safe_process
[root@localhost mysql-5.7.20]# make install
[root@localhost mysql-5.7.20]# cd ..
[root@localhost opt]# ls
mysql-5.7.20 nginx-1.12.2 rh
[root@localhost opt]# cd /usr/local
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql nginx sbin share src
[root@localhost local]# ls -l
总用量 0
drwxr-xr-x. 11 root root 197 12月 23 22:12 mysql
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost local]# ls -l
总用量 0
drwxr-xr-x. 11 mysql mysql 197 12月 23 22:12 mysql
[root@localhost local]# vim /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[root@localhost local]# chown mysql:mysql /etc/my.cnf
[root@localhost local]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost local]# echo 'export PATH' >> /etc/profile
[root@localhost local]# tail -2 /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@localhost local]# source /etc/profile
source使加入的数据生效,使mysql的相关命令识别
[root@localhost local]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin COPYING-test include man README share usr
COPYING docs lib mysql-test README-test support-files
[root@localhost mysql]#
[root@localhost mysql]# cd bin
[root@localhost bin]# ls
innochecksum mysql_config mysqlslap
lz4_decompress mysql_config_editor mysql_ssl_rsa_setup
myisamchk mysqld mysqltest
myisam_ftdump mysqld_pre_systemd mysqltest_embedded
myisamlog mysqldump mysql_tzinfo_to_sql
myisampack mysqldumpslow mysql_upgrade
my_print_defaults mysql_embedded mysqlxtest
mysql mysqlimport perror
mysqladmin mysql_install_db replace
mysqlbinlog mysql_plugin resolveip
mysqlcheck mysqlpump resolve_stack_dump
mysql_client_test mysql_secure_installation zlib_decompress
mysql_client_test_embedded mysqlshow
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# cd ..
[root@localhost mysql]# pwd
/usr/local/mysql
[root@localhost mysql]#
[root@localhost mysql]# ls
bin COPYING-test include man README share usr
COPYING docs lib mysql-test README-test support-files
[root@localhost mysql]# bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
[root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /lib/systemd/system/
[root@localhost system]# ls -l mysqld.service
-rw-r--r--. 1 root root 1639 Dec 23 17:33 mysqld.service
[root@localhost system]# systemctl start mysqld.service
[root@localhost system]# netstat -natp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 120555/nginx: maste
[root@localhost system]# netstat -natp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 7718/mysqld
[root@localhost mysql]# systemctl enable mysqld
[root@localhost mysql]# mysqladmin -uroot -p password
Enter password:
New password: 12341234
Confirm new password: 12341234
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, 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> quit
Bye
[root@localhost mysql]#
接下来安装PHP
fastcgi可以跨平台,可以作用在linux,也可作用在win
[root@localhost mysql]# yum -y install \
libjpeg \ //jpeg图片识别
libjpeg-devel \ //jpeg开发包
libpng libpng-devel \ //png图片识别还有开发包
freetype freetype-devel \ //freetype 识别字体
libxml2 \ //xml文件格式识别
libxml2-devel \
zlib zlib-devel \ //zlib压缩
curl curl-devel \ //curl 支持文件上传下载,网页端的下载
openssl openssl-devel //身份验证去连接网站
[root@localhost mysql]# cd /abc/LNMP-C7/LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip php-7.1.10.tar.bz2
mysql-boost-5.7.20.tar.gz php-7.1.20.tar.bz2
ncurses-5.6.tar.gz php-7.1.20.tar.gz
nginx-1.12.2.tar.gz zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]# tar jxvf php-7.1.10.tar.bz2 -C /opt
[root@localhost LNMP-C7]# cd /opt/php-7.1.10/
[root@localhost php-7.1.10]# ls
acinclude.m4 footer mkinstalldirs README.PARAMETER_PARSING_API snapshot
aclocal.m4 generated_lists netware README.REDIST.BINS stamp-h.in
appveyor genfiles NEWS README.RELEASE_PROCESS stub.c
build header pear README.SELF-CONTAINED-EXTENSIONS tests
buildconf INSTALL php7.spec.in README.STREAMS travis
buildconf.bat install-sh php.gif README.SUBMITTING_PATCH TSRM
CODING_STANDARDS LICENSE php.ini-development README.TESTING UPGRADING
config.guess ltmain.sh php.ini-production README.TESTING2 UPGRADING.INTERNALS
config.sub main README.EXT_SKEL README.UNIX-BUILD-SYSTEM vcsclean
configure makedist README.GIT-RULES README.WIN32-BUILD-SYSTEM win32
configure.in Makefile.frag README.input_filter run-tests.php Zend
CONTRIBUTING.md Makefile.gcov README.MAILINGLIST_RULES sapi
CREDITS Makefile.global README.md scripts
ext makerpm README.namespaces server-tests-config.php
EXTENSIONS missing README.NEW-OUTPUT-API server-tests.php
[root@localhost php-7.1.10]#./configure \
--prefix=/usr/local/php \ //指定安装目录
--with-mysql-sock=/usr/local/mysql/mysql.sock \ //指向mysql的sock文件,用以后台程序去连接数据库
--with-mysqli \ //客户终端工具,可以直接去访问mysql服务器,去找它进行定义存储过程,事务的处理一些功能
--with-zlib \
--with-curl \
--with-gd \ //gd 是一个图像化的处理
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \ //fpm 是指动态请求的模块
--enable-mbstring \ //mbstring 多节点字符串
--enable-xml \ //xml 启用xml格式支持
--enable-session \ //支持session会话
--enable-ftp \ //网页可以ftp的功能
--enable-pdo \ //pdo 类似一个通用的接口一样,下面的不同的数据库的数据,会统一接口接收
--enable-tokenizer \ //tokenizer 是一个函数库
--enable-zip //zip 压缩
make && make install
[root@localhost php-7.1.10]# make && make install
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
/opt/php-7.1.10/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
[root@localhost php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini
937 ; Defines the default timezone used by the date functions
938 ; http://php.net/date.timezone
'939 date.timezone = Asia/Shanghai
1167 ; Default socket name for local MySQL connects. If empty, uses the built-in
1168 ; MySQL defaults.
1169 ; http://php.net/mysqli.default-socket
'1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
保存退出,主配置文件改好了
/usr/local/php/bin/php -m 验证安装的模块
[root@localhost php-7.1.10]# /usr/local/php/bin/php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
[root@localhost php-7.1.10]#
[root@localhost php-7.1.10]# cd /usr/local/php
[root@localhost php]# ls
bin etc include lib php sbin var
[root@localhost php]# cd etc
[root@localhost etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vim php-fpm.conf
13 [global]
14 ; Pid file
15 ; Note: the default prefix is /usr/local/php/var
16 ; Default Value: none
' 17 pid = run/php-fpm.pid
18
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# ls
www.conf.default
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# ln -s /usr/local/php/bin/* /usr/local/bin
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
//开启运行,这条很重要
[root@localhost php-fpm.d]# netstat -natp | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 81299/php-fpm: mast
[root@localhost php-fpm.d]# cd /usr/local/nginx/conf/
[root@localhost conf]# ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
[root@localhost conf]# vim nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
70 include fastcgi_params;
71 }
[root@localhost conf]# systemctl stop nginx.service
[root@localhost conf]# systemctl start nginx.service
[root@localhost conf]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html index.html
[root@localhost html]# mv index.html index.php
[root@localhost html]# vim index.php
[root@localhost html]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, 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> CREATE DATABASE bbs;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> quit
Bye
[root@localhost html]# cd /abc/LNMP-C7/LNMP-C7/
[root@localhost LNMP-C7]# ls
Discuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gz php-7.1.20.tar.bz2
mysql-boost-5.7.20.tar.gz php-5.6.11.tar.bz2 php-7.1.20.tar.gz
ncurses-5.6.tar.gz php-7.1.10.tar.bz2 zend-loader-php5.6-linux-x86_64_update1.tar.gz
[root@localhost LNMP-C7]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt/
[root@localhost LNMP-C7]# cd /opt
[root@localhost opt]# ls
dir_SC_UTF8 mysql-5.7.20 nginx-1.12.2 php-7.1.10 rh 说明.htm
[root@localhost opt]# cd dir_SC_UTF8/
[root@localhost dir_SC_UTF8]# ls
readme upload utility
[root@localhost dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs
[root@localhost dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/
[root@localhost bbs]# ls -l
总用量 68
-rw-r--r--. 1 root root 2748 12月 23 23:21 admin.php
drwxr-xr-x. 10 root root 149 12月 23 23:21 api
-rw-r--r--. 1 root root 727 12月 23 23:21 api.php
drwxr-xr-x. 2 root root 23 12月 23 23:21 archiver
drwxr-xr-x. 2 root root 90 12月 23 23:21 config
-rw-r--r--. 1 root root 1017 12月 23 23:21 connect.php
-rw-r--r--. 1 root root 106 12月 23 23:21 crossdomain.xml
drwxr-xr-x. 12 root root 202 12月 23 23:21 data
-rw-r--r--. 1 root root 5558 12月 23 23:21 favicon.ico
-rw-r--r--. 1 root root 2245 12月 23 23:21 forum.php
-rw-r--r--. 1 root root 821 12月 23 23:21 group.php
-rw-r--r--. 1 root root 1280 12月 23 23:21 home.php
-rw-r--r--. 1 root root 5885 12月 23 23:21 index.php
drwxr-xr-x. 5 root root 64 12月 23 23:21 install
drwxr-xr-x. 2 root root 23 12月 23 23:21 m
-rw-r--r--. 1 root root 1025 12月 23 23:21 member.php
-rw-r--r--. 1 root root 2435 12月 23 23:21 misc.php
-rw-r--r--. 1 root root 1788 12月 23 23:21 plugin.php
-rw-r--r--. 1 root root 977 12月 23 23:21 portal.php
-rw-r--r--. 1 root root 582 12月 23 23:21 robots.txt
-rw-r--r--. 1 root root 1155 12月 23 23:21 search.php
drwxr-xr-x. 10 root root 168 12月 23 23:21 source
drwxr-xr-x. 7 root root 86 12月 23 23:21 static
drwxr-xr-x. 3 root root 38 12月 23 23:21 template
drwxr-xr-x. 7 root root 106 12月 23 23:21 uc_client
drwxr-xr-x. 14 root root 256 12月 23 23:21 uc_server
[root@localhost bbs]# chown -R root:nginx ./config/
[root@localhost bbs]# chown -R root:nginx ./data/
[root@localhost bbs]# chown -R root:nginx ./uc_client/
[root@localhost bbs]# chown -R root:nginx ./uc_server/
[root@localhost bbs]# chmod -R 777 ./config/
[root@localhost bbs]# chmod -R 777 ./data/
[root@localhost bbs]# chmod -R 777 ./uc_client/
[root@localhost bbs]# chmod -R 777 ./uc_server/
全新安装
数据库名填bbs