首页 > 技术文章 > LAMP架构

zhangpingping 2018-09-13 19:25 原文

第一步:安装及配置httpd

1,yum安装httpd

         [root@68-HTTPD~]# yum install -y httpd

 

2、修改httpd的配置文件

         [root@68-HTTPD~]# vim /etc/httpd/conf/httpd.conf

 

         需要修改的行如下:没有在此列出的保持默认即可

         ServerNamewww.example.com:80  取消注释以免检查格式报错

 

         #DocumentRoot"/var/www/html"  加上注释,因为我们要启用虚拟主机

 

         NameVirtualHost*:80  取消注释,因为后面要启用虚拟主机

 

3、编辑基于域名的虚拟主机配置文件

         [root@68-HTTPD~]# vim /etc/httpd/conf.d/vhosts.conf

                   <VirtualHost*:80>

                       ServerName www.phpwind.net

                       DocumentRoot "/vhosts/phpwind"

                       <Directory"/vhosts/phpwind">

                           Options None

                           AllowOverride None

                           Order Allow,deny

                           Allow from all

                       </Directory>

                   </VirtualHost>

                   <VirtualHost*:80>

                       ServerName www.discuz.net

                       DocumentRoot "/vhosts/discuz"

                       <Directory"/vhosts/discuz">

                           Options None

                           AllowOverride None

                           Order Allow,deny

                           Allow from all

                       </Directory>

                   </VirtualHost>

                   <VirtualHost*:80>

                       ServerName www.wordpress.net

                       DocumentRoot "/vhosts/wordpress"

                       <Directory"/vhosts/wordpress">

                           Options None

                           AllowOverride None

                           Order Allow,deny

                           Allow from all

                       </Directory>

                   </VirtualHost>

 

4、建立虚拟主机的网站根目录

         [root@68-HTTPD~]# mkdir -pv /vhosts/{phpwind,discuz,wordpress}

         mkdir:created directory `/vhosts'

         mkdir:created directory `/vhosts/phpwind'

         mkdir:created directory `/vhosts/discuz'

         mkdir:created directory `/vhosts/wordpress'

 

5,检查各配置文件语法格式是否有误

         [root@68-HTTPD~]# httpd -t

         SyntaxOK  说明所有的书写语法没有错误,可以正常启动HTTPD服务了

 

第二步:安装php

         [root@68-HTTPD~]# yum install -y php php-mysql

其实这一步可以和第一步合并安装,因为php只需要安装一下,不需要做其它操作

 

第三步:安装及配置mysql-server(包括创建后续论坛以及博客所需要的帐户及数据库)

1,安装mysql-server

         [root@68-HTTPD~]# yum install -y mysql-server

 

2,启动mysql

         [root@68-HTTPD~]# service mysqld start

         InitializingMySQL database:  WARNING: The host'68-HTTPD' could not be looked up with resolveip.

         Thisprobably means that your libc libraries are not 100 % compatible

         withthis binary MySQL version. The MySQL daemon, mysqld, should work

         normallywith the exception that host name resolving will not work.

         Thismeans that you should use IP addresses instead of hostnames

         whenspecifying MySQL privileges !

         InstallingMySQL system tables...

         OK

         Fillinghelp tables...

         OK

 

         Tostart mysqld at boot time you have to copy

         support-files/mysql.serverto the right place for your system

 

         PLEASEREMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

         Todo so, start the server, then issue the following commands:

 

         /usr/bin/mysqladmin-u root password 'new-password'

         /usr/bin/mysqladmin-u root -h 68-HTTPD password 'new-password'

 

         Alternativelyyou can run:

         /usr/bin/mysql_secure_installation

 

         whichwill also give you the option of removing the test

         databasesand anonymous user created by default. This is

         stronglyrecommended for production servers.

 

         Seethe manual for more instructions.

 

         Youcan start the MySQL daemon with:

         cd/usr ; /usr/bin/mysqld_safe &

 

         Youcan test the MySQL daemon with mysql-test-run.pl

         cd/usr/mysql-test ; perl mysql-test-run.pl

 

         Pleasereport any problems with the /usr/bin/mysqlbug script!

 

                                                                 [  OK  ]

         Startingmysqld:                                          [  OK  ]

         [root@68-HTTPD~]#

         能看到如上信息时说明mysql启动成功了,同时,成功的日志记录如下

 

         [root@68-HTTPD~]# cat /var/log/mysqld.log

         16100917:33:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

         16100917:33:25  InnoDB: Initializing bufferpool, size = 8.0M

         16100917:33:25  InnoDB: Completedinitialization of buffer pool

         InnoDB:The first specified data file ./ibdata1 did not exist:

         InnoDB:a new database to be created!

         16100917:33:25  InnoDB: Setting file ./ibdata1size to 10 MB

         InnoDB:Database physically writes the file full: wait...

         16100917:33:25  InnoDB: Log file ./ib_logfile0did not exist: new to be created

         InnoDB:Setting log file ./ib_logfile0 size to 5 MB

         InnoDB:Database physically writes the file full: wait...

         16100917:33:25  InnoDB: Log file ./ib_logfile1did not exist: new to be created

         InnoDB:Setting log file ./ib_logfile1 size to 5 MB

         InnoDB:Database physically writes the file full: wait...

         InnoDB:Doublewrite buffer not found: creating new

         InnoDB:Doublewrite buffer created

         InnoDB:Creating foreign key constraint system tables

         InnoDB:Foreign key constraint system tables created

         16100917:33:26  InnoDB: Started; log sequencenumber 0 0

         16100917:33:26 [Note] Event Scheduler: Loaded 0 events

         16100917:33:26 [Note] /usr/libexec/mysqld: ready for connections.

         Version:'5.1.73'  socket:'/var/lib/mysql/mysql.sock'  port:3306  Source distribution

         [root@68-HTTPD~]#

 

3,配置mysql的用户帐户及建立论坛所需要的数据库

   我们这里准备使用上面创建好的三台虚拟主机搭建两个论坛(phpwind,discuz),一个博客(wordpress

  phpwind的数据库:pwdb,数据库管理员:pwadmin

  discuz的数据库:dcdb,数据库管理员:dcadmin

  wordpress的数据库:wpdb,数据库管理员:wpadmin

 

[root@68-HTTPD ~]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.1.73 Source distribution

 

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rightsreserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current inputstatement.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.02 sec)

 

mysql> create database pwdb;           创建各论坛的数据库

Query OK, 1 row affected (0.04 sec)

 

mysql> create database dcdb;

Query OK, 1 row affected (0.00 sec)

 

mysql> create database wpdb;

Query OK, 1 row affected (0.01 sec)

 

mysql> grant all on pwdb.* to 'pwadmin'@'127.0.0.1' identified by'pwadmin';  创建连接各论坛的数据库帐户及密码

Query OK, 0 rows affected (0.01 sec)

 

mysql> grant all on dcdb.* to 'dcadmin'@'127.0.0.1' identified by'dcadmin';

Query OK, 0 rows affected (0.03 sec)

 

mysql> grant all on wpdb.* to 'wpadmin'@'127.0.0.1' identified by'wpadmin';

Query OK, 0 rows affected (0.00 sec)

 

mysql> use mysql    进入mysql自身的数据库

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

mysql> update user set password=password('guestadmin') whereuser='root';    修改管理员root帐户的密码

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed:3  Warnings: 0

 

mysql> flush privileges;   更新数据库的授权信息

Query OK, 0 rows affected (0.02 sec)

 

mysql> exit

Bye

[root@68-HTTPD ~]#

 

第四步:安装论坛、博客模板

 

2、phpwin论坛安装过程详解

 

我们在第一台虚拟主机(www.phpwind.net)上安装phpwind论坛

 

解压模板文件包,放置到对应的网站根目录下

 

[root@68-HTTPD ~]# unzip phpwind_v9.0.1_utf8.zip -d phpwind

 

[root@68-HTTPD ~]# cd phpwind/phpwind_v9.0.1_20141223/upload/

 

[root@68-HTTPD upload]# mv * /vhosts/phpwind/

 

[root@68-HTTPD upload]# ll -a

 

total 12

 

drwxrwxr-x. 2 root root 4096 Oct 9 18:58 .

 

drwxrwxr-x. 3 root root 4096 Nov 29 2014 ..

 

-rwxrwxr-x. 1 root root  169Nov 29  2014 .htacces

 

[root@68-HTTPD upload]# mv .htaccess /vhosts/phpwind/

 

[root@68-HTTPD upload]#

 

关于文件权限即安全又简单的处理方法可以使用如下两条命令

[root@68-HTTPD vhosts]# chown -R apachephpwind

[root@68-HTTPD vhosts]# chmod -R go=phpwind

 

执行过程如下

[root@68-HTTPD vhosts]# ll

total 12

drwxr-xr-x. 2 root root 4096 Oct  9 16:59discuz

drwxr-xr-x. 14 root root 4096 Oct  9 20:42 phpwind

drwxr-xr-x. 2 root root 4096 Oct  9 16:59wordpress

[root@68-HTTPD vhosts]# chown -R apachephpwind

[root@68-HTTPD vhosts]# chmod -R go=  phpwind

[root@68-HTTPD vhosts]# ll phpwind

total 100

drwx------. 2 apache root 4096 Nov 29  2014aCloud

-rw-------. 1 apache root  306 Nov 29  2014 admin.php

drwx------. 2 apache root 4096 Nov 29  2014attachment

-rw-------. 1 apache root  451 Nov 29  2014 AUTHORS

drwx------. 4 apache root 4096 Nov 29  2014conf

-rw-------. 1 apache root  175 Nov 29  2014 crossdomain.xml

drwx------. 2 apache root 4096 Nov 29  2014 data

-rwx------. 1 apache root 1406 Nov 29  2014favicon.ico

drwx------. 2 apache root 4096 Nov 29  2014html

-rw-------. 1 apache root 1181 Nov 29  2014humans.txt

-rw-------. 1 apache root   92 Nov 29  2014 index.php

-rw-------. 1 apache root  105 Nov 29  2014 install.php

-rwx------. 1 apache root 3757 Nov 29  2014LICENSE

-rw-------. 1 apache root 2382 Nov 29  2014notify.php

drwx------. 2 apache root 4096 Nov 29  2014pay

-rw-------. 1 apache root   92 Nov 29  2014 read.php

drwx------. 5 apache root 4096 Nov 29  2014res

-rw-------. 1 apache root  215 Nov 29  2014 robots.txt

drwx------. 12 apache root 4096 Nov 29  2014 src

drwx------. 39 apache root 4096 Nov 29  2014 template

drwx------. 7 apache root 4096 Nov 29  2014themes

-rw-------. 1 apache root   26 Nov 29  2014 thumb.php

drwx------. 22 apache root 4096 Nov 29  2014 wind

drwx------. 5 apache root 4096 Nov 29  2014windid

-rw-------. 1 apache root  159 Nov 29  2014 windid.php

[root@68-HTTPD vhosts]#

 

3、discuz论坛安装过程详解

接下来我们继续在第二台虚拟主机(www.discuz.net)上安装discuz论坛

[root@68-HTTPD ~]# unzip Discuz_X3.2_SC_UTF8.zip -d discus

[root@68-HTTPD ~]# mv discuz/upload/* /vhosts/discuz/

[root@68-HTTPD vhosts]# cd discuz/con

config/     connect.php 

[root@68-HTTPD vhosts]# cd discuz/config

[root@68-HTTPD config]# ll

total 20

-rw-r--r--. 1 root root 8868 May 31 11:08config_global_default.php

-rw-r--r--. 1 root root 1663 May 31 11:08config_ucenter_default.php

-rw-r--r--. 1 root root    1 May 31 11:08 index.htm

[root@68-HTTPD config]# touchconfig_global.php config_ucenter.php

[root@68-HTTPD config]# ll

total 20

-rw-r--r--. 1 root root 8868 May 31 11:08 config_global_default.php

-rw-r--r--. 1 root root    0 Oct 10 00:04 config_global.php

-rw-r--r--. 1 root root 1663 May 31 11:08config_ucenter_default.php

-rw-r--r--. 1 root root    0 Oct 10 00:04 config_ucenter.php

-rw-r--r--. 1 root root    1 May 31 11:08 index.htm

[root@68-HTTPD config]#

 

 

推荐阅读