服务器php、mysql、apache环境搭建

来源:互联网 发布:城市电话区号查询软件 编辑:程序博客网 时间:2024/04/30 10:35

最近给公司搭建服务器,算是很杂的事情,还是记录一下吧

给装的是ubuntu server,装的时候也遇到了一点问题,开始准备装debian后来发现网卡不支持,为了省事还是换成了ubuntu server。装上后发现进不去系统,grub坏了

,无奈只好用ubuntu的安装光碟使用使用ubuntu的方法进去。到boot/grub目录下,将sda中放内核和boot目录的分区mount上

grub-install --boot-directory=/mnt/boot   /dev/sda

相信看了就知道什么意思了,这样安装成功后,再启动系统就可以进去。

下面就是搭建web环境

主要软件包:

httpd-2.2.17.tar.gz

mysql-5.5.10.tar.gz

php-5.3.5.tar.gz

安装php需要的软件包:

libxml2-2.6.11.tar.gz         http://ftp.gnome.org/pub/GNOME/sources/libxm2

curl-7.14.0.tar.gz               http://curl.haxx.se/download

GD库所需要软件包(有人说PHP源码包里自带了GD2.0.28和zlib,只要安装GD的三个支持包:jpg,png和freetype,但是我们还是下载) 

gd-2.0.35.tar.gz            http://www.libgd.org/Main_Page or http://www.libgd.org/releases/ 

freetype-2.4.4.tar.bz2    http://sourceforge.net/projects/freetype

jpegsrc.v8c.tar.gz          http://ijg.org/files/

libpng-1.5.1.tar.gz          http://www.libpng.org/pub/png/libpng.html

zlib-1.2.5.tar.gz                http://www.zlib.net

请下载以上软件

1、安装mysql

查看BUILD-CMAKE得知
先sudo apt-get install cmake

#mkdir -p /usr/local/mysql

#cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/
会出现以下错误:
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:126 (FIND_CURSES)
  cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT)
  CMakeLists.txt:250 (MYSQL_CHECK_READLINE)
解决办法:
可能是缺少libncurses5-dev包
我们安装ncurses包
http://ftp.gnu.org/pub/gnu/ncurses/
下载ncurses
我们下载最新的ncurses-5.8.tar.gz
#mkdir -p /usr/local/ncurses-5.8
#./configure --prefix=/usr/local/ncurses-5.8/
会发生如下错误
-- The CXX compiler identification is unknown
CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
看错误好像是没有安装g++
#aptitude install g++
#make

出现如下错误:

/home/huguohu/ProgramFile/mysql-5.5.10/sql/mysqld.cc: In function ‘void handle_connections_sockets()’:
/home/huguohu/ProgramFile/mysql-5.5.10/sql/mysqld.cc:5180: error: invalid conversion from ‘size_socket*’ to ‘socklen_t*’
/home/huguohu/ProgramFile/mysql-5.5.10/sql/mysqld.cc:5180: error: initializing argument 3 of ‘int accept(int, sockaddr*, socklen_t*)’
/home/huguohu/ProgramFile/mysql-5.5.10/sql/mysqld.cc:5247: error: invalid conversion from ‘int*’ to ‘socklen_t*’
/home/huguohu/ProgramFile/mysql-5.5.10/sql/mysqld.cc:5247: error: initializing argument 3 of ‘int getsockname(int, sockaddr*, socklen_t*)’
make[2]: *** [sql/CMakeFiles/sql.dir/mysqld.cc.o] 错误 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] 错误 2
make: *** [all] 错误 2
这个是gcc的版本问题,还没解决
使用apt-get mysql-server后然后remove掉mysql-server
然后重新解压安装,上述错误没有,原因还没找到

#make install

# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &

#./mysqld_safe &
查看mysql服务有没有启动
#ps -A | grep mysql
如果看到mysql的输出
#./mysqladmin -u root password 'xxxxxx'
#./mysql -u root -pxxxxxx

启动mysql即#./mysqld_safe &的时候会出现:

110322 09:40:33 mysqld_safe Logging to '/var/lib/mysql/loongson.err'.
110322 09:40:33 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
110322 09:40:33 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
查看loongson.err,记录错误如下:
Can't find messagefile '/usr/share/mysql/english/ errmsg.sys'
287 ^G/usr/local/mysql/bin/mysqld: File './mysql-bin.index' not found
这个问题,找网上的说法
An old style --language value with language specific part detected: /usr/local/mysql/share/english/

发现真正的原因在:
在/etc/mysql/my.cnf中
basedir = /usr
datadir = /var/lib/mysql
这两个配置上
因为这两个配置是错误的,应配置如下:
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
然后启动就没有问题。
但是估计上面那个语言配置也是正确,但basedir和data

经过以上的折腾后,mysql基本安装好了

以下是其他软件的过程,是抄下来的,具体的软件版本不同,方法都是一样的,以下瑾供参考

a.安装 jpeg8建立目录: 
# mkdir -p /usr/local/jpeg8
# mkdir -p /usr/local/jpeg8/bin 
# mkdir -p /usr/local/jpeg8/lib 
# mkdir -p /usr/local/jpeg8/include 
# mkdir -p /usr/local/jpeg8/man 
# mkdir -p /usr/local/jpeg8/man1 
# mkdir -p /usr/local/jpeg8/man/man1 
# cd /root/Software/ 
# tar -zvxf jpegsrc.v8b.tar.gz 
# cd jpeg8 
# ./configure --prefix=/usr/local/jpeg8/ --enable-shared --enable-static 
# make
# make install 

b.libpng包(支持PNG)
# cd /root/Software/ 
# tar -zvxf libpng-(version).tar.gz
# cd libpng-(version)
# ./configure --prefix=/usr/local/libpng
# make
#> make install

会出现

gd_png.c:16:54: png.h: No such file or directory
解决办法
通过查找发现png在/usr/local/libpng/include/png.h
vim gd_png.c +16
将#include "png.h"
改为#include "/usr/local/libpng/include/png.h"
make即可


c.安装 freetype 
# cd /root/Software/ 
# tar -zvxf freetype-(version).tar.gz 
# cd freetype-(version) 
# mkdir -p /usr/local/freetype 
# ./configure --prefix=/usr/local/freetype 
# make
# make install 

d.安装zlib 
# cd /root/Software/ 
# tar -zxvf zlib-1.2.3.tar.gz 
# cd zlib.1.2.3
# mkdir /usr/local/zlib 
# ./configure --prefix=/usr/local/zlib
# make
# make install 

e.安装GD库 
# cd /root/Software/ 
# tar -zvxf gd-(version).tar.gz 
# mkdir -p /usr/local/gd2 
# cd gd-(version) 
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-zlib-dir=/usr/local/zlib --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype 
# make
# make install 

e.安装Curl库 
# cd /root/Software/ 
# tar -zxf curl-(version).tar.gz 
# mkdir -p /usr/local/curl 
# ./configure --prefix=/usr/local/curl 
# make
# make install 

四:安装apache2
# cd /roo/Software/ 
# tar -zvxf httpd-2.2.6.tar.gz 
# cd httpd-2.2.6 
# mkdir -p /usr/local/apache2 
# ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite 
# make
# make install 
# /usr/local/apache2/bin/apachectl -k start //启动apahce
用浏览器查看http://localhost,得到it works,说明apache已经配置成功了.
# /usr/local/apache2/bin/apachectl -k stop //停止apache 


安装php5

a. 安装libxml2 
# cd /root/Software/ 
# tar -zvxf libxml2-(version).tar.gz 
# cd libxml2-(version)
# mkdir -p /usr/local/libxml2 
# ./configure --prefix=/usr/local/libxml2 
# make
# make install 


elfgcchack.h:60: error: '__xmlGenericError' aliased to undefined symbol '__xmlGenericError__internal_alias'
elfgcchack.h:64: error: '__xmlGenericErrorContext' aliased to undefined symbol '__xmlGenericErrorContext__internal_alias'
elfgcchack.h:70: error: 'docbCreatePushParserCtxt' aliased to undefined symbol 'docbCreatePushParserCtxt__internal_alias'
elfgcchack.h:75: error: 'htmlAttrAllowed' aliased to undefined symbol 'htmlAttrAllowed__internal_alias'
……
解决办法
在elfgcchack.h里开头处:
* autogenerated with xsltproc doc/elfgcchack.xsl doc/libxml2-api.xml
*/
加上:
#ifdef IN_LIBXML
#ifdef __GNUC__
#ifdef PIC
#ifdef linux
#if (__GNUC__ == 3 && __GNUC_MINOR__ == 3)
并在文件最后加上:
#endif
#endif
#endif
#endif
#endif

然后重新make,
会出现如下错误:
call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
找到对应文件中open的地方加上一个参数:0666,然后编译成功。

安装php5

# cd /root/Software/ 
# tar -zvxf php-(version).tar.gz 
# mkdir -p /usr/local/php5 
# cd php-(version)

./configure --prefix=/usr/local/php5/ --with-apxs2=/usr/local/apache2/bin/apxs --with-gd=/usr/local/gd2/ --with-jpeg-dir=/usr/local/jpeg8/ --with-zlib-dir=/usr/local/zlib/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --enable-trace-vars --with-mysql=/usr/local/mysql --enable-mbstring=all --with-curl=/usr/local/curl/ --enable-mbregex --with-config-file-path=/usr/local/php5/ --enable-ftp --enable-soap --with-libxml-dir=/usr/local/libxml2/

# cp php.ini-dist /usr/local/php5/php.ini (别忘记了呵呵)


重新配置apache2让他支持php
# cd /usr/local/apache2/conf
# vim httpd.conf
在LoadModule php5_module modules/libphp5.so
添加AddType application/x-httpd-php .php

重新起动APACHE:
# /usr/local/apache2/bin/apachectl start

 

apache启动的时候会出现如下提示:
httpd: Could not reliably determine the server's
httpd: Could not reliably determine the server's fully qualified domain name
apache,重新启动后,回出现上面的错误,只要把/conf/httpd.conf文件的#ServerName 前的#去掉就好了。

连接上mysql后登录phpadmin的时候,登录数据库的时候总是出现
2002 – 服务器没有响应 (或者本地 MySQL 服务器的套接字没有正确配置)
网上查的如下:
要将 config.inc.php 中
$cfg['Servers'][$i]['host'] = ’localhost’;
改成 $cfg['Servers'][$i]['host'] = ’127.0.0.1′;
可是查phpmyadmin3下面却是:config.sample.inc.php
mv config.sample.inc.php config.inc.php
然后按照上面的方法就可以登陆phpadmin


然后安装Discuz

安装Discuz的时候出现
解决Can't connect to local MySQL server through socket '/tmp/mysql.sock'
是因为mysql的sock在mysql的my.cnf中可以看到sock为/var/run/mysqld/mysqld.sock
而系统默认会去找/tmp/mysql.sock找,于是做个链接
ln -s /var/run/mysqld/mysqld.sock   /tmp/mysql.sock

apache中htdocs目录下文件网页显示中文乱码
修改conf中httpd.conf添加
indexOptions Charset=UTF-8

经过以上折腾基本可以用了,以后再记吧!


后来又安装了一个ZenTao的项目管理软件,其中也会碰到一些问题,查网络。

install的时候安装数据的时候总是安补上

今天在redhat的lnmp环境下安装试用,安装过程中报错:

1
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2030 This command is not supported in the prepared statement protocol yet' in /usr/local/apache2/htdocs/zentaopms/module/install/model.php:195 Stack trace: #0 /usr/local/apache2/htdocs/zentaopms/module/install/model.php(195): PDO->query('CREATE DATABASE...') #1 /usr/local/apache2/htdocs/zentaopms/module/install/model.php(128): installModel->createDB('5.0') #2 /usr/local/apache2/htdocs/zentaopms/module/install/control.php(82): installModel->checkConfig() #3 [internal function]: install->step3() #4 /usr/local/apache2/htdocs/zentaopms/framework/router.class.php(1069): call_user_func_array(Array, Array) #5 /usr/local/apache2/htdocs/zentaopms/www/install.php(63): router->loadModule() #6 {main} thrown in /usr/local/apache2/htdocs/zentaopms/module/install/model.php on line 195

解决办法是修改module/install/model.php,找到 public function connectDB() 函数,在

1
2
3
$dbh = new PDO($dsn, $this->config->db->user, $this->config->db->password);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

后加入

1
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);

在www/install.php中同样添加

在以下后面

if(isset($config->installed) and $config->installed) $dbh = $app->connectDB();

添加:

if(isset($config->installed) and $config->installed) $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);

重启apache就可以通过了

修改Discuz

 在原来的discuz X1版本中,标题中去掉“Powered by Discuz!”版权标识很容易,只需要修改模板文件的头部公用文件,将['bbname'] - <!--{/if}--> Powered by Discuz!</title> 中红色部分去掉即可。
但是discuz X1.5直接把- Powered by Discuz!中的 - 放在了变量里,所以删除后,title 标题一句话结束后会有一个小 - 尾巴,对搜索引擎很不友好,找了好久,终于发现了一个完美的方法。
也有一个好的办法完美解决,即:
打开\template\default\common \header_common.htm文件,
找到<title><!--{if !empty($navtitle)}-->$navtitle - <!--{/if}--><!--{if empty
($nobbname)}--> $_G['setting']['bbname'] - <!--{/if}--> Powered by Discuz!</title>
将其中的“Powered By Discuz!” (红色的文字部分)字串改为“{lang secondtitle}”。

然后再打开 source/language/lang_template.php。
在变量的最后,也就是整个数组的目录后按以前的格式,加上引号内的内容”  'secondtitle' => '网站或论坛名称',“。
更新缓存即可。


原创粉丝点击