mysql数据库,apacha服务器,php服务器的搭建

博客

一、安装mysql:

准备压缩包:mysql-5.5.33-linux2.6-x86_64.tar.gz

[root@www ~]# groupadd -r mysql<=========================新建一个mysql组,因为mysql的运行是要靠mysql用户的

[root@www ~]# useradd -g mysql -r -s /sbin/nologin mysql<==========新建mysql用户

[root@www ~]# id mysql<==================================确认一下是否建好了

uid=496(mysql) gid=493(mysql) groups=493(mysql)

[root@www ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  mysql-5.5.33-linux2.6-x86_64.tar.gz

[root@www ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local<======将压缩包解压

[root@www ~]# cd /usr/local<===========================切换到此目录下,查看一下生成的文件

[root@www local]# ls

bin  etc  games  include  lib  lib64  libexec  mysql-5.5.33-linux2.6-x86_64  sbin  share  src

[root@www local]# ln -sv mysql-5.5.33-linux2.6-x86_64/ mysql<=======为文件建立一个链接,                                                                        以后使用时更方便

`mysql‘ -> `mysql-5.5.33-linux2.6-x86_64/‘

[root@www local]# mkdir /data<=======================新建data目录,为下面设备挂载时使用

[root@www local]# fdisk /dev/sda<========================新建一个分区

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to

        switch off the mode (command ‘c‘) and change display units to

        sectors (command ‘u‘).


Command (m for help): n

Command action

  e   extended

  p   primary partition (1-4)

p

Partition number (1-4): 3

First cylinder (7859-15665, default 7859):

Using default value 7859

Last cylinder, +cylinders or +size{K,M,G} (7859-15665, default 15665): +20G


Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): 8e

Changed system type of partition 3 to 8e (Linux LVM)


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@www local]# cat /proc/partitions<=======查看一下分区状况,如果新建的分区没有显示出                                                                           来,就重启一下

major minor  #blocks  name


  8        0  125829120 sda

  8        1     204800 sda1

  8        2   62914560 sda2

  8        3   20979891 sda3<==================这是新建的分区

253        0   20971520 dm-0

253        1    2097152 dm-1

253        2   10485760 dm-2

253        3   20971520 dm-3

[root@www local]# pvcreate /dev/sda3

 Physical volume "/dev/sda3" successfully created

 [root@www local]# vgcreate myvg /dev/sda3

 Volume group "myvg" successfully created

[root@www local]# lvcreate -L 10G -n mydata myvg

 Logical volume "mydata" created

[root@www local]# lvs<===============查看一下新建的卷组信息

 LV     VG   Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert

 mydata myvg -wi-a---- 10.00g                                            

 root   vg0  -wi-ao--- 20.00g                                            

 swap   vg0  -wi-ao---  2.00g                                            

 usr    vg0  -wi-ao--- 10.00g                                            

 var    vg0  -wi-ao--- 20.00g      

 [root@www local]# mke2fs -t ext4 /dev/myvg/mydata<===========格式化卷组



[root@www local]# vim /etc/fstab<=================开机挂载

 # Created by anaconda on Sat Mar 22 10:51:06 2014

#

# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/vg0-root    /                       ext4    defaults        1 1

UUID=21013d46-de12-479a-beed-1a04aa11033d /boot                   ext4    defaults        1 2

/dev/mapper/vg0-usr     /usr                    ext4    defaults        1 2

/dev/mapper/vg0-var     /var                    ext4    defaults        1 2

/dev/mapper/vg0-swap    swap                    swap    defaults        0 0

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

/dev/myvg/mydata       /data                    ext4    defaults        0 0<==这是要挂载的卷组

~                                                                            

[root@www local]# mount -a<=============重载一下,把卷组挂载上来


[root@www local]# mount<=====================查看一下挂载的卷组信息

/dev/mapper/vg0-root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

/dev/mapper/vg0-usr on /usr type ext4 (rw)

/dev/mapper/vg0-var on /var type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/dev/mapper/myvg-mydata on /data type ext4 (rw) <=========这里就是新挂载的卷组信息      


[root@www local]# cd /data

[root@www data]# mkdir mydata<======================新建mydata目录

[root@www data]# chown -R mysql.mysql mydata/<======修改目录的属主属组

[root@www data]# ll<================================确认一下修改的信息

total 20

drwx------ 2 root  root  16384 Mar 22 12:01 lost+found

drwxr-xr-x 2 mysql mysql  4096 Mar 22 12:06 mydata

[root@www data]# cd /usr/local/mysql

[root@www mysql]# chown -R root.mysql ./*<===========修改mysql文件的属主及属组

[root@www mysql]# ll<================================确认更改成功

total 200

drwxr-xr-x  2 root mysql   4096 Mar 22 11:54 bin

-rw-r--r--  1 root mysql  17987 Jul 15  2013 COPYING

drwxr-xr-x  3 root mysql   4096 Mar 22 11:54 data

drwxr-xr-x  2 root mysql   4096 Mar 22 11:54 docs

drwxr-xr-x  3 root mysql   4096 Mar 22 11:54 include

-rw-r--r--  1 root mysql 134493 Jul 15  2013 INSTALL-BINARY

drwxr-xr-x  3 root mysql   4096 Mar 22 11:54 lib

drwxr-xr-x  4 root mysql   4096 Mar 22 11:54 man

drwxr-xr-x 10 root mysql   4096 Mar 22 11:54 mysql-test

-rw-r--r--  1 root mysql   2496 Jul 15  2013 README

drwxr-xr-x  2 root mysql   4096 Mar 22 11:54 scripts

drwxr-xr-x 27 root mysql   4096 Mar 22 11:54 share

drwxr-xr-x  4 root mysql   4096 Mar 22 11:54 sql-bench

drwxr-xr-x  3 root mysql   4096 Mar 22 11:54 support-files

[root@www mysql]# scripts/mysql_install_db --datadir=/data/mydata --user=mysql<==安装并初始化mysql,这是安装之前很重要的一步

Installing MySQL system tables...

OK

Filling help tables...

OK

[root@www mysql]# ls /data/mydata

mysql  performance_schema  test

[root@www mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld<=====提供服务脚本

[root@www mysql]# chkconfig --add mysqld<==========================开机自动启动此进程

[root@www mysql]# chkconfig --list mysqld

mysqld         0:off1:off2:on3:on4:on5:on6:off

[root@www mysql]# cp support-files/my-large.cnf /etc/my.cnf<===========提供配置文件,注意这里是把原先的文件覆盖了

cp: overwrite `/etc/my.cnf‘? y

[root@www mysql]# vim /etc/my.cnf<=============编辑配置文件

# The MySQL server

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

# Try number of CPU‘s*2 for thread_concurrency

thread_concurrency 4<====================================大概在40行左右,这里更改一下

datadir = /data/mydata<==================================要加下此信息,指定mysql的目录


[root@www mysql]# service mysqld start<============================启动mysql验证一下是否能够正常启动

Starting MySQL...                                          [  OK  ]


[root@www mysql]# vim /etc/profile.d/mysql.sh<============为mysql导入命令文件

export PATH=/usr/local/mysql/bin:$PATH

~                                        

[root@www mysql]# cd

[root@www ~]# . /etc/profile.d/mysql.sh<================让系统执行一下刚才建立的文件

现在mysql就可能运行起来了,我们进入mysql看一下吧,看看还有什么要设置的

[root@www ~]# mysql

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

Your MySQL connection id is 1

Server version: 5.5.33-log MySQL Community Server (GPL)


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


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 input statement.


mysql>


mysql> use mysql<===============================新建一个用户表

Database changed

mysql> SELECT user,host,password from user;<=====================

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

| user | host          | password |

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

| root | localhost     |          |

| root | www.jiayu.com |          |

| root | 127.0.0.1     |          |

| root | ::1           |          |

|      | localhost     |          |

|      | www.jiayu.com |          |

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

6 rows in set (0.01 sec)


mysql> DROP USER ‘‘@‘www.jiayu.com‘ ;<==============================

Query OK, 0 rows affected (0.00 sec)


mysql> DROP USER ‘‘@‘localhost‘;<=================================

Query OK, 0 rows affected (0.00 sec)

mysql> UPDATE user SET password=PASSWORD(‘love‘) WHERE user=‘root‘;<============创建密码

Query OK, 4 rows affected (0.02 sec)

Rows matched: 4  Changed: 4  Warnings: 0


mysql> SELECT user,host,password from user;<=========================查看密码是否生成

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

| user | host          | password                                  |

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

| root | localhost     | *656B19382E8A16676406422882380722D756E17A |

| root | www.jiayu.com | *656B19382E8A16676406422882380722D756E17A |

| root | 127.0.0.1     | *656B19382E8A16676406422882380722D756E17A |

| root | ::1           | *656B19382E8A16676406422882380722D756E17A |

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

4 rows in set (0.00 sec)

mysql> FLUSH PRIVILEGES;《===========================================

Query OK, 0 rows affected (0.00 sec)


[root@www ~]# mysql -uroot -hlocalhost -plove <==========密码创建之后,要这样才能进入mysql

Welcome to the MySQL monitor.  Commands end with ; or


[root@www ~]# vim .my.cnf<============如果上面进入系统太麻烦了,那就他建一个隐藏文件吧,把密码保存到里面

[mysql]

user=root

host=localhost

password=love

~            

[root@www ~]# mysql<========================================再进入mysql就不用输密码了

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

Your MySQL connection id is 3



[root@www ~]# ln -sv /usr/local/mysql/include/ /usr/include/mysql<<===================导出头文件

`/usr/include/mysql‘ -> `/usr/local/mysql/include/‘

[root@www ~]# vim /etc/ld.so.conf.d/mysql.conf<===================================导出库文件

/usr/local/mysql/lib


[root@www ~]# ldconfig

[root@www ~]# ldconfig -p | grep mysql

libtcmalloc_minimal.so.0 (libc6,x86-64) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0

libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r.so.16

libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18<====关键要看到这一项

libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.16

libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so






二、安装httpd:      httpd的安装要依靠apr和apr-util所以安装之前必须先安装这两个文件。

httpd-2.4.9.tar.bz2

apr-1.5.0.tar.bz2

apr-util-1.5.3.tar.bz2


[root@www ~]# yum install pcre-devel -y

[root@www ~]# tar xf apr-1.5.0.tar.bz2

[root@www ~]# cd apr-1.5.0

[root@www apr-1.5.0]# ./configure --prefix=/usr/local/apr

[root@www apr-1.5.0]# make && make install


[root@www ~]# tar xf apr-util-1.5.3.tar.bz2

[root@www ~]# cd apr-util-1.5.3

[root@www apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

[root@www apr-1.5.0]# make && make install

[root@www httpd-2.4.9]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --with-zlib --with-pcre --enable-rewrite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event

[root@www httpd-2.4.9]make && make install



--prefix=/usr/local/apache<===========指定安装路径

--sysconfdir=/etc/httpd24<============配置文件的存放位置

--enable-so --enable-ssl --enable-cgi <====开启so,ssl,cgi功能

--enable-rewrite<======================开启字体设置功能

--with-apr=/usr/local/apr<=============安装时到哪去找apr

--with-apr-util=/usr/local/apr-util/<==安装时到哪去找apr-util

--enable-mpms-shared=all <=========编辑mpms功能

--with-mpm=event<==================指定php用event模式



[root@www httpd-2.4.9]# cd /etc/rc.d/init.d

[root@www init.d]# cp httpd httpd24


[root@www init.d]# vim httpd24


# Path to the apachectl script, server binary, and short-form for messages.

apachectl=/usr/local/apache/bin/apachectl<====在约在40行左右,把原来的路径改成这样

httpd=${HTTPD-/usr/local/apache/bin/httpd}<===指定新的路径



[root@www init.d]# chkconfig --add httpd24

[root@www init.d]# chkconfig --list httpd24

httpd24        0:off1:off2:off3:off4:off5:off6:off


[root@www ~]# vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH


[root@www ~]# . /etc/profile.d/httpd.sh


[root@www ~]# vim /etc/httpd24/httpd.conf

# Do not add a slash at the end of the directory path.  If you point

# ServerRoot at a non-local disk, be sure to specify a local disk on the

# Mutex directive, if file-based mutexes are used.  If you wish to share the

# same ServerRoot for multiple httpd daemons, you will need to change at

# least PidFile.

#

ServerRoot "/usr/local/apache"

pidFile "var/run/httpd/httpd.conf"<=====大约40行左右,把这个pidFile加上


[root@www ~]# service httpd24 start

Starting httpd:                                            [  OK  ]



安装php服务器

要准备的文件

php-5.4.26.tar.bz2

xcache-3.0.3.tar.bz2

phpMyAdmin-4.0.5-all-languages.zip



[root@www ~]# tar xf php-5.4.26.tar.bz2

[root@www ~]# cd php-5.4.26

[root@www php-5.4.26]#./configure --prefix=/usr/local/php

--with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm  --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl

[root@www php-5.4.26]# make && make install

[root@www php-5.4.26]# cp php.ini-production /etc/php.ini

编辑配置文件

[root@www php-5.4.26]# vim /etc/httpd24/httpd.conf

  在382行左右AddType下面如下两行

AddType application/x-httpd-php .php


AddType application/x-httpd-php-source .phps


在252行左右修改成如下

<IfModule dir_module>

   DirectoryIndex index.php index.html

</IfModule>



root@www ~]# service httpd24 reload

Reloading httpd:

[root@www ~]# ss -tnlp


   

下面是测试php是不是工作正常了

[root@www ~]# cd /usr/local/apache

[root@www apache]# ls

bin  build  cgi-bin  error  htdocs  icons  include  logs  man  manual  modules

[root@www apache]# cd htdocs

[root@www htdocs]# ls

index.html

[root@www htdocs]# mv index.html index.php

[root@www htdocs]# ls

index.php

[root@www htdocs]# vim index.php

<? php


    phpinfo();

?>

~   在浏览器里打开你的服务器地址,看看是否运行正常了




本文出自 “linux” 博客,请务必保留此出处http://8519539.blog.51cto.com/8509539/1386687

mysql数据库,apacha服务器,php服务器的搭建,布布扣,bubuko.com

mysql数据库,apacha服务器,php服务器的搭建

上一篇:mysql的事务运作


下一篇:SQL语句引发的思考