Rumah >pangkalan data >tutorial mysql >mysql数据库,apacha服务器,php服务器的搭建_MySQL

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

WBOY
WBOYasal
2016-06-01 13:10:291006semak imbas

博客

一、安装mysql:

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

[root@www ~]# groupadd -r mysql

[root@www ~]# useradd -g mysql -r -s /sbin/nologin 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

[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

[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 ./*

[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

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

datadir = /data/mydata


[root@www mysql]# service mysqld start

Starting MySQL...                                          [  OK  ]


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

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

Welcome to the MySQL monitor.  Commands end with ; or


[root@www ~]# vim .my.cnf

[mysql]

user=root

host=localhost

password=love

~            

[root@www ~]# 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

--enable-rewrite

--with-apr=/usr/local/apr

--with-apr-util=/usr/local/apr-util/

--enable-mpms-shared=all

--with-mpm=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

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"


[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行左右修改成如下

   DirectoryIndex index.php index.html



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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn