Enrich life today. Yesterday is history. Tomorrow is mystery.

人生如负重远行,不可急于求成

从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态


                   

前言:平时做网站一般都用模版系统,用多了一些细节原理就搞不清楚,也不容易排错。于是我花了些时间自己从一个纯净的系统来完全部署环境。本次使用西部数码centos6.4纯净版系统,配置nginx+php7.0+mysql5.6,并且搭建一个wordpress站点,配置伪静态和 ssl证书。

1、安装nginx
(1)安装依赖环境
# yum -y install zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-level
(2)进入http://nginx.org/en/download.html 下载 编译安装
# wget http://nginx.org/download/nginx-1.14.2.tar.gz && tar -zxvf nginx-1.14.2.tar.gz && chown root:root -R nginx-1.14.2 && cd nginx-1.14.2
# ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module
# make && make install
# /usr/local/nginx/sbin/nginx -v (查看到版本号说明安装好了)
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
(3)配置nginx
创建nginx运行的用户和组
# /usr/sbin/groupadd www
# /usr/sbin/useradd -g www www
建立一个网站的配置文件路径:
# mkdir /home/confile/nginx/vhost -p
编辑配置文件:
# vi /usr/local/nginx/conf/nginx.conf
填入以下内容替换:
user www www;
worker_processes 4;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include /home/confile/nginx/vhost/*.conf;
}
在网站配置文件路径编辑默认配置文件:
# vi /home/confile/nginx/vhost/default.conf
填入以下内容:
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /home/wwwroot/default/;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
保存
先建好目录/home/wwwroot/default/,放一个index.html进去验证访问
# chown www:www -R wwwroot/
注意权限修改
(4)启动nginx
/usr/local/nginx/sbin/nginx
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
访问可以了。
(6)添加nginx到系统服务中,设置自启动
# vi /etc/init.d/nginxd 写入如下内容
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by caffreyxin at 2007.10.15.
# it is v.0.0.1 version.
# if you find any errors on this scripts, please contact caffreyxin.
# and send mail to xinyflove at sina dot com.
#
# chkconfig: – 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it’s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog=”nginx”
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = “no” ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo “nginx already running….”
exit 1
fi
echo -n $”Starting $prog: “
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $”Stopping $prog: “
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $”Reloading $prog: “
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $”Usage: $prog {start|stop|restart|reload|status|help}”
exit 1
esac
exit $RETVAL
之后设置权限启动项
[root@ebs-63572 ~]# chmod 755 /etc/init.d/nginxd
[root@ebs-63572 ~]# chkconfig nginxd on
[root@ebs-63572 ~]# chkconfig –list 查看启动项
测试服务启动正常
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
配置文件路径:/usr/local/nginx/conf/nginx.conf
虚拟主机配置文件路径:/home/confile/nginx/vhost/*.conf
2、安装mysql5.6
2.1安装
#yum list installed | grep mysql
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
由于默认是5.1我们先删除
# yum -y remove mysql-libs
下载5.6的rpm包
这个rpm还不是mysql的安装文件,只是两个yum源文件,执行后,在/etc/yum.repos.d/ 这个目录下多出mysql-community-source.repo和mysql-community.repo
# rpm -ivh mysql-community-release-el6-5.noarch.rpm
用yum repolist mysql这个命令查看一下是否已经有mysql可安装文件
# yum repolist all | grep mysql
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
已经有5.6了,下面继续安装
# yum install mysql-community-server
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
确认下版本无误
# y
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
安装完毕后启动mysql服务,设置开机自启动
# service mysqld start
# chkconfig mysqld on
2.2 配置:
(1)第一次登陆无需输入密码,登录进入后设置即可
# mysql -u root
passwd:(直接回车)
> use mysql;
> update user set password=PASSWORD(‘asd123!’) where User=’root’;
> flush privileges;
> quit;
上面设置了mysql的root密码为asd123!
(2)修改一些参数
在home下建立mysql数据目录,设置权限,转移数据到数据盘:
# mkdir /home/mysql/data -p && cd /home && chown mysql:mysql -R mysql/
# mv /var/lib/mysql/* /home/mysql/data/
# vi /etc/my.cnf
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
错误日志路径也修改下
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
修改mysql启动修项中的路径配置
# vi /etc/init.d/mysqld
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
关闭selinux(可能影响修改路径后的mysql启动)
# setenforce 0
# vi /etc/selinux/config
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
如果启动mysql报错,ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) 可能有sock文件位置还未修改到,用下面命令执行
# ln -s /home/mysql/data/mysql.sock /var/lib/mysql/mysql.sock
以上mysql基本配置完成,再建立一个数据库,再建一个用户:
如需开启远程访问mysql数据库,登录mysql
> update mysql.user set host=’%’ where user=’root’;
> flush privileges;
这里用navicat远程先建立一个wordpress数据库,在创建一个用户wordpress 密码设置为asd123!,再添加权限
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
测试可以登录即可
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
3、安装php7.0
(1)安装编译
# wget http://php.net/distributions/php-7.0.33.tar.gz && tar -zxvf php-7.0.33.tar.gz && cd php-7.0.33
# ./configure –prefix=/usr/local/phps/php7 –with-config-file-path=/usr/local/phps/php7/etc –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-iconv=/usr/local/libiconv/ –enable-xml –enable-bcmath –enable-inline-optimization –enable-mbregex –enable-fpm –with-openssl –with-xmlrpc –enable-zip –enable-soap –without-pear –enable-session –with-libxml-dir –with-zlib –with-curl –enable-dba –enable-ftp –with-freetype-dir –with-gd –with-jpeg-dir –with-png-dir –with-zlib-dir –with-gettext –enable-mbstring –enable-pcntl –without-pdo-sqlite –enable-shmop –enable-sockets –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-opcache
如果有报错库不支持,则安装下对应库
# yum -y install gcc g++ libxml2 libxml2-devel openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
另外测试发现需要iconv和
wget http://mirror.hust.edu.cn/gnu/libiconv/libiconv-1.10.tar.gz
tar zxvf libiconv-1.10.tar.gz
cd libiconv-1.10
./configure –prefix=/usr/local/libiconv
make
make install
再进行一次配置然后编译
# ./configure ……
# make && make install
(2)配置php-fpm
创建个配置文件
# cp /usr/local/phps/php7/etc/php-fpm.conf.default /usr/local/phps/php7/etc/php-fpm.conf
# cp /usr/local/phps/php7/etc/php-fpm.d/www.conf.default /usr/local/phps/php7/etc/php-fpm.d/www.conf
# cp ~/php-7.0.33/php.ini-development /usr/local/phps/php7/etc/php.ini
配置修改
# vi /usr/local/phps/php7/etc/php-fpm.conf
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
# vi /usr/local/phps/php7/etc/php-fpm.d/www.conf
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
启动php-fpm
# /usr/local/phps/php7/sbin/php-fpm
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
添加php-fpm启动项
# vi /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/phps/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 +x /etc/init.d/php-fpm
添加启动项
# chkconfig –add php-fpm
4、FTP配置
安装vsftp
# yum install vsftp* -y
给之前www用户设置了密码为asd123! 并且设置用户目录为/home/wwwroot
vsftpd配置
# vi /etc/vsftpd/vsftpd.conf
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
锁定家目录,配置被动端口
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
5、建站配置
1、新建网站目录,在目录下放了个php探针
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
2、新建nginx配置文件
# vi /home/confile/nginx/vhost/guaiguaimv_com.conf
填入如下内容
server
{
listen 80;
server_name guaiguaimv.com;
index index.html index.htm index.php;
root /home/wwwroot/guaiguaimv/wwwroot;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 15d;
# access_log off;
}
access_log off;
}
保存重启nginxd服务
访问绑定的域名:
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
上传wordpress程序,解压,安装,用之前建立的数据库wordpress安装
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
3、伪静态配置
后台先设置固定连接:
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
nginx配置文件修改:
# vi /home/confile/nginx/vhost/guaiguaimv_com.conf
在server花括号中添加下面代码
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
重启nginx服务后可以打开伪静态了
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
4、配置域名ssl
https://www.west.cn/web/ssl/ 申请一个1元的ssl证书
下载nginx格式的
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
合并证书,cer在前crt在后,然后上传到建立的ssl目录
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
在虚拟主机nginx配置中节中继续填写如下代码:
server {
listen 443 ssl;
server_name guaiguaimv.com;
root /home/wwwroot/guaiguaimv/wwwroot;
ssl_certificate /home/ssl/www.guaiguaimv.com_ca.crt;
ssl_certificate_key /home/ssl/www.guaiguaimv.com.key;
index index.html index.php index.htm;
error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 405 /errpage/405.html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
添加后重启nginx服务,https已可以访问
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》
下面启用强制跳转ssl,在配置文件的80节中添加
rewrite ^(.*) https://guaiguaimv.com$1 permanent;
《从0开始,centos6.4 纯净版 nginx+php+mysql 建立wordpress站,配置ssl,伪静态》

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

hi~

你好,欢迎来到我的博客,欢迎留言。

快速搜索:







Generic selectors

Exact matches only


Search in title


Search in content



Search in posts


Search in pages

欢迎关注我:

微博
steam
QQ
500px
网易云音乐