之前搭建了一次LNMP的环境,在这里做一下总结。
本次操作是在vmware虚拟机上进行的。
操作平台:
操作系统:CentOS7.2
nginx1.9.9
mysql5.7.16
php7.0.12
软件包位置目录:/home/
各软件包安装路径:
nginx1.9.9 : /etc/nginx
mysql5.7.16 : /usr/local/mysql
php7.0.12 : /etc/php
准备好软件包:mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz,nginx-1.9.9, php-7.0.1.tar.gz
另外安装第三方yum源
wget http://www.atomicorp.com/installers/atomic
sh ./atomic
当然也可以安装其他的yum源,例如网易的,中科软的都可以(下面的网址可供参考学习)
http://blog.chinaunix.net/uid-23683795-id-3477603.html
一、部署mysql:
注:其中可能有关于my.cnf的问题,可以先删除/etc/my.cnf
解压:
tar zxvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
复制:
cp mysql-5.7.16-linux-glibc2.5-x86_64/ /usr/local/mysql -r
添加系统mysql组和mysql用户:
groupadd mysql
useradd -r -g mysql mysql
修改目录所有者:
cd /usr/local/mysql/
chown -R mysql:mysql .
chgrp -R mysql .
安装:
cd /usr/local/mysql/bin
yum install libaio
./mysql_install_db –user=mysql –basedir=/usr/local/mysql/ –datadir=/usr/local/mysql/data
mkdir /var/log/mariadb
chmod 700 /var/log/mariadb
mkdir /var/run/mariadb
chmod 700 /var/run/mariadb
cd ../support-files
./mysql.server start
./mysql.server stop停止mysql(安装时不要使用)
获取初始密码:
cat /root/.mysql_secret
利用初始密码登录:
cd /usr/local/mysql/bin
./mysql -u root -p
重新设置密码:
set password=password(‘111111’);
设定远程登录mysql:
use mysql;
select Host,User from user;
GRANT ALL PRIVILEGES ON . TO root@’%’ identified by ‘111111’;
flush privileges;
添加服务项
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/
启动服务
service mysql start
二、部署Nginx:
安装nginx前,首先检查gcc是否已经装好了。
输入命令:gcc -v;装好了则会告诉你版本信息,否则会找不到命令。
若没有安装,需要执行如下命令进行安装:
yum -y install gcc;
yum -y install pcre-devel openssl openssl-devel;mkdir /etc/nginx
mkdir /etc/nginx/geoipwget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
tar zxvf GeoIP.tar.gz
./configure
make
make installcd /etc/nginx/geoip
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat
.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz
解压下载好的nginx压缩包
tar zxvf nginx-1.9.9
./configure –prefix=/etc /nginx –with-http_geoip_module
make
make install
此时nginx就安装完成了。
nginx的启动和重启
1、启动Nginx:
/etc/nginx/sbin/nginx -t 查看配置信息是否正确
/etc/nginx/sbin/nginx 启动
2、平滑启动nginx
/etc/nginx/sbin/nginx -s reload
3、查看nginx的进程:
ps -ef|grep nginx
三、php的安装:
tar zxvf php-7.0.1.tar.gz
安装依赖
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers MySQL php-mcrypt libmcrypt libmcrypt-devel
编译和安装php
./configure –prefix=/etc/php –enable-fpm –with-mcrypt –enable-mbstring –disable-pdo –with-curl –disable-debug –disable-rpath –enable-inline-optimization –with-bz2 –with-zlib –enable-sockets –enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex –with-mhash –enable-zip –with-pcre-regex –with-mysql –with-mysqli –with-gd –with-jpeg-dir
make
make test
make install
配置php环境(先进入php解压目录)
cp php.ini-development / etc/php/lib/php.ini
cp /etc/php/etc/php-fpm.conf.default /etc/php/etc/php-fpm.conf
cp / etc /php/etc/php-fpm.d/www.conf.default /etc/php/etc/php-fpm.d/www.conf
cp -R /etc/php/sbin/php-fpm /etc/init.d/php-fpm
php的启动
/etc/php/sbin/php-fpm
php进程的查看
ps -ef|grep php-fpm
四、整合php和nginx
让nginx能够识别php的文件
修改nginx的配置文件:
vi /etc/nginx/conf/nginx.conf
user nobody;
worker_processes 1;error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;pid logs/nginx.pid;
events {
worker_connections 1024;
}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"';
#access_log logs/access.log main;
##
#GeoIP Configs
##
geoip_country /etc/nginx/geoip/GeoIP.dat;
geoip_city /etc/nginx/geoip/GeoLiteCity.dat;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
# Port to listen to
listen 80;
server_name localhost;
# Root Directory
root /var/www/httpdocs;
# Index files
index index.php index.html index.htm;
if ($geoip_country_code ~ "CN"){ rewrite ^/?$ /cn/ permanent;}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
#charset koi8-r;
#access_log logs/host.access.log main;
#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 html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
set $fsn /index.php;
if (-f $document_root$fastcgi_script_name) {
set $fsn $fastcgi_script_name;
}
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# Is there any reason why you're not going to the FPM PHP socket instead?
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#include vhosts.conf;
}
保存配置文件,并重启nginx服务
/etc/nginx/sbin/nginx -t //查看配置信息是否正确
/etc /nginx/sbin/nginx -s reload
五、部署wp
mkdir /var/www/httpdocs
tar zxvf wordpress-4.7-zh_CN.tar.gzcp -r wordpress/ /var/www/httpdocs
cp wordpress/ /var/www/httpdocs
chmod 777 -R /var/www/httpdocs
chmod 777 -R /var/www/httpdocs
数据库里创建对应库然后浏览器访问服务器IP按照提示部署即可