一. 安裝nginx。
1.1查看系統環境
[root@localhosttools]# cat /etc/redhat-release
CentOSrelease 6.9 (Final)
[root@localhosttools]# uname -a
Linuxlocalhost 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64x86_64 x86_64 GNU/Linux
1.2創建文件存放目錄
[root@localhost~]# mkdir /server/tools –p
1.3下載ngin-1.10.3安裝包
[root@localhosttools]# wget -q http://nginx.org/download/nginx-1.10.3.tar.gz
[root@localhosttools]# ls -l
total 892
-rw-r--r-- 1root root 911509 Jan 31 2017nginx-1.10.3.tar.gz
1.4 安裝依賴包
yum install -y pcre-devel openssl-devel
1.5解壓Nginx
[root@localhosttools]# tar xf nginx-1.10.3.tar.gz
[root@localhosttools]# cd nginx-1.10.3
1.6設置nginx管理用戶www.
[[email protected]]# useradd www -s /sbin/nologin –M
1.7編譯安裝Nginx.
./configure --prefix=/application/nginx-1.10.3--user=www --group=www --with-http_stub_status_module --with-http_ssl_module
make&& make install
1.8創建Nginx軟鏈接
[[email protected]]# ln -s /application/nginx-1.10.3/ /application/nginx
[[email protected]]# ln -s /application/nginx/sbin/nginx /usr/sbin/ #可以在任意目錄執行Nginx啓動命令
1.9啓動Nginx
[[email protected]]# nginx
[[email protected]]# ps -ef|grep nginx
root 3722 1 0 08:24 ? 00:00:00 nginx: master process nginx
www 3723 3722 0 08:24 ? 00:00:00 nginx: worker process
root 3728 1247 0 08:25 pts/0 00:00:00 grep nginx
1.10 查看啓動情況
在瀏覽器輸入服務器的ip地址,返回下面界面代表Nginx安裝成功。
二.mysql安裝
2.1在/server/tools/上傳mysql安裝包
[root@localhosttools]# ls
libiconv-1.14.tar.gz nginx-1.10.3 php-5.5.32.tar.gz
mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz nginx-1.10.3.tar.gz wordpress-4.7.3-zh_CN.tar.gz
2.2解壓安裝包
[root@localhosttools]# tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz
2.3添加mysql程序運行時的管理用戶
[root@localhosttools]# useradd mysql -s /sbin/nologin –M
2.4將mysql解壓後的程序包搬家到程序目錄下,並進行重命名
[root@localhosttools]# mkdir -p /application/
[root@localhosttools]# mv /server/tools/mysql-5.6.34-*-x86_64 /application/mysql-5.6.34
2.5 爲mysql服務程序創建軟鏈接
[root@localhosttools]# ln -s /application/mysql-5.6.34//application/mysql
2.6 讓mysql用戶管理 /application/mysql/
[root@localhosttools]# chown -R mysql.mysql /application/mysql/data
2.7初始化數據庫
[root@localhosttools]# /application/mysql/scripts/mysql_install_db--basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
注意:此過程中出現兩個OK爲安裝成功
2.8複製啓動腳本授權
[root@localhosttools]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhosttools]# chmod +x /etc/init.d/mysqld
2.9修改啓動腳本和 mysql命令中的路徑
[root@localhosttools]# sed -i's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe/etc/init.d/mysqld
2.10複製默認的配置文件
[root@localhosttools]# \cp/application/mysql/support-files/my-default.cnf /etc/my.cnf
2.11啓動mysql服務
[root@localhosttools]# /etc/init.d/mysqld start
StartingMySQL..... SUCCESS!
[root@localhosttools]# ps -ef|grep mysql
root 3818 1 0 08:43 pts/0 00:00:00 /bin/sh/application/mysql/bin/mysqld_safe --datadir=/application/mysql/data--pid-file=/application/mysql/data/localhost.pid
mysql 3934 3818 4 08:43 pts/0 00:00:01 /application/mysql/bin/mysqld--basedir=/application/mysql --datadir=/application/mysql/data--plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/application/mysql/data/localhost.err--pid-file=/application/mysql/data/localhost.pid
2.12創建登錄mysql的軟鏈接
[root@localhosttools]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@localhosttools]# source /etc/profile
[root@localhosttools]# which mysql
/application/mysql/bin/mysql
2.13登錄mysql設置mysql密碼
[root@localhosttools]# mysql #登錄mysql
Welcome tothe MySQL monitor. Commands end with ;or \g.
Your MySQLconnection id is 1
Serverversion: 5.6.34 MySQL Community Server (GPL)
Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates.Other names may be trademarks of their respective
owners.
Type 'help;'or '\h' for help. Type '\c' to clear the current input statement.
mysql>
[root@localhosttools]# mysqladmin -uroot password oldboy123#在命令行設置
Warning:Using a password on the command line interface can be insecure.
[root@localhosttools]# mysql -u root -poldboy123 #通過密碼登錄
Warning: Usinga password on the command line interface can be insecure.
Welcome tothe MySQL monitor. Commands end with ;or \g.
Your MySQLconnection id is 3
Serverversion: 5.6.34 MySQL Community Server (GPL)
Copyright (c)2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates.Other names may be trademarks of their respective
owners.
Type 'help;'or '\h' for help. Type '\c' to clear the current input statement.
mysql>
三. Php5.5.32安裝
3.1安裝依賴包
[root@localhosttools]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devellibiconv-devel –y
[root@localhosttools]# yum install freetype-devel libpng-devel gd-devel libcurl-devellibxslt-devel libxslt-devel –y
cd /server/tools
tar zxf libiconv-1.14.tar.gz
[root@localhosttools]# cd libiconv-1.14
[[email protected]]# ./configure --prefix=/usr/local/libiconv
[[email protected]]# make && make install
安裝與加密相關的3個軟件
wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-6.repo
[[email protected]]# yum -y install libmcrypt-devel mhash mcrypt
3.2解壓安裝php
[root@localhost tools]# tar xf php-5.5.32.tar.gz
[root@localhost tools]# cd php-5.5.32
./configure \
--prefix=/application/php-5.5.32 \
--with-mysql=/application/mysql/ \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-ftp \
--enable-opcache=no
爲防止在make時報錯做一下操作
[root@localhost php-5.5.32]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@localhost php-5.5.32]# touch ext/phar/phar.phar
[root@localhost php-5.5.32]# make && makeinstall
ln -s -f phar.phar /application/php-5.5.32/bin/phar
Installing PDO headers: /application/php-5.5.32/include/php/ext/pdo/
3.3爲php做軟鏈接
[root@localhost php-5.5.32]# ln -s /application/php-5.5.32//application/php
3.4配置php解析文件/配置php-fpm配置文件
[root@localhost php-5.5.32]# cd/server/tools/php-5.5.32
[root@localhost php-5.5.32]# cp php.ini-production/application/php/lib/php.ini
php.ini-production 與 php.ini-development 文件區別關係對比
擴展:文件比較命令 diff zdiff vimdiff windows上的文件比較
[root@localhost php-5.5.32]# cd /application/php/etc/
[root@localhost etc]# cp php-fpm.conf.defaultphp-fpm.conf
3.5啓動php-fpm程序
[root@localhost etc]# /application/php/sbin/php-fpm
[root@localhost etc]# lsof -i:9000
COMMAND PIDUSER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 125951 root 7u IPv4 125162 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 125952 www 0u IPv4 125162 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 125953 www 0u IPv4 125162 0t0 TCP localhost:cslistener (LISTEN)
四.配置nginx+php
[root@localhost conf]# egrep -v "#|^$"nginx.conf.default >nginx.conf
[root@localhost conf]# vim nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
includeextra/blog.conf;
}
[root@localhost ~]# cd /application/nginx/conf/
[root@localhost conf]# mkdir extra
[root@localhost conf]# cd extra/
[root@localhost extra]# vim blog.conf
server {
listen 80;
server_name blog.bai.com;
location/ {
root html/blog;
index index.php index.htmlindex.htm;
}
error_page 500 502 503 504 /50x.html;
location= /50x.html {
root html;
}
location~* .*\.(php|php5)?$ {
root html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
檢查語法重啓Nginx.
[root@localhost extra]# nginx -t
nginx: the configuration file /application/nginx-1.10.3/conf/nginx.confsyntax is ok
nginx: configuration file/application/nginx-1.10.3/conf/nginx.conf test is successful
[root@localhost extra]# nginx -s reload
在windows本地做域名解析
10.0.0.152 blog.bai.org
[root@localhost blog]# pwd
/application/nginx/html/blog
[root@localhost blog]# cat test_info.php
<?php phpinfo(); ?>
訪問網頁:http://blog.bai.org/test_info.php,出現下面網頁即成功。
五.配置nginx連接數據庫
[root@localhost blog]# cat test_mysql.php
<?php
//$link_id=mysql_connect('主機名','用戶','密碼');
//mysql -u用戶 -p密碼 -h 主機
$link_id=mysql_connect('localhost','root','oldboy123')or mysql_error();
if($link_id){
echo "mysql successful by root !\n";
}else{
echo mysql_error();
}
?>
[root@localhost blog]# /etc/init.d/mysqld start
Starting MySQL..... SUCCESS!
訪問網頁,出現下面界面。表示連接成功。
六.wordpress博客搭建
6.1解壓安裝wordpress安裝包
[root@localhost blog]# cd /server/tools/
[root@localhost tools]# tar xfwordpress-4.7.3-zh_CN.tar.gz
[root@localhost tools]# cd wordpress
[root@localhost wordpress]# ls
index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.
license.txt wp-admin wp-config-sample.php wp-includes wp-login
readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.
[root@localhost wordpress]# mv ./*/application/nginx/html/blog/
[root@localhost wordpress]# chown -R www.www/application/nginx/html/blog/
6.2創建數據庫和管理賬號
[root@localhost wordpress]# mysql -u root -poldboy123-e "create database wordpress;"
Warning: Using a password on the command lineinterface can be insecure.
[root@localhost wordpress]# mysql -u root -poldboy123-e "show databases;"
Warning: Using a password on the command lineinterface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
[root@localhost wordpress]# mysql -u root -poldboy123-e "grant all on wordpress.* to wordpress@'10.0.0.%' identified by'oldboy123';"
Warning: Using a password on the command lineinterface can be insecure.
[root@localhost wordpress]# mysql -u root -poldboy123-e "flush privileges;"
6.3設置wordpress
6.3.1通過瀏覽器訪問blog.bai.org。輸入設置的數據庫和主機信息
6.3.2信息輸入正確就會到下面這一步,點擊進行安裝即可。
6.3.3設置用戶名和密碼
6.3.4出現下面的界面,代表安裝成功。