前期准备:
关闭防火墙于selinux:
iptables -F #关闭防火墙
setenforce 0 #关闭selinux
getenforce #查看selinux状态
vim /etc/selinux/config #在配置文件中修改selinux
[root@localhost html]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #改成disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
:wq
下载源码包:
将源码包下载到/usr/local/src路径中,源码包可以在软件官网中有下载,这里不再一一列出下载地址,需要下载的源码包有mysql,nginx,php,wordpress.
[root@localhost src]# ls
mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz php-5.6.30 wordpress-4.9.4-zh_CN.tar.gz
nginx-1.12.1 php-5.6.30.tar.gz
mysql-5.6.35-linux-glibc2.5-x86_64 nginx-1.12.1.tar.gz wordpress
开发环境与编译工具:
yum -y groupinstall Development Tools
yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio libaio-devel perl-Data-Dumper net-tools
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel libxml2*
1.安装mysql并配置:
查看并删除系统的mysql服务:
rpm -qa | grep mysql #如果查询到mysql,就是用rpm -e命令来卸载了原来的mysql
rm -rf /etc/my.cnf #删除原来mysql的配置文件
解压并复制文件:
tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz #在下载目录中解压文件
mkdir /usr/local/mysql #创建安装目录,方便以后管理
cp -R ./mysql-5.6.35-linux-glibc2.5-x86_64/* /usr/local/mysql/ #复制解压文件的目录中
切换目录并安装:
#使用cmake工具进行安装mysql
cd /usr/local/mysql/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make install
创建数据目录,执行用户并执行初始化脚本:
#初始化脚本
mkdir /data
useradd -s /sbin/nologin mysql
chmod +x ./scripts/mysql_install_db
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
复制配置文件并配置:
#配置文件及启动脚本
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysql.server
chmod 755 /etc/init.d/mysql.server
在`vim /etc/my.cnf`配置如下:
[root@localhost mysql]# vim /etc/my.cnf
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
datadir =/data/mysql #添加这个数据存放路径
# port = .....
# server_id = .....
# socket = .....
socket = /var/lib/mysql/mysql.sock #还有这个,其他暂时不用动
...省略...
:wq
启动mysql并初始设置:
/etc/init.d/mysql.server start #启动mysql
/usr/local/mysql/bin/mysql_secure_installation #初始设置,包含root密码设置等等
检查服务是否启动:
[root@localhost html]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7102/nginx: master
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1427/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1032/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1026/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1268/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 7304/sshd: root@pts
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 7304/sshd: root@pts
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 1032/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1026/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1268/master
tcp6 0 0 ::1:6010 :::* LISTEN 7304/sshd: root@pts
tcp6 0 0 ::1:6011 :::* LISTEN 7304/sshd: root@pts
tcp6 0 0 :::3306 :::* LISTEN 39096/mysqld
#3306已经启动监听
看到mysql启动了就算安装mysql完成了.
2.安装php并配置:
解压并进入目录:
cd /usr/local/src/ #进入下载目录
tar -zxvf php-5.6.30.tar.gz
cd php-5.6.30/ #进入解压目录
添加用户并编译安装:
#添加php-fpm用户
useradd -s /sbin/nologin php-fpm
#可以通过./configure --help来按需要进行添加编译选项
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock
make && make install
复制配置文件并设置权限:
#复制配置文件及启动脚本
cp php.ini-production /usr/local/php-fpm/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
创建配置文件:
创建vim /usr/local/php-fpm/etc/php-fpm.conf
,内容如下:
[root@localhost php-5.6.30]# vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock #监听ip和端口,端口默认为9000
listen.mode = 666 #用来定义php-fcgi.sock文件的权限
user = php-fpm
group = php-fpm
pm = dynamic #后面这些都是关于进程的信息
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
:wq
检查配置文件并启动:
/usr/local/php-fpm/sbin/php-fpm -t
chkconfig --add php-fpm
chkconfig php-fpm on
service php-fpm start
检查服务是否启动:
[root@localhost src]# ps aux | grep php
root 3023 0.0 0.1 55896 3492 ? Ss Jun09 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 3024 0.0 0.5 62032 9940 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3025 0.0 0.4 61264 8940 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3026 0.0 0.5 61836 11016 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3027 0.0 0.6 64164 11620 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3028 0.0 0.5 62116 9772 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3029 0.0 0.5 61580 10912 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3030 0.0 0.4 59300 8432 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3031 0.0 0.2 58292 5380 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3032 0.0 0.6 64164 11620 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3033 0.0 0.4 61256 8912 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3034 0.0 1.5 81572 29416 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3035 0.0 0.5 61580 10924 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3036 0.0 1.3 76660 25900 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3037 0.0 0.6 62248 11820 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3038 0.0 0.5 61580 10912 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3039 0.0 0.6 62500 12120 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3040 0.0 0.4 59300 8428 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3041 0.0 0.5 62116 9776 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3042 0.0 0.6 64452 12880 ? S Jun09 0:00 php-fpm: pool www
php-fpm 3043 0.0 0.5 62116 9772 ? S Jun09 0:00 php-fpm: pool www
root 8573 0.0 0.0 112708 976 pts/3 S+ 00:12 0:00 grep --color=auto php
这里看到php已经启动,说明安装成功了.
3.安装并配置nginx:
解压并进入目录:
cd /usr/local/src/ #进入下载目录
tar -zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1/
编译安装:
#可以使用./configure --help查看更多信息
./configure --prefix=/usr/local/nginx
make && make install
创建启动脚本并修改权限:
在vim /etc/init.d/nginx中创建脚本
chkconfig
这个和下面的选项好正确,否则会报service nginx does not support chkconfig的错误,
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
:wq
chmod 755 /etc/init.d/nginx
加入服务列表并开机启动:
chkconfig --add nginx
chkconfig nginx on
修改nginx.conf文件:
在/usr/local/nginx/conf/目录下修改nginx.conf文件,为了保证安全先备份原来conf文件并创建新的配置文件.
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
配置新的vim /usr/local/nginx/conf/nginx.conf文件,内容如下:
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
:wq
检查配置文件语法错误并启动服务:
/usr/local/nginx/sbin/nginx -t
service nginx start
检查服务是否启动:
[root@localhost src]# netstat -lntp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7102/nginx: master
到这里LNMP已经搭建完成了,可以测试一下
测试LNMP环境:
在/usr/local/nginx/html/目录中添加一个test.php 的文件,内容如下:
[root@localhost php-5.6.30]# vim /usr/local/nginx/html/test.php
<?php
phpinfo();
?>
:wq
通过客户端访问LNMP服务器,结果如下:
证明LNMP已经搭建完成了.
4.安装wordpress:
解压并复制文件:
进入下载目录并解压
cd /usr/local/src
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz
删除nginx服务主页目录/usr/local/nginx/html/中的所有文件,并将解压目录的文件全部复制过去
rm -rf /usr/local/nginx/html/*
cp -a /usr/local/src/wordpress/* /usr/local/nginx/html/
在mysql中设置wordpress的账号密码,数据库:
登陆mysql
/usr/local/mysql/bin/mysql -uroot -p
设置用户密码权限等等
mysql> GRANT ALL ON wordpress.* TO 'wpuser'@'%' IDENTIFIED BY 'wppass'; #设置用户密码权限
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE DATABASE wordpress; #创建wordpress数据库
复制配置文件模版并配置:
cd /usr/local/nginx/html/
cp wp-config-sample.php wp-config.php #配置文件名称不要改其他的,会报错
[root@localhost html]# vim wp-config.php
/**#@+
* 身份认证密钥与盐。
*
* 修改为任意独一无二的字串!
* 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/
* WordPress.org密钥生成服务}
* 任何修改都会导致所有cookies失效,所有用户将必须重新登录。
*
* @since 2.6.0
*/
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
/**#@-*/
/**
* WordPress数据表前缀。
*
* 如果您有在同一数据库内安装多个WordPress的需求,请为每个WordPress设置
* 不同的数据表前缀。前缀名只能为数字、字母加下划线。
*/
$table_prefix = 'wp_';
* * ABSPATH
*
* @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
*
* @package WordPress
*/
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress'); #改为数据库的名称
/** MySQL数据库用户名 */
define('DB_USER', 'wpuser'); #改为数据库用户名
/** MySQL数据库密码 */
define('DB_PASSWORD', 'wppass'); #数据库的密码
/** MySQL主机 */
define('DB_HOST', 'localhost'); #允许访问的主机地址
/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');
/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');
/**#@+
* 身份认证密钥与盐。
*
...省略...
:wq
客户端登陆wordpress论坛:
配置完成了就 可以通过客户端去登陆论坛,按页面提示来操作就可以了,
填写相应的信息,包括之前数据库创建的用户密码,自己的邮箱等等,格式正确就可以点安装wordpress了
安装成功直接点登录
用户和密码正确了,就可以看到论坛的先过出来了.到这里就全部完成了LNMP+wordpress的搭建了