LNMP搭建wordpress

使用LNMP搭建wordpress

  • 1、MySQL5.7.11部署
  • 2、linux下Nginx编译安装
  • 2.1、CentOS7下配置Nginx的开机自启动
  • 2.2、CentOS6下配置Nginx的开机自启动
  • 3、PHP安装
  • 3.1、CentOS7下配置PHP的开机自启动
  • 3.2、CentOS6下配置PHP的开机自启动

开始修改配置文件

1、MySQL5.7.11部署

  • MySQL5.7部署参考文档:
  • https://github.com/Hackeruncle/MySQL/blob/master/MySQL%205.7.11%20Install.txt

2、Linux下Nginx编译安装

进入Nginx官网:http://nginx.org/,点击download,选择稳定版本,本地下载后使用rz命令上传到linux服务器。
LNMP搭建wordpress_第1张图片
1、解压到/usr/local目录,做一个软连接,软连接的好处?方便软件升级。
[hadoop@hadoop001 local]$ sudo tar -xzvf nginx-1.12.2.tar.gz -C /usr/local/
[hadoop@hadoop001 local]$ ln -s nginx-1.12.2/ nginx

2、注意nginx需要由专门的用户来维护,useradd nginx,passwd nginx

3、直接进入到目录开始编译提示缺少一些必要的包,此时我们需要使用yum进行安装这些必要的包: yum -y install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

4、此时直接进入到nginx的目录执行此命令:[hadoop@hadoop001 nginx]$ sudo ./configure --prefix=/usr/local/nginx,编译过程中提示的信息如下所示:

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

5、nginx编译完成后进行安装,命令如下:make && make install,等待如何验证是否编译成功呢,我们进行编译的时候信息提示如下:

[root@hadoop001 nginx]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/usr/local/nginx-1.12.2'
make[1]: Nothing to be done for `build'.
make[1]: Leaving directory `/usr/local/nginx-1.12.2'
make -f objs/Makefile install
make[1]: Entering directory `/usr/local/nginx-1.12.2'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
        || mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
        || mv '/usr/local/nginx/sbin/nginx' \
                '/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
        || mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp: 鈥榗onf/koi-win鈥and 鈥usr/local/nginx/conf/koi-win鈥are the same file
make[1]: *** [install] Error 1
make[1]: Leaving directory `/usr/local/nginx-1.12.2'
make: *** [install] Error 2

6、如上信息提示是因为我们安装了软连接的原因:查看版本就是如下命令:

[root@hadoop001 nginx]# cd sbin
[root@hadoop001 sbin]# ll
total 7152
-rwxr-xr-x 1 root root 3660184 Mar  5 17:28 nginx
-rwxr-xr-x 1 root root 3660184 Mar  5 17:27 nginx.old
[root@hadoop001 sbin]# ./nginx -v
nginx version: nginx/1.12.2

从浏览器上确认nginx是否安装成功:
LNMP搭建wordpress_第2张图片

2.1、CentOS7下配置开机nginx的开机自启动

7、配置nginx的开机自启动:
参考博客:https://www.cnblogs.com/piscesLoveCc/p/5867900.html

1、在如下目录下创建一个文件:
[root@hadoop001 system]# pwd
/lib/systemd/system
[root@hadoop001 system]# ll nginx.service 
-rwxr-xr-x 1 root root 256 Mar  6 13:43 nginx.service

2、nginx.service的文件内容如下:
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3、设置开机启动
systemctl enable nginx.service

启动nginx服务:systemctl start nginx.service

设置开机自启动:systemctl enable nginx.service

停止开机自启动:systemctl disable nginx.service

查看服务当前的状态:systemctl status nginx.service

重新启动服务:systemctl restart nginx.service

2.2、CentOS6下配置开机nginx的开机自启动

配置开机启动还遇到了一个问题,执行脚本的时候报错如下:

[root@hadoop001 sbin]# ./nginx
nginx: [emerg] unknown directive " " in /usr/local/nginx/conf/nginx.conf:51

经过百度得知原因是换行符和tab键和空格起的冲突。

1、主要是在编辑vi /etc/init.d/nginx的时候:
nginx="/usr/local/nginx/sbin/nginx"		启动目录
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"		配置文件目录

2、内嵌在系统中的服务此时去启动
[root@hadoop001 init.d]# ll nginx
-rwxr-xr-x 1 root root 1745 Mar  6 17:32 nginx
[root@hadoop001 init.d]# service nginx start
Starting nginx

3、编辑完成后重新启动reboot,再次进行监听查看得到没有问题;
[root@hadoop001 ~]# ps -ef|grep php
root      1191     1  0 13:18 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
hadoop    1192  1191  0 13:18 ?        00:00:00 php-fpm: pool www          
hadoop    1193  1191  0 13:18 ?        00:00:00 php-fpm: pool www          
root      2782  2733  0 13:19 pts/0    00:00:00 grep php
[root@hadoop001 ~]# ps -ef|grep nginx
root      2641     1  0 13:18 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    2644  2641  0 13:18 ?        00:00:00 nginx: worker process                                          
root      2790  2733  0 13:19 pts/0    00:00:00 grep nginx

3、PHP安装

make 命令出现:“make:*** No targets specified and no makefile found.Stop.”
注意:使用yum update即可解决

  • 首先需要安装依赖包: 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

1、进入目录开始编译安装,下面是常用的一些扩展,我们直接进行安装:

  • ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --with-openssl --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl

2、编译好后进行安装:make && make install,因为这台云主机的配置太低1核2G,所以提示如下,虚拟内存不够分配,参照如下博客进行重新编译。

virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决办法:参照这篇博客写的:https://www.cnblogs.com/rxbook/p/8005944.html

3、找到php.ini-production,复制到/usr/local/php下,并且改名为php.ini:

[root@hadoop001 php]# pwd
/usr/local/php
[root@hadoop001 php]# ll php.ini
php.ini              php.ini-development  php.ini-production
[root@hadoop001 php]# ll php.ini-production 
-rw-rw-r-- 1 root root 71413 Feb 18 17:46 php.ini-production
[root@hadoop001 php]# cp php.ini-production /usr/local/php/php.ini 

4、复制启动脚本,如下使用绝对路径:

1、复制启动脚本
[root@hadoop001 php]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

2、修改php-fpm的配置文件:
[root@hadoop001 etc]# cd /usr/local/php/etc
[root@hadoop001 etc]# cp php-fpm.conf.default php-fpm.conf
[root@hadoop001 etc]# vi php-fpm.conf
去掉pid前的分号:;pid = run/php-fpm.pid

3、进入如下目录是PHP下的目录,拷贝一份配置文件:
[root@hadoop001 etc]# cd php-fpm.d/
[root@hadoop001 php-fpm.d]# ll
total 20
-rw-r--r-- 1 root root 18869 Mar  6 12:35 www.conf.default
[root@hadoop001 php-fpm.d]# cp www.conf.default www.conf

4、编辑www.conf,输入用户名和用户组
user = hadoop
group = hadoop

5、启动PHP,启动、停止、重启分别对饮搞得是start stop restart
[root@hadoop001 /]# /etc/init.d/php-fpm start
Starting php-fpm  done
[root@hadoop001 /]# ps -ef|grep php
root      7554     1  0 12:49 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
hadoop    7555  7554  0 12:49 ?        00:00:00 php-fpm: pool www
hadoop    7556  7554  0 12:49 ?        00:00:00 php-fpm: pool www
root      7558 10119  0 12:49 pts/3    00:00:00 grep --color=autophp

3.1、PHP服务的自启动配置

php服务的自启动安装,也只是需要参照nginx自启动写的就行

1、还是在系统文件中创建一个文件夹:
[root@hadoop001 system]# pwd
/lib/systemd/system
[root@hadoop001 system]# ll php-fpm.service 


2、输入如下内容:
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
PrivateTmp=true
[Install]
WantedBy=multi-user.target


3、自启动服务:
[root@hadoop001 system]# systemctl enable php-fpm.service 
[root@hadoop001 system]# ps -ef|grep php
root      3252  2974  0 15:09 pts/0    00:00:00 grep --color=autophp
[root@hadoop001 system]# systemctl start php-fpm.service 
[root@hadoop001 system]# ps -ef|grep php
root      3261     1  0 15:09 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
hadoop    3262  3261  0 15:09 ?        00:00:00 php-fpm: pool www
hadoop    3263  3261  0 15:09 ?        00:00:00 php-fpm: pool www
root      3265  2974  0 15:09 pts/0    00:00:00 grep --color=autophp


4、重新启动验证来进行测试:
没问题

3.2、CentIOS6下配置PHP服务的开机自启动

CentOS6的系统服务配置目录:/etc/init.d;
直接参考此篇博客:一通复制黏贴就可以了

注意在CentOS6中配置的服务我们启动php-fpm的命令:
进入到/etc/init.d目录下,因为我们已经配置在系统服务中了,如何启动呢:service php-fpm start

修改配置文件

第一步: 编辑nginx与php连通性测试文件,并进行测试

vi /usr/local/nginx/html/test_info.php
echo ''

LNMP搭建wordpress_第3张图片

第二步:
nginx.conf的原配置文件如下:

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

修改后的如下显示:

server {
        listen       80;
        server_name  www.motu.tech;		此处需要是我们购买的域名,并且域名已经做好了一个映射关系

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /usr/local/nginx/html/wordpress;
            index index.php index.html index.htm;
        }

LNMP搭建wordpress_第4张图片

此时使用网址即可直接访问:
LNMP搭建wordpress_第5张图片

正式安装的时候:应该是先在mysql数据库下安装了wordpress库,然后直接在/wordpress目录下,拷贝一份wp-config.php文件;
这他妈的就好了。
LNMP搭建wordpress_第6张图片

你可能感兴趣的:(LNMP搭建wordpress)