Centos7.6安装php7.2+mysql5.7+nginx1.14

centos7.6安装php7.2+mysql5.7+nginx1.14

  • 因为公司要求,需要安装一套LNMP的环境,其中php+nginx安装在一台机器上,废话不多说,写上安装步骤。
  • 全新干净的环境安装。

因为公司要求,需要安装一套LNMP的环境,其中php+nginx安装在一台机器上,废话不多说,写上安装步骤。

全新干净的环境安装。

关闭防火墙和selinux。

##下载nginx
wget -c https://nginx.org/download/nginx-1.14.2.tar.gz
##安装依赖
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ make cmake
##创建nginx用户
useradd -M -s /sbin/nologin nginx
##创建nginx目录
mkdir /usr/local/nginx
##解压源码包并进入源码目录
tar xf nginx-1.14.2.tar.gz
cd nginx-1.14.2/
##编译安装
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
##安装完成
##配置nginx与php连接。下面为替换部分
vim /usr/local/nginx/conf/nginx.conf
45 index index.html index.htm;
65 #location ~ .php$ {
66 # root html;
67 # fastcgi_pass 127.0.0.1:9000;
68 # fastcgi_index index.php;
69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 # include fastcgi_params;
71 #}
##上面是源文件,下面是替换后的文件
45 index index.html index.htm index.php;
65 location ~ .php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
70 include fastcgi_params;
71 }
启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
(可选)加入开机启动
echo ‘/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf’ >> /etc/rc.local
加入systenctl -V启动脚本
vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 99 20
# description: Oooo this is my nginx startup script
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case “$1” in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
)
echo “Usage: $0 {start|stop|restart|reload}”
exit 1
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
##查看端口 ############如果没有netstat 命令,请安装此命令 安装命令是 yum -y install net-tools#########
netstat -tunlp | grep ‘:80’
tcp 0 0 0.0.0.0:80 0.0.0.0:
LISTEN 24085/nginx: master
##查看进程
#ps -ef | grep nginx
root 24085 1 0 04:50 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx 24086 24085 0 04:50 ? 00:00:00 nginx: worker process
root 24093 13858 0 04:52 pts/0 00:00:00 grep --color=auto nginx
##加入开机启动
echo ‘/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf’ >> /etc/rc.local
php安装
官网下载
wget -c http://cn2.php.net/get/php-7.2.15.tar.gz/from/this/mirror
解压
tar xf mirror
进入目录
cd php-7.2.15/
安装依赖
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
##创建php安装目录
mkdir /usr/local/php
##编译安装
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
make && make install
#环境变量
echo -e ‘PATH=$PATH:$HOME/bin:/usr/local/php/bin\nexport PATH’>> /etc/profile.d/php.sh
source /etc/profile.d/php.sh
##复制默认配置文件
####解压包里面####
ls /etc/php.ini || cp php.ini-production /etc/php.ini
ls /usr/local/php/etc/php-fpm.conf || cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ls /usr/local/php/etc/php-fpm.d/www.conf || cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
##复制启动文件至
ls /etc/init.d/php-fpm || cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
##添加执行权限
chmod +x /etc/init.d/php-fpm
##加入systenctl启动管理
chkconfig --add php-fpm
chkconfig php-fpm on
##启动
systemctl start php-fpm
##查看状态
ps -ef | grep php-fpm
root 19261 1 0 05:32 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nginx 19262 19261 0 05:32 ? 00:00:00 php-fpm: pool www
nginx 19263 19261 0 05:32 ? 00:00:00 php-fpm: pool www
root 19265 13858 0 05:32 pts/0 00:00:00 grep --color=auto php-fpm
##查看端口
netstat -tunlp | grep ‘:9000’
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 19261/php-fpm: mast
##mysql安装
##清理环境
rm -rf /etc/my*
rm -rf /var/lib/mysql
rm -rf /usr/local/mysql
##安装依赖
yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake
##官网下载mysql源码包
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-5.7.25-1.el7.src.rpm
##安装源码包
##rpm -ivh mysql-community-5.7.25-1.el7.src.rpm
##进入源码包
cd /root/rpmbuild/SOURCES
##解压源码
tar xf mysql-5.7.25.tar.gz
##由于自带的boost库不能用,重新官网下载boost库
wget -c http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
##解压至mysql解压包里面
tar -xzf boost_1_59_0.tar.gz -C mysql-5.7.25/
##创建mysql目录
mkdir /usr/local/mysql
##添加mysql用户
useradd -r mysql -M -s /sbin/nologin
##进入mysql源码目录,开始编译安装
cd mysql-5.7.25/
cmake . -DWITH_BOOST=boost_1_59_0/ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DINSTALL_MANDIR=/usr/share/man -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1
make && make install
##初始化
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
##初始密码
##################### 初始密码 XXXXXXXX #################
##手动编写配置文件
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
#生成启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
##启动mysql
systemctl start mysqld
##配置mysql环境变量
vim /etc/profile.d/mysql.sh
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
export PATH
##刷新一下
source /etc/profile.d/mysql.sh
##登录mysql
mysql -uroot -p
修改mysql密码并查看状态
mysql> set password=password(‘XXXXXXXX’);
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> status
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Connection id: 2
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ‘’
Using delimiter: ;
Server version: 5.7.25
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 4 min 20 sec
Threads: 1 Questions: 7 Slow queries: 0 Opens: 106 Flush tables: 1 Open tables: 99 Queries per second avg: 0.026
##安装完成

你可能感兴趣的:(笔记)