MySQL概述
php概述
LNMP | LAMP |
---|---|
作用 是用来在Linux系统下Nginx+MySQL+PHP这种网站中搭建服务器架构。 |
作用 是Linux(操作系统)、ApacheHTTP 服务器。一般用来建立web应用平台。 |
定义 指的是一个基于CentOS/Debian编写的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一键安装包。 |
定义 是Web应用软件组合。 |
用户评价 lnmp搭建的Linux系统,是目前最流行的免费操作系统。 |
用户评价 lAMP是最强大的网站解决方案。 |
软件组 Nginx、MySQL、PHP、PHPMyAdmin、Apache(可选)、Zend Optimizer(可选)、eAccelerator(可选)、ionCube(可选)、PureFTPd(可选)、VsFTPd(可选)。 |
软件组 Linux、Apache、MySQL、PHP,Perl 或 Python。 |
总结 使用的是Nginx,Nginx是一款高性能额Http和反向代理服务器,也是一个AMAP/POP3/SMTP服务器,Nginx是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日,2011年6月1日,nginx 1.0.4发布 |
总结 使用的是Apache,Apache是世界是用排名第一的Web服务器软件,其几乎可以在所有广泛使用的计算机平台上运营,由于其跨平台和安全性被广泛使用,是最流行的Web服务端软件之一。 |
[root@localhost ~]# cd /opt/
[root@localhost opt]# systemctl stop firewalld.service
[root@localhost opt]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost opt]# mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost opt]# yum -y install pcre-devel.x86_64 zlib-devel.x86_64 gcc gcc-c++ make
安装过程略
[root@localhost opt]# useradd -M -s /sbin/nologin nginx
[root@localhost opt]# tar zxvf nginx-1.12.2.tar.gz -C /opt/
解压过程略
[root@localhost opt]# cd nginx-1.12.2/
[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 -j12 && make install
编译过程略
[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.12.2]# vim /lib/systemd/system/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=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost nginx-1.12.2]# chmod 754 /lib/systemd/system/nginx.service
[root@localhost nginx-1.12.2]# systemctl start nginx.service
[root@localhost nginx-1.12.2]# systemctl enable nginx.service
[root@localhost opt]# rpm -q cifs-utils
cifs-utils-6.2-10.el7.x86_64
[root@localhost opt]# smbclient -L 192.168.1.22
Enter SAMBA\root's password:
OS=[Windows 10 Pro for Workstations 18363] Server=[Windows 10 Pro for Workstations 6.3]
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk 远程管理
C$ Disk 默认共享
D$ Disk 默认共享
E$ Disk 默认共享
IPC$ IPC 远程 IPC
linux软件包 Disk
Users Disk
Connection to 192.168.1.22 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
NetBIOS over TCP disabled -- no workgroup available
[root@localhost opt]# mkdir qz
[root@localhost opt]# mount.cifs //192.168.1.22/linux软件包 /qz
Password for root@//192.168.1.22/linux软件包: ****
[root@localhost opt]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda5 31G 3.7G 27G 12% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 2.7M 2.0G 1% /dev/shm
tmpfs 2.0G 9.1M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda2 15G 33M 15G 1% /home
/dev/sda1 497M 151M 346M 31% /boot
tmpfs 394M 24K 394M 1% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
//192.168.1.22/linux软件包 932G 242G 691G 26% /qz
[root@localhost opt]# cd /qz/
[root@localhost qz]# ls
apr-1.6.2.tar.gz epel-release-latest-7.noarch.rpm mysql-boost-5.7.20.tar.gz
apr-util-1.6.0.tar.gz extundelete-0.2.4.tar.bz2 mysql.rar
awstats-7.6.tar.gz httpd-2.4.29.tar.bz2 nginx-1.12.0.tar.gz
boost_1_59_0.tar.gz john-1.8.0.tar.gz nginx-1.12.2.tar.gz
Discuz_X3.4_SC_UTF8.zip mysql-5.7.17.tar.gz php-7.1.10.tar.bz2
[root@localhost qz]# tar zxvf mysql-boost-5.7.20.tar.gz -C /opt/
解压过程略
[root@localhost nginx-1.12.2]# cd /opt/
[root@localhost opt]# rz -E
rz waiting to receive.
[root@localhost opt]# yum -y install \
> ncurses \
> ncurses-devel \
> bison \
> cmake
安装过程略
[root@localhost opt]# useradd -M -s /sbin/nologin mysql
[root@localhost opt]# cd /opt/mysql-5.7.20/
[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 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -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 \
> -DWITH_SYSTEMD=1
过程略
[root@localhost mysql-5.7.20]# make -j12 && make install
编译安装过程略
[root@localhost mysql-5.7.20]# 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
auto-rehash
[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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
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 mysql-5.7.20]# chown -R mysql:mysql /usr/local/mysql/
[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf
[root@localhost mysql-5.7.20]# echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
[root@localhost mysql-5.7.20]# source /etc/profile
[root@localhost mysql-5.7.20]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysqld \
> --initialize-insecure \
> --user=mysql \
> --basedir=/usr/local/mysql \
> --datadir=/usr/local/mysql/data
初始化过程略
[root@localhost bin]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl start mysqld.service
[root@localhost bin]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.
[root@localhost bin]# mysqladmin -uroot -p password "5514"
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost bin]# mysql -uroot -p5514
mysql: [Warning] Using a password on the command line interface can be insecure.
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> grant all on *.* to 'root'@'%' identified by '5514';
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
[root@localhost opt]# yum -y install \
> gd \
> libjpeg libjpeg-devel \
> libpng libpng-devel \
> freetype freetype-devel \
> libxml2 libxml2-devel \
> zlib zlib-devel \
> curl curl-devel \
> openssl openssl-devel
安装过程略
[root@localhost opt]# cd /qz/
[root@localhost qz]# cp php-7.1.10.tar.bz2 /opt/
[root@localhost qz]# cd /opt/
[root@localhost opt]# ls
mysql-5.7.20 nginx-1.12.2 nginx-1.12.2.tar.gz php-7.1.10.tar.bz2 rh
[root@localhost opt]# tar jxvf php-7.1.10.tar.bz2
解压过程略
[root@localhost opt]# cd php-7.1.10/
[root@localhost php-7.1.10]# ./configure \
> --prefix=/usr/local/php \
> --with-mysql-sock=/usr/local/mysql/mysql.sock \
> --with-mysqli \
> --with-zlib \
> --with-curl \
> --with-gd \
> --with-jpeg-dir \
> --with-png-dir \
> --with-freetype-dir \
> --with-openssl \
> --enable-fpm \
> --enable-mbstring \
> --enable-xml \
> --enable-session \
> --enable-ftp \
> --enable-pdo \
> --enable-tokenizer \
> --enable-zip
过程略
[root@localhost php-7.1.10]# make -j10 && make install
编译过程略
[root@localhost php-7.1.10]# ln -s /usr/local/php/bin/ * /usr/local/bin/
[root@localhost php-7.1.10]# ln -s /usr/local/php/sbin/ * /usr/local/sbin/
php有三个配置文件
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
[root@localhost php-7.1.10]# cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
[root@localhost php-7.1.10]# vim /usr/local/php/lib/php.ini
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
【1170行进行修改】
939 date.timezone = Asia/Shanghai
【939行取消注释并修改,这里是使用“;”进行注释】
[root@localhost php-7.1.10]# php -m
[root@localhost etc]# cd /usr/local/php/etc/
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vim php-fpm.conf
17 pid = run/php-fpm.pid
【将第17行的注释“;”去掉】
[root@localhost etc]# cd /usr/local/php/etc/php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default www.conf
[root@localhost php-fpm.d]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
[root@localhost php-fpm.d]# netstat -tapn | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 74091/php-fpm: mast
【PHP-FPM是一个PHPFastCGI管理器,由于Nginx服务器不能处理动态页面,所有需要由Nginx把动态请求交给php-fpm进程进行解析】
[root@localhost php-fpm.d]# vim /usr/local/nginx/conf/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 }
【将第65-71行取消注释,并将69行的/scripts修改成nginx的工作目录】
[root@localhost php-fpm.d]# systemctl restart nginx.service
[root@localhost php-fpm.d]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
[root@localhost php-fpm.d]# 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> CREATE DATABASE bbs;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY '5514';
Query OK, 0 rows affected, 1 warning (0.01 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.00 sec)
[root@localhost php-fpm.d]# vim /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.131.14','bbsuser','5514');
if($link) echo "成功!
";
else echo "失败!";
?>
[root@localhost php-fpm.d]# cd /qz/
[root@localhost qz]# cp Discuz_X3.4_SC_UTF8.zip /opt/
[root@localhost qz]# cd /opt/
[root@localhost opt]# unzip Discuz_X3.4_SC_UTF8.zip -d /opt/dis
[root@localhost opt]# cd /opt/dis/dir_SC_UTF8/
[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]# 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/