**
MYSQL安装
**
lamp架构安装
依赖包安装
yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* cmake curl curl-devel
mysql安装
groupadd mysql
useradd -g mysql mysql
cd /usr/local
tar zxvf mysql-advanced-5.6.23-linux-glibc2.5-x86_64.tar.gz
ln -s mysql-advanced-5.6.23-linux-glibc2.5-x86_64 mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql
cp my.cnf /etc/
vim /etc/my.cnf
-----------------------------------------------
[mysqld]
user = mysql
log-bin = mysql-bin
binlog-format = mixed
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
plugin-dir = /usr/local/mysql/lib/plugin
pid-file = /usr/local/mysql/data/mysql.pid
socket = /usr/local/mysql/data/mysql.sock
log-error = /usr/local/mysql/data/mysql.err
-----------------------------------------------
/etc/init.d/mysql start
vim /etc/profile #最后添加,以下全局变量
-------------------------------------------------------
export PATH=$PATH:/usr/local/mysql/bin
-------------------------------------------------------
source /etc/profile
登陆msyql
#mysql
ERROR2002(HY000):Can'tconnecttolocalMySQLserverthroughsocket'/tmp/mysql.sock'(2)
报以上错误解决
#cat/etc/my.cnf|grepsocket
socket = /usr/local/mysql/data/mysql.sock
# ln -s /usr/local/mysql/data/mysql.sock /tmp/
设置远程访问并设置mysql密码
# mysqladmin -uroot password mysql //这样可以设置密码,下面是同时设置密码允许远程
# mysql -uroot -pmysql
grant all privileges on *.* to root@"%" identified by "mysql" WITH grant option;
flush privileges;
apache安装
cd /usr/local
tar zxvf httpd-2.2.27.tar.gz
cd httpd-2.2.27
./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max
make
make install
手动更改,打开http的80端口,否则启动不了
vim /usr/local/apache/conf/httpd.conf
---------------------------------------------
#ServerName www.example.com:80
ServerName localhost:80
---------------------------------------------
或者用sed在命令行直接改
sed -i '/#ServerNamewww.example.com:80/a\ServerNamelocalhost:80' /usr/local/apache/conf/httpd.conf
/usr/local/apache/bin/apachectl -k start
firefox http://127.0.0.1/
php安装
cd /usr/local
tar jxvf php-5.5.10.tar.bz2
cd php-5.5.10
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config --with-curl --enable-zip --enable-bz2 --with-libXML-dir --enable-sockets --with-zilb-dir --enable-mbstring
make
make install
cp php.ini-production /usr/local/php/lib/php.ini
sed -i.bak 's/DirectoryIndex index.html/DirectoryIndex index.html index.php/g' /usr/local/apache/conf/httpd.conf
sed -i '/AddType application\/x-gzip .gz .tgz/a\AddType application\/x-httpd-php .php' /usr/local/apache/conf/httpd.conf
chcon -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
创建php页面
vim /usr/local/apache/htdocs/phpinfo.php
-------------------------------------------------
<?php
echo phpinfo();
?>
-------------------------------------------------
创建mysql与php连接测试页面
vim /usr/local/apache/htdocs/testdb.php
-------------------------------------------------
<html><body><h1>The page to test mysql local connection.</h1></body></html>
<?php
$conn=mysql_connect('localhost','root','mysql');
if ($conn)
echo "<h2>Success...</h2>";
else
echo "<h2>Failure...</h2>";
?>
-------------------------------------------------
chmod 755 /usr/local/apache/htdocs/phpinfo.php
chmod 755 /usr/local/apache/htdocs/testdb.php
service mysql restart
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl -k start
firefox http://127.0.0.1/phpinfo.php
firefox http://127.0.0.1/testdb.php
安装phpmyadmin管理工具
cd /usr/local/
tar zxvf phpMyAdmin-3.5.0-all-languages.tar.gz
cp -a phpMyAdmin-3.5.0-all-languages /usr/local/apache/htdocs/phpmyadmin
cd /usr/local/apache/htdocs/phpmyadmin
cp config.sample.inc.php config.inc.php
vim config.inc.php
-------------------------------------------------------------------------
将auth_type改为http
-------------------------------------------------------------------------
firefox http://127.0.0.1/phpmyadmin/index.php
最后把所有都加入开机启动
echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.local
grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd
vim /etc/init.d/httpd //最上面加以下三条
-------------------------
#!/bin/sh
# chkconfig: 2345 85 15
# description: Apache is a World Wide Webserver.
-------------------------
chmod +x /etc/init.d/mysql
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig --list httpd
service httpd restart
chkconfig httpd on
chkconfig mysql on
如果出现以下错误
解决方法为php安装mcrypt扩展
确认你的linux没有安装mcrypt库,如果已安装,跳过安装步骤
# yum list installed | grep mcrypt
以上显示已经安装过,若没有,则按以下两种方式安装
方法一:yum命令懒人安装
----------------------------------------------------------------------------------------
# yum install libmcrypt libmcrypt-devel mcrypt mhash
方法二:源码编译安装
----------------------------------------------------------------------------------------
1.去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包
libmcrypt (libmcrypt-2.5.8.tar.gz )
mcrypt (mcrypt-2.6.8.tar.gz )
mhash (mhash-0.9.9.9.tar.gz )
2.安装libmcrypt
cd /usr/local/
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
3.安装mhash
cd ..
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
4.安装mcrypt
cd ..
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure
make
make install
5.安装php的mcrypt扩展(动态加载编译)
cd /usr/local/php-5.5.10/ext/mcrypt/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
ll /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/
echo 'extension=mcrypt.so' >> /usr/local/php/lib/php.ini
/etc/init.d/httpd restart
6.查看是否成功
http:/127.0.0.1/phpinfo.php
PHP安装GD库
1.安装libpng
cd /usr/local/
tar zxvf libpng-1.2.40.tar.gz
cd libpng-1.2.40
mv scripts/makefile.linux ./Makefile
./configure
make
make install
2.安装freetype
cd ..
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype
make
make install
3.安装php的mcrypt扩展(动态加载编译)
cd /usr/local/php-5.5.10/ext/gd/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
echo 'extension=gd2.so' >> /usr/local/php/lib/php.ini
/etc/init.d/httpd restart