专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
使用技巧
当前位置:首页 > 技术文档 > 使用技巧 >  > 
Linux Apache php mysql 安装详细

       LAMP服务安装配置

一 安装mysql5.1.38

升级软件包

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

以得到软件支持。

 

安装php支持软件

libiconv-1.13.1 \\ libiconv库为需要做转换的应用提供了一个iconv()的函数

tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local    \\安装路径
make
make install

 

tar zxvf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig  为了让动态链接库为系统所共享
cd libltdl/
./configure --enable-ltdl-install
make
make install

 

tar zxvf mhash-0.9.9.9.tar.gz  \\php的扩展块
cd mhash-0.9.9.9/
./configure
make
make install

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

 

tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install

 

安装mysql 5.1.38数据库

tar zxvf mysql-5.1.38.tar.gz

进入解压缩目录mysql-5.1.38

./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg

 

make && make install

 

chmod +w /usr/local/webserver/mysql   \\给目录写权限
chown -R mysql:mysql /usr/local/webserver/mysql  \\ 修改该目录文件属主为mysql R为递归方式

创建MySQL数据库存放目录

mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql:mysql /data0/mysql/

 

mysql用户帐号的身份建立数据表

Useradd g mysql mysql 

Groupadd mysql

/usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/data0/mysql/3306/data --user=mysql

创建my.cnf配置文件:

vi /data0/mysql/3306/my.cnf

添加如下内容

 

[client]
character-set-server = utf8
port    = 3306
socket  = /tmp/mysql.sock

[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user    = mysql
port    = 3306
socket  = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit    = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

interactive_timeout = 120
wait_timeout = 120

skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

#master-host     =   192.168.1.2
#master-user     =   username
#master-password =   password
#master-port     =  3306

server-id = 1

innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0

#log-slow-queries = /data0/mysql/3306/slow.log
#long_query_time = 10

[mysqldump]
quick
max_allowed_packet = 32M

 

创建管理MySQL数据库的shell脚本:

vi /data0/mysql/3306/mysql

 

 输入以下内容(这里的用户名admin和密码12345678接下来的步骤会创建):

#!/bin/sh

mysql_port=3306
mysql_username="admin"
mysql_password="12345678"

function_start_mysql()
{
    printf "Starting MySQL...\n"
    /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}

function_stop_mysql()
{
    printf "Stoping MySQL...\n"
    /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown
}

function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    sleep 5
    function_start_mysql
}

function_kill_mysql()
{
    kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
    kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
}

if [ "$1" = "start" ]; then
    function_start_mysql
elif [ "$1" = "stop" ]; then
    function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
    printf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"
fi

 、赋予shell脚本可执行权限:

chmod +x /data0/mysql/3306/mysql

/data0/mysql/3306/mysql start  \\启动数据库

root进入数据库

/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock

输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';

 

二 安装apache2.2.17

解压缩

tar jxvf httpd-2.2.17.tar.bz2

进入该目录

依次安装aprapr-util

# cd srclib  //apr是支持apache跨平台
# ./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static
# make && make install

cd ../apr-util

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ --with-mysql=/usr/local/webserver/mysql

make && make install

安装apache2.2.17

./configure --prefix=/usr/local/apache2 

"--enable-so" \

"--enable-deflate=shared" \

"--enable-expires=shared" \

"--enable-rewrite=shared" \

"--enable-static-support" \

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

 

Make

Make install

 

三 安装php5.2.14

解压缩php-5.2.14.tar.gz

进入该目录

 编译文件

./configure "--prefix=/usr/local/webserver/php" "--with-apxs2=/usr/local/apache2/bin/apxs" "--with-config-file-path=/usr/local/webserver/php/etc" "--with-mysql=/usr/local/webserver/mysql" "--with-mysqli=/usr/local/webserver/mysql/bin/mysql_config" "--with-iconv-dir=/usr/local" "--with-freetype-dir" "--with-jpeg-dir" "--with-png-dir" "--with-bz2" "--with-zlib" "--with-libxml-dir=/usr" "--with-openssl-dir" "--with-curl" "--with-curlwrappers" "--with-mcrypt" "--with-gd" "--with-openssl" "--with-mhash" "--with-ldap" "--with-ldap-sasl" "--with-xmlrpc" "--enable-xml" "--enable-safe-mode" "--enable-bcmath" "--enable-shmop" "--enable-exif" "--enable-sysvsem" "--enable-inline-optimization" "--enable-ftp" "--enable-gd-native-ttf" "--enable-pcntl" "--enable-sockets" "--enable-zip" "--enable-mbregex" "--enable-mbstring" "--enable-soap" "--disable-ipv6" "--disable-cgi" "--disable-cli" "--disable-rpath"

 

make ZEND_EXTRA_LIBS='-liconv' 加载 该扩展模块

make install 安装

四 apache php整合

从安装目录php-5.2.14

cp php.ini-dist /usr/local/lib/php.ini

编辑该文件/usr/local/lib/php.ini

 

register_globals = Off改为register_globals = On

 

#vi /usr/local/httpd/httpd.conf 些模块简单的修改

 

在配置文件中添加如下:
AddType application/x-httpd-php .php .php3 .php4 .php5 支持php模块

 

查找:(设置 WEB 默认文件)
DirectoryIndex index.html index.php