centos lnmp源码安装mysql_CentOS7源码编译安装部署LNMP(php7、mysql5.7)

编译安装LNMP:

系统:CentOS-7.5

软件:MySQL-5.7.2、PHP-7.1.5、Nginx-1.14.2

安装MySQL:

下载源码包:点击下载

卸载自身mariadb:

find / -name mariadb*

#/etc/ld.so.conf.d/mariadb-x86_64.conf

#/usr/share/doc/mariadb-libs-5.5.56

rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

find / -name mariadb*

安装依赖包:

yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl-Data-Dumper boost boost-doc boost-devel

创建源码目录:

mkdir /home/tools && cd /home/tools

解压源码包:

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.22.tar.gz

tar zxf mysql-boost-5.7.22.tar.gz && cd mysql-5.7.22/

创建目录:

mkdir /usr/local/mysql

mkdir /usr/local/mysql/mydata

mkdir /usr/local/mysql/conf

useradd -s /sbin/nologin -M mysql

chown -R mysql:mysql /usr/local/mysql*

预编译:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/mydata \

-DSYSCONFDIR=/usr/local/mysql/conf \

-DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 -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 \

-DWITH_SYSTEMD=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost

注意:---------------------------------------------------------------

-DWITH_SYSTEMD=1 ------>是否支持systemd方式管理MySQL

-DDOWNLOAD_BOOST=1 ------>自动下载boost支持

-DWITH_BOOST=./boost ------>本地boost目录

为了简化本地连接MySQL,提供一种封装形式的TCP/IP协议。

-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock

编译:

make && make install && echo $?

初始化:

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/usr/local/mysql/mydata --basedir=/usr/local/mysql

修改配置文件:vim /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql

datadir=/usr/local/mysql/mydata

socket=/usr/local/mysql/mysql.sock

log_error=/var/log/mysql.log

user=mysql

[client]

socket=/usr/local/mysql/mysql.sock

创建日志文件:

touch /var/log/mysql.log && chown -R mysql.mysql /var/log/mysql.log

更新启动脚本:

cd /usr/local/mysql/support-files && sed -i 's#mysqld_safe#mysqld#g' mysql.server

cp mysql.server /etc/rc.d/init.d/mysqld

配置systemd管理:vim /etc/systemd/system/mysqld.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE = 5000

systemd管理启动:

systemctl start/stop/restart/status mysqld

配置环境变量:

echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile

source /etc/profile

密码配置:

mysqladmin password 'redhat' ----->第一次改密码使用方法,密码为“redhat”

b42f53bb2294d57c3cdab2a53d11f582.png

安装PHP:

创建用户:

useradd -s /sbin/nologin -u 122 -M nginx

安装依赖包:

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt-devel libicu-devel

下载源码包:

cd /home/tools && wget http://cn2.php.net/distributions/php-7.1.5.tar.gz

或者 wget https://mirrors.yangxingzhen.com/php/php-7.1.5.tar.gz

tar zxf php-7.1.5.tar.gz && cd php-7.1.5/

预编译:

./configure --prefix=/usr/local/php-7.1.5 \

--with-config-file-path=/usr/local/php-7.1.5/etc \

--with-mysql-sock=/usr/local/mysql/mysql.sock \

--with-mysqli \

--enable-fpm \

--with-fpm-user=nobody \

--with-fpm-group=nobody \

--with-pdo-mysql=mysqlnd \

--with-iconv-dir \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir \

--enable-xml \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--enable-mbregex \

--enable-mbstring \

--enable-intl \

--with-mcrypt \

--enable-ftp \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-zip \

--enable-soap \

--with-gettext \

--enable-opcache \

--with-xsl

编译和安装:

make && make install && echo $?

优化处理配置:

ln -s /usr/local/php-7.1.5 /usr/local/php

cp php.ini-development /usr/local/php/lib/php.ini

vim /usr/local/php/lib/php.ini

#修改以下内容:

mysqli.default_socket = /usr/local/mysql/mysql.sock //将php与Mysql关联

date.timezone = Asia/Shanghai //设置时区

pdo_mysql.default_socket=/usr/local/mysql/mysql.sock //修改mysql.sock文件路径

验证安装的模块:

/usr/local/php/bin/php –m

配置fpm模块:

cd /usr/local/php/etc/ && cp php-fpm.conf.default php-fpm.conf

cd /usr/local/php/etc/php-fpm.d && cp www.conf.default www.conf

vim /usr/local/php/etc/php-fpm.conf //配置fpm模块

#修改以下内容:

pid = run/php-fpm.pid //分号去掉

配置systemd管理:

vim /usr/lib/systemd/system/php-fpm.service

[Unit]

Description=The PHP FastCGI Process Manager

After=syslog.target network.target

[Service]

Type=simple

PIDFile=/run/php-fpm.pid

ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf

ExecReload=/bin/kill -USR2 $MAINPID

ExecStop=/bin/kill -SIGINT $MAINPID

[Install]

WantedBy=multi-user.target

systemctl daemon-reload

启动fpm模块:

systemctl start php-fpm.service

systemctl enable php-fpm.service

190dedf5f5e1943c3615b102e4281cb2.png

安装Nginx:

安装依赖包:

yum -y install pcre* openssl-devel

创建目录:

mkdir /home/tools && cd /home/tools

解压源码包:

wget http://nginx.org/download/nginx-1.14.2.tar.gz

tar zxf nginx-1.14.2.tar.gz && cd nginx-1.14.2/

预编译:

./configure --prefix=/usr/local/nginx \

--with-http_ssl_module --with-http_stub_status_module \

--with-http_stub_status_module --with-pcre

编译:

make && make install && echo $?

检测是否安装成功:

/usr/local/nginx/sbin/nginx -t --------->输入命令查看nginx版本

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

备份并修改配置文件:

cd /usr/local/nginx/conf/ && cp nginx.conf nginx.conf.bak && vim nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for" ';

access_log logs/access.log main;

server {

listen 80;

server_name 111.231.136.144;

location / {

root html/www;

index index.php index.html index.htm;

}

location ~ .*\.(php|php5)?$ {

root html/www;

fastcgi_index index.php;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

}

}

加入systemd管理:

vim /etc/systemd/system/nginx.service

[Unit]

Description=nginx server daemon

Documentation=man:nginx(8)

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

systemctl daemon-reload

启动Nginx:

systemctl start nginx

systemctl enable nginx

2ca5b845d13db84717794807ef1de929.png

默认站点目录:

cd /usr/local/nginx/html/

测试文件添加:

测试PHP文件:

mkdir -p /usr/local/nginx/html/www && echo '<?php phpinfo(); ?>' > /usr/local/nginx/html/www/phpinfo.php

测试MySQL文件:

vim /usr/local/nginx/html/www/mysql.php

$link=mysqli_connect('localhost','root','redhat');

if($link) echo "

Database connection successful

";

else echo "Fail!!";

?>

表示php已经配置完毕!

57248c6ca9f91222fe75a6d33aa81d42.png

表示数据库连成功

a31bdf292b8c84ea66f52ffd1ffd8136.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值