一、安装前准备
1、个人喜欢liunx小插件 vim
root# yum install vim 提示是否同意安装 选择 y 回车 然后就在各种依赖文件。
2、安装php 选择编译安装,编译安装属于一个复杂的方式,但很灵活。
root# wget http://hk1.php.net/get/php-7.2.10.tar.gz/from/this/mirror //下载文件
下载完成,解压
root# tar -zxvf mirror
注意:安装nginx服务器时需要 --enobte-fpm配置选项来激活FPM支持。 apache服务器则不需要安装
root# yum install gcc gcc++ libxml2-devel
root# cd php-7.2.10
把php安装到/usr/local/php7的目录中
php-7.2.10# ./configure --prefix=/usr/local/php7 --enable-fpm
看见显示 thank you for using php 安装成功。
php-7.2.10# make //安装比较慢耐心等待
php-7.2.10# make install
php-7.2.10# cd..
root# vim test.php 输入<?php echo phpinfo(); ?>
root# /usr/local/php7/bin/php test.php
打印phpinfo内容就安装完成了。
================================接下来安装mysql数据库============
查看自己想要的mysql数据地址
https://dev.mysql.com/downloads/mysql/
//root# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.12.tar.gz
root# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.23.tar.gz
root# tar -zxvf mysql-8.0.12.tar.gz
// root# ynm install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel
root# yum install -y cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel
root# cd mysql-8.0.12
mysql-8.0.12# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/mydata/mysql/data \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled
mysql-8.0.12# make
mysql-8.0.12# make install
mysql-8.0.12# mysqld
安装结束
===========================CentOS7 通过YUM安装MySQL5.7========================================
yum安装数据库
1.进入到要存放安装包的位置
cd /home/lnmp
2.查看系统中是否已安装 MySQL 服务,以下提供两种方式:
rpm -qa | grep mysql
yum list installed | grep mysql
3.如果已安装则删除 MySQL 及其依赖的包:
yum -y remove mysql-libs.x86_64
4.下载 mysql57-community-release-el7-8.noarch.rpm 的 YUM 源:
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
5.安装 mysql57-community-release-el7-8.noarch.rpm:
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
安装完后,得到如下两个包:
mysql-community.repo
mysql-community-source.repo
6.安装 MySQL,出现提示的话,一路 Y 到底
yum install mysql-server
安装完毕后,运行mysql,然后在 /var/log/mysqld.log 文件中会自动生成一个随机的密码,我们需要先取得这个随机密码,以用于登录 MySQL 服务端:
service mysqld start
grep "password" /var/log/mysqld.log
将会返回如下内容,末尾字符串就是密码,把它复制下来:
A temporary password is generated for root@localhost: hilX0U!9i3_6
7.登录到 MySQL 服务端并更新用户 root 的密码:
注意:由于 MySQL5.7 采用了密码强度验证插件 validate_password,故此我们需要设置一个有一定强度的密码;
mysql -u root -p
hilX0U!9i3_6
然后更改密码
SET PASSWORD = PASSWORD('your new password');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;
设置用户 root 可以在任意 IP 下被访问:
grant all privileges on *.* to root@"%" identified by "new password";
设置用户 root 可以在本地被访问:
grant all privileges on *.* to root@"localhost" identified by "new password";
刷新权限使之生效:
flush privileges;
OK,输入 exit 后用新密码再次登录看看吧!
注意:如果用远程工具还是连接不上,试试用 iptables -F 命令来清除防火墙中链中的规则
8.MySQL控制命令:启动、停止、重启、查看状态
service mysqld start
service mysqld stop
service mysqld restart
service mysqld status
systemctl start mysqld
service mysqld stop
service mysqld restart
systemctl status mysqld
9.设置 MySQL 的字符集为 UTF-8:
打开 /etc 目录下的 my.cnf 文件(此文件是 MySQL 的主配置文件):
vim /etc/my.cnf
在 [mysqld] 前添加如下代码:
[client]
default-character-set=utf8
在 [mysqld] 后添加如下代码:
character_set_server=utf8
重启mysql后再登录,看看字符集,6个utf8就算OK
show variables like '%character%';
10.查看指定的数据库中指定数据表的字符集,如查看 mysql 数据库中 servers 表的字符集:
show table status from mysql like '%servers%';
查看指定数据库中指定表的全部列的字符集,如查看 mysql 数据库中 servers 表的全部的列的字符集:
show full columns from servers;
11. 忘记密码时,可用如下方法重置:
service mysqld stop
mysqld_safe --user=root --skip-grant-tables --skip-networking &
mysql -u root
进入MySQL后
use mysql;
update user set password=password("new_password") where user="root";
flush privileges;
12.一些文件的存放目录
配置文件
vim /etc/my.cnf
存放数据库文件的目录
cd /var/lib/mysql
日志记录文件
vim /var/log/ mysqld.log
服务启动脚本
/usr/lib/systemd/system/mysqld.service
socket文件
/var/run/mysqld/mysqld.pid
13.MySQL 采用的 TCP/IP 协议传输数据,默认端口号为 3306,我们可以通过如下命令查看:
netstat -anp
==========================安装nginx===========
root# wget http://nginx.org/download/nginx-1.14.0.tar.gz 下载文件
root# tar -zxvf nginx-1.14.0.tar.gz 解压下载文件
root# yum install -y gcc gcc-c ++
.安装PCRE库
root# cd / usr / local /
root# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
root# tar -zxvf pcre-8.33.tar.gz
root# cd pcre -8.33
root# ./configure
root# make && make install
安装SSL库
root# cd / usr / local /
root# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
root# tar -zxvf openssl-1.0.1j.tar.gz
root# cd openssl-1.0.1j
root# ./config
root# make && make install
.安装的zlib的库存
root# cd / usr / local /
root# wget http://zlib.net/zlib-1.2.11.tar.gz
root# tar -zxvf zlib-1.2.11.tar.gz
root# ./configure
root# make && make install
安装nginx的的
root# cd / usr / local /
root# wget http://nginx.org/download/nginx-1.14.0.tar.gz
root# tar -zxvf nginx-1.14.0.tar.gz
root# cd nginx-1.14.0
root# ./ configure --user = nobody --group = nobody --prefix = / usr / local / nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --with -pcre = /usr/local/pcre-8.33 --with-zlib = /usr/local/zlib-1.2.11 --with-openssl = /usr/local/openssl-1.0.1j
(注: - with- http_ssl_module:这个不加的话后面在nginx.conf配置ssl:on after,启动会报nginx:
[emerg]未知指令“ssl”在/opt/nginx/conf/nginx.conf异常)
root# make && make install
启动会报nginx:
root# /usr/local/nginx/sbin/nginx
重启:
$/usr/local/nginx/sbin/nginx -s reload
停止:
$ /usr/local/nginx/sbin/nginx -s stop
链接php和nginx
启动php-fpm
[root@ sbin]#cd /usr/local/php7/sbin
[root@ sbin]# ./php-fpm
在nginx.conf的http断中加上如下内容:
####################################start##############################
server {
listen 80;
server_name zabbixserver.com;
access_log /data/logs/nginx/zabbixserver.com.access.log main;
index index.php index.html index.html;
root /data/site/zabbixserver.com;
location /
{
try_files $uri $uri/ /index.php?$args;
}
#########开始复制###########
location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
########复制结束############
}
################################end################################
在/usr/local/nginx/html下面创建个test.php输入<?php echo '终于安装成功了!';?>
访问地址ip x.x.x.x/test.php
配置nginx自动启动服务
首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:
vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
这个脚本来自nginx官方,脚本地址:http://wiki.nginx.org/RedHatNginxInitScript ,不过要注意,如果你是自定义编译安装的nginx,需要根据您的安装路径修改下面这两项配置:
nginx=”/usr/sbin/nginx” 修改成nginx执行程序的路径。
NGINX_CONF_FILE=”/etc/nginx/nginx.conf” 修改成配置文件的路径。
保存脚本文件后设置文件的执行权限:
chmod a+x /etc/init.d/nginx
chkconfig --add /etc/init.d/nginx
chkconfig nginx on
##############################php-fpm自启动###############################
创建文件
vim /etc/init.d/php-fpm
把下面赋值进去
#!/bin/sh
# chkconfig: 2345 15 95
# description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
# with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php7/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
chmod a+x /etc/init.d/php-fpm
chkconfig --add /etc/init.d/php-fpm
chkconfig php-fpmon
完成