LNMP服务器配置WordPress站点

Linux Alan 9年前 (2015-11-07) 5809次浏览 0个评论 扫描二维码

一键安装包LNMP环境搭建

一直以来都是使用LAMP服务器环境,但Nginx早就盛名在外了,所以这次有一个搭建新站的任务就决定尝试一下LNMP环境的搭建。本文中将暂不采用分别安装独立安装包的,而使用网上的一个一键安装包来完成,参考教程地址:http://lnmp.org/install.html

首先执行screen -S lnmp创建screen会话,出现如下提示

-bash: screen: command not found

于是安装screen:yum install screen -y,重新执行上述命令,然后获取一键安装包,同时解压并执行安装文件(安装文件百度网盘链接: http://pan.baidu.com/s/1o6latlg 密码: d259)

wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz && tar zxf lnmp1.2-full.tar.gz && cd lnmp1.2-full && ./install.sh lnmp

接着就开始设置MySQL的root账号密码

+------------------------------------------------------------------------+
|          LNMP V1.2 for CentOS Linux Server, Written by Licess          |
+------------------------------------------------------------------------+
|        A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux       |
+------------------------------------------------------------------------+
|          For more information please visit http://www.lnmp.org         |
+------------------------------------------------------------------------+
Please setup root password of MySQL.(Default password: root)
Please enter:

确定是否需要开启InnoDB存储引擎

Do you want to enable or disable the InnoDB Storage Engine?
Default enable,Enter your choice [Y/n]: 

确定需安装的MySQLa或MariaDB的版本

You have 5 options for your DataBase install.
1: Install MySQL 5.1.73
2: Install MySQL 5.5.42 (Default)
3: Install MySQL 5.6.23
4: Install MariaDB 5.5.42
5: Install MariaDB 10.0.17
Enter your choice (1, 2, 3, 4 or 5):

确定所需安装的PHP版本

You have 5 options for your PHP install.
1: Install PHP 5.2.17
2: Install PHP 5.3.29
3: Install PHP 5.4.41 (Default)
4: Install PHP 5.5.25
5: Install PHP 5.6.9
Enter your choice (1, 2, 3, 4 or 5):

选择是否安装内存优化

You have 3 options for your Memory Allocator install.
1: Don't install Memory Allocator. (Default)
2: Install Jemalloc
3: Install TCMalloc
Enter your choice (1, 2 or 3): 

配置完成按任意键开始安装

Press any key to install...or Press Ctrl+c to cancel

安装成功后访问服务器ip地址后就会出现在/usr/local/nginx/conf/nginx.conf已配置的/home/wwwroot/default/index.html文件

LNMP服务器配置Wordpress站点

配置多站点

一键安装包已经自动在配置文件/usr/local/nginx/conf/nginx.conf中加入了include vhost/*.conf,因而可以在/usr/local/nginx/conf/vhost/文件夹下添加example.com.conf进行站点的配置。配置内容参考:

server {
        listen  80;
        server_name example.com www.example.com;
        location / {
            root   /var/www/example.com;
            index  index.php index.html index.htm;
        }
	}

location ~ \.php$ {

		root          /var/www/example.com;

		fastcgi_pass   127.0.0.1:9000;

		fastcgi_index  index.php;

		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

		include        fastcgi_params;

			}

直接安装Nginx

首先使用yum install nginx -y来进行nginx的安装

然后安装PHP, MySQL及常用的扩展

yum install httpd mysql php -y 
yum install php-devel php-fpm php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt -y  
yum install mysql-server mysql mysql-devel -y

设置开机启动Nginx, MySQL和php-fpm

chkconfig nginx on

chkconfig mysqld on

chkconfig php-fpm on

执行service mysqld start启动MySQL服务,然后输入mysql_secure_installation设置数据库root密码并删除测试库数据。

执行service nginx start启动http服务,然后在浏览器中输入服务器ip,就会出现如下默认页面

LNMP服务器配置Wordpress站点

可以看出Nginx主配置文件在/etc/nginx/nginx.conf中,可以在该文件中发现include /etc/nginx/conf.d/*.conf,所以配置多站点的方法与上面相似,只需在/etc/nginx/conf.d/文件夹下创建一个conf文件即可。

我们刚刚访问的页面就是default.conf中配置的/usr/share/nginx/html下的index.html文件

安装Wordpress

首先在MySQL上创建数据库用于安装时使用,然后上传Wordpress安装文件或直接使用wget http://wordpress.org/latest.tar.gz下载最新版本然后解压到/var/www/example.com目录下

输入服务器IP或设置好解析的域名开启Wordpress的安装,这里就不再赘述。

我们着重讲一下Wordpress在Nginx的rewrite配置,我们都知道Wordpress默认的.htaccess文件是针对Apache的,要在Nginx下实现类似的重写规则就需要进行额外的配置。配置的方法是在前面的/etc/nginx/conf.d/example.com.conf文件中的location / 内加入如下代码

if (-f $request_filename/index.php){
	   rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
		rewrite (.*) /index.php;
}

 

 

喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址