简单的LAMP环境搭建

 

一、安装php,mysql

二、相关配置文件

三、启动httpd,测试php连接

四、测试php连接mysql

五、安装wordpress

 

生产环境需要编译安装,下次博客再更新

 

一、安装php,mysql

yum install -y php

如果没有安装httpd,使用yum源安装php时会一并安装

 

安装mysql服务端和客户端,另外mysql与php通信,需要安装php-mysql程序包

[root@test3 html]# yum install -y mysql mysql-server php-mysql
[root@test3 html]# chkconfig --list mysqld
mysqld         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@test3 html]# chkconfig --list httpd
httpd          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@test3 html]# chkconfig mysqld on
[root@test3 html]# chkconfig --list mysqld
mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

 

二、相关配置文件


1、php

安装完成后其主配置文件为/etc/php.ini

和apache结合起来工作,配置文件/etc/httpd/conf.d/php.conf


2、httpd

主配置文件/etc/httpd/conf/httpd.conf


 

三、启动httpd,测试php连接

1、启动httpd服务

[root@test3 vsftpd]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 211.139.136.73 for ServerName
                                                           [  OK  ]

如果有上述提示,则在/etc/httpd/conf/httpd.conf中添加一行

ServerName  localhost:80    #这里的localhost可以是主机名和IP

 

2、配置文件

(1)、编辑/etc/httpd/conf/httpd.conf

DirectoryIndex index.php index.html index.html.var    添加index.php

(2)、在/var/www/html/下新建index.php文件,编辑index.php,内容如下

<h1>host1</h1>
<?php
        phpinfo();
?>

在浏览器中输入主机地址,此时访问成功

image

 

四、测试php连接mysql


1、mysql相关

服务文件:/etc/init.d/mysqld

启动服务:service mysqld start 或/etc/init.d/mysqld start,第一次启动会初始化,mysql监听在tcp/3306端口

客户端执行程序:mysql

默认用户:root,密码为空


2、基础命令:

 

(1)、服务端命令,命令末尾需要分号

SHOW DATABASES:显示有权限访问的所有数据库

SELECT DATABASE():显示当前默认数据库

CREATE DATABASE DB_NAME:创建名为DB_NAME的数据库,创建的数据库文件目录在/var/lib/mysql/

DROP DATABASE DB_NAME:删除名为DB_NAME的数据库

(2)、客户端命令,命令末尾不需要分号

USE DB_NAME:设置DB_NAME为默认数据库

 

3、测试php连接mysql

编辑/var/www/html/index.php,内容如下,保存退出后,重载httpd

<h1>host1</h1>
<?php
        $link=mysql_connect(localhost,root,'');    #执行函数返回值mysql_connect(localhost,"root",)存储在变量$link中
        if ($link)
                echo "Sueccess.";
        else
                echo "Failure.";
?>

 

浏览器地址栏输入主机地址,显示如下信息则说明php成功连接mysql

image

关掉mysqld服务,再次测试

image

 

五、安装wordpress

LAMP环境,常见开源应用:

wordpress,discuz,phpwind,phpbb,drupal,joomla

 

这里我们安装wordpress


1、下载wordpress

[root@test3 ~]# wget https://cn.wordpress.org/wordpress-4.2-zh_CN.zip
[root@test3 ~]# ls
anaconda-ks.cfg  install.log.syslog   wordpress-4.2-zh_CN.zip
install.log


2、将wordpress所有文件放到httpd工作目录

[root@test3 ~]# ls
anaconda-ks.cfg  install.log.syslog   wordpress   install.log   wordpress-4.2-zh_CN
[root@test3 ~]# tar -cf html.tar /var/www/html/*    #有需要可以先备份下站点目录中的文件
tar: Removing leading `/' from member names
[root@test3 ~]# ls
anaconda-ks.cfg  install.log   wordpress-4.2-zh_CN.ziphtml.tar   install.log.syslog   wordpress
[root@test3 ~]# tar -tvf html.tar    #查看归档文件内容 
-rw-r--r-- root/root        85 2015-05-16 18:00 var/www/html/index.html
-rw-r--r-- root/root       122 2015-05-17 23:20 var/www/html/index.php
[root@test3 ~]# rm /var/www/html/* �Cf    #清空站点目录中的内容
[root@test3 ~]# ls /var/www/html/
[root@test3 ~]# mv wordpress/* /var/www/html/    #将wordpress中的文件移到站点目录
[root@test3 ~]# ls /var/www/html/
index.php    wp-activate.php     wp-comments-post.php  wp-cron.php        wp-load.php   wp-settings.php   xmlrpc.php
license.txt  wp-admin            wp-config-sample.php  wp-includes        wp-login.php  wp-signup.php
readme.html  wp-blog-header.php  wp-content            wp-links-opml.php  wp-mail.php   wp-trackback.php

然后可以使用浏览器连接,连接成功,会提示我们需要做些准备工作

image


3、完成简单的准备工作

(1)、连上mysql,创建数据库

mysql> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

(2)、修改配置文件

[root@test3 html]# cp wp-config-sample.php wp-config.php
[root@test3 html]# vim wp-config.php    #编辑配置文件

// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'root');

/** MySQL数据库密码 */
define('DB_PASSWORD', '');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

再次刷新浏览器,出现下图信息,说明已经成功在LAMP环境下安装了wordpress

image

你可能感兴趣的:(mysql,wordpress,lamp)