日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

centos php7.0 mysql_CentOS 7.3 下 安装LNMP(Nginx1.10+MySQL5.7+PHP7.0.20)

發布時間:2024/4/14 数据库 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos php7.0 mysql_CentOS 7.3 下 安装LNMP(Nginx1.10+MySQL5.7+PHP7.0.20) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:最近總是要安裝服務器環境,記錄這次CentOS 7.3下安裝LNMP(Nginx1.10+MySQL5.7+PHP7.0.20)環境的過程,以備日后使用。

一、準備工作

1. 更新源

# yum update

2. 安裝vsftpd

3. 關閉selinux

//修改配置文件,重啟服務后永久生效。

# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

// 立即生效。

# setenforce 0

4. 安裝依賴

# yum install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

二、安裝nginx(兩種,編譯和源)

第一種 源安裝(推薦,之后配置以這種安裝為準):

// 安裝nginx源

# yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

// 安裝nginx

# yum install nginx

// 啟動nginx

# service nginx start

第二種 編譯安裝(編譯安裝自由度高,但配置麻煩):

// 下載Nginx (如需最新版,也可直接去官網下載)

# wget http://nginx.org/download/nginx-1.11.12.tar.gz

// 解壓

# tar -zxvf nginx-1.11.12.tar.gz

# cd nginx-1.11.12

// 創建用戶

# groupadd -r nginx

# useradd -r -g nginx nginx

// 編譯安裝

# ./configure \

--prefix=/usr/local/nginx \

--sbin-path=/usr/sbin/nginx \

--conf-path=/etc/nginx/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--pid-path=/var/run/nginx.pid \

--lock-path=/var/run/nginx.lock \

--http-client-body-temp-path=/var/tmp/nginx/client \

--http-proxy-temp-path=/var/tmp/nginx/proxy \

--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/nginx/scgi \

--user=nginx \

--group=nginx \

--with-pcre \

--with-http_v2_module \

--with-http_ssl_module \

--with-http_realip_module \

--with-http_addition_module \

--with-http_sub_module \

--with-http_dav_module \

--with-http_flv_module \

--with-http_mp4_module \

--with-http_gunzip_module \

--with-http_gzip_static_module \

--with-http_random_index_module \

--with-http_secure_link_module \

--with-http_stub_status_module \

--with-http_auth_request_module \

--with-mail \

--with-mail_ssl_module \

--with-file-aio \

--with-ipv6 \

--with-http_v2_module \

--with-threads \

--with-stream \

--with-stream_ssl_module

# make && make install

# mkdir -pv /var/tmp/nginx/client

// 添加SysV啟動腳本。

# 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/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

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

killall -9 nginx

}

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

>> 寫入內容結束

// 賦予腳本執行權限。

# chmod +x /etc/init.d/nginx

// 添加至服務管理列表,設置開機自啟。

# chkconfig --add nginx

# chkconfig nginx on

// 啟動nginx

# service nginx start

nginx安裝完成,等php安裝好后,可以配置nginx文件

三、安裝mysql5.7

// 在MySQL官網中下載YUM源rpm安裝包

# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

// 安裝mysql源

# yum localinstall mysql57-community-release-el7-8.noarch.rpm

// 檢查mysql源是否安裝成功

# yum repolist enabled | grep "mysql.*-community.*"

> mysql-connectors-community/x86_64 MySQL Connectors Community 3

> mysql-tools-community/x86_64 MySQL Tools Community 4

> mysql57-community/x86_64 MySQL 5.7 Community Server 18

// 安裝mysql

# yum install mysql-community-server

# yum install mysql-community-devel

// 啟動mysql

# service mysqld start

// 查看mysql啟動狀態

# service mysqld status

// 設置開機啟動

# systemctl enable mysqld

# systemctl daemon-reload

// 獲取mysql默認生成的密碼

# grep 'temporary password' /var/log/mysqld.log

> 2017-07-04T06:06:06.824762Z 1 [Note]Atemporary password is generated for root@localhost: h8wob/ou+wpC

// :(冒號)后的就是自動生成的密碼 h8wob/ou+wpC ,換成自己的密碼

# mysql -uroot -p

> Enter password:h8wob/ou+wpC

> mysql>

// 更換密碼

> mysql>ALTERUSER 'root'@'localhost'IDENTIFIEDBY '123IsYourNewPassword!';

注意:這里的新密碼必須包含數字、小寫或大寫字母、特殊字符串。這個密碼的復雜程度,和validate_password_policy的值有關。

PolicyTests Performed

0 or LOW

Length

1 or MEDIUM

Length; numeric, lowercase/uppercase, and special characters

2 or STRONG

Length; numeric, lowercase/uppercase, and special characters; dictionary file

默認是1,即MEDIUM。如果想要降低密碼復雜度,可以進入mysql后設置。

> mysql> set global validate_password_policy=0;

// 退出后再確認一次

> mysql> quit;

# mysql -uroot -p123IsYourNewPassword!

> mysql>

至此,mysql安裝完畢

四、安裝php7

// 官網下載7.0.20版本后,用ftp將源碼包傳到服務器中,保存在/root下

# tar -zxvf php-7.0.20.tar.gz

# cd php-7.0.20

// 安裝依賴包

# yum 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

// 編譯配置。如果按照我的步驟一步步來,應該一步到位,直接看見 Thank you for using 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-mcrypt \--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-native-ttf \--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

// 添加 PHP 命令到環境變量

# vim /etc/profile

// 立即生效

# source /etc/profile

// 查看PHP版本

# php -v

> PHP 7.0.20 (cli) (built: Jul 4 2017 14:39:02) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

// 配置php-fpm

# cp php.ini-production /etc/php.ini

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

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

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

# chmod +x /etc/init.d/php-fpm

// 添加php-fpm至服務列表并設置開機自啟。

# chkconfig --add php-fpm

# chkconfig --list php-fpm

# chkconfig php-fpm on

// 啟動php-fpm

# /etc/init.d/php-fpm start

php安裝完成

五、nginx站點配置

// 創建配置文件

# vim /etc/nginx/conf.d/yourWebAddress.com.conf

>> 寫入內容

server {

listen 80;

server_name www.yourWebAddress.com;

#charset koi8-r;

#access_log /var/log/nginx/log/host.access.log main;

location / {

root /var/www/html;

index index.php index.html index.htm;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /var/www/html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

root /var/www/html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

>> 寫入內容結束

最近總是要安裝服務器環境,記錄這次CentOS 7.3下安裝LNMP(Nginx1.10+MySQL5.7+PHP7.0.20)環境的過程,以備日后使用。

Ubuntu 14.04 LTS 安裝 LNMP Nginx\PHP5 (PHP-FPM)\MySQL? http://www.linuxidc.com/Linux/2014-05/102351.htm

總結

以上是生活随笔為你收集整理的centos php7.0 mysql_CentOS 7.3 下 安装LNMP(Nginx1.10+MySQL5.7+PHP7.0.20)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。