CentOS 5.9裸机编译安装搭建LAMP
Posted Joynic
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 5.9裸机编译安装搭建LAMP相关的知识,希望对你有一定的参考价值。
Linux系统:CentOS 5.9,查看CentOS版本,命令如下:
[[email protected] /]# cat /etc/redhat-release CentOS release 5.9 (Final)
以前装过mysql和php的机器,最好是先查看一下MySQL或者PHP是否未卸载:
[[email protected] /]# rpm -qa|grep mysql [[email protected] /]#
↑ 结果表明MySQL未安装或者已经被卸载,如果已安装,则可以选择保留或者卸载,卸载命令:yum remove mysql
[[email protected] /]# rpm -qa|grep php [[email protected] /]#
↑结果表明PHP未安装或者已经被卸载
Apache同上述……
到SourceForge(http://sourceforge.net/ 强大的SF,下载很方便,顶一个!)下载安装包,Apache搜索“Apache HTTP Server”、MySQL直接搜索“MySQL”,phpMyAdmin搜索“phpMyAdmin”至于PHP嘛,还是建议去php.net下载,:)
下载完成传到Linux服务器上……也可以直接在服务器上用wget命令下载,可是找链接地址还得搜索,费劲,不如直接去下来得方便。。。个人意见,勿喷,,
开始安装:
解压各个包到 /usr/src 目录下:
tar zxvf [文件名.tar.gz] -C /usr/src (C必须大写,否则报错!)
例如,解压php:
[[email protected] home]# tar zxvf php-xxxx.tar.gz -C /usr/src
其他包相同……
一.安装MySQL
1.程序安装
MySQL 5.5.x版本需要先安装 bison和cmake :
bison直接用yum 安装就好:
[[email protected] home]# yum install bison
安装cmake:
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
下载后同样解压到 /usr/src 目录下
[[email protected] home]# cd /usr/src/cmake-2.8.4/ [[email protected] home]# ./configure
执行上述命令后发现报错:
[[email protected] cmake-2.8.6]# ./configure --------------------------------------------- CMake 2.8.6, Copyright 2000-2009 Kitware, Inc. --------------------------------------------- Error when bootstrapping CMake: Cannot find appropriate C compiler on this system. Please specify one using environment variable CC. See cmake_bootstrap.log for compilers attempted. --------------------------------------------- Log of errors: /usr/src/cmake-2.8.6/Bootstrap.cmk/cmake_bootstrap.log ---------------------------------------------
原来是在系统上找不到合适的C编译器,啊哦,GCC忘了装,莫慌,直接 yum命令装上gcc,还有gcc-C++没装的话后面也会提示错误,一起装上吧,,,
[[email protected] cmake-2.8.6]# yum install gcc gcc-c++
装好了之后,重新在cmake目录下执行: # ./configure,执行成功后会在最后提示你 “CMake has bootstrapped. Now run gmake.
”,好的,运行:
gmake
gmake install
等一会,cmake就装好了,
添加组和用户:
[[email protected] home]# groupadd mysql [[email protected] home]# useradd -g mysql mysql [[email protected] home]# mkdir -p /data/mysql [[email protected] home]# chown -R mysql:mysql /data/mysql
接下来依次执行:
[[email protected] home]# cd /usr/src/mysql-5.5.29 [[email protected] home]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/
报错:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:83 (MESSAGE): Curses library not found. Please install appropriate package, 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:127 (FIND_CURSES) cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT) CMakeLists.txt:269 (MYSQL_CHECK_READLINE) -- Configuring incomplete, errors occurred!
解决办法:
[[email protected] mysql-5.5.29]# rm CMakeCache.txt [[email protected] mysql-5.5.29]# yum install ncurses-devel
解决之后依次:
[[email protected] mysql-5.5.29]# make [[email protected] mysql-5.5.29]# make install
设置MySQL:
cd /usr/local/mysql cp ./support-files/my-huge.cnf /etc/my.cnf
编辑/etc/my.cnf
在 [mysqld] 段增加
datadir = /data/mysql
wait-timeout = 30
max_connections = 512
max_connect_errors = 10000000
default-storage-engine=MyISAM
在 [mysqld] 段修改
max_allowed_packet = 16M
接下来执行:
./scripts/mysql_install_db --user=mysql cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/rc.d/init.d/mysqld chkconfig --add mysqld chkconfig --level 3 mysqld on
编译/etc/rc.d/init.d/mysqld
把basedir=编辑成basedir=/usr/local/mysql
把datadir=编辑成datadir=/data/mysql
至此,MySQL数据库就装好了,:D
启动服务:
[[email protected] mysql]# service mysqld start Starting MySQL... [ OK ] [[email protected] mysql]#
OK,成功!
2.设置root的密码
进入mysql:
[[email protected] mysql]# mysql -uroot -p -bash: mysql: command not found
因为mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时,系统在/usr/bin下面查此命令,所以找不到了
解决办法是:做个链接即可
[[email protected] /]# ln -s /usr/local/mysql/bin/mysql /usr/bin
进入MySQL控制台之后,给root添加密码(这里给root设置的密码为“root”):
mysql> use mysql; Database changed mysql> update user set password=PASSWORD(‘root‘) where user=‘root‘; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql>
执行成功,退出控制台,重启MySQL服务即可:
[[email protected] /]# service mysqld restart Shutting down MySQL. [ OK ] Starting MySQL.. [ OK ] [[email protected] /]#
二.安装Apache HTTP Server
1.安装前准备
要安装Apache HTTP Server,必须先安装zlib-devel包:
yum install zlib-devel
配置Apache:
./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-so --enable-rewrite --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-deflate --enable-expires --enable-headers --disable-actions --disable-cgid --disable-cgi --disable-autoindex --disable-userdir --disable-alias --disable-include --enable-proxy-ajp --enable-proxy --enable-proxy-balancer
编译和安装:
[[email protected] httpd-2.2.23]# make [[email protected]calhost httpd-2.2.23]# make install
把Apache的服务控制器复制到系统 init.d目录下
[[email protected] httpd-2.2.23]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
现在Apache已经装好了,但是不支持chkconfig,也不支持service httpd start/stop,解决方案:
1)、将apachectl文件拷贝到/etc/rc.d/init.d 中,然后在/etc/rc.d/rc5.d/下加入链接即可。
命令如下:
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd //如果有其他的版本的Apache存在,也可以直接覆盖掉
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S85httpd
此时Apache就可以自动启动了。
2)、 运行chkconfig --list,发现没有linux服务列表中httpd,通过chkconfig --add httpd来添加,但是提示:httpd服务不支持 chkconfig。需要编辑/etc/rc.d/init.d/httpd,添加以下注释信息:
# chkconfig: 345 85 15
# description: Activates/Deactivates Apache Web Server //描述文字,随便写
第一行3个数字参数意义分别为:哪些Linux级别需要启动httpd(3,4,5);启动序号(85);关闭序号(15)。
保存后执行:chkconfig --add httpd,成功添加。
完成后就可以使用service httpd start/stop了,只是没有提示信息 :-(,如下:
[[email protected] /]# service httpd start [[email protected] /]# service httpd start httpd (pid 27846) already running [[email protected] /]#
解决方法:
编辑 httpd.conf
开启include httpd-info,即去掉前面的#号
然后编辑/usr/local/apache2/conf/extra/下的 httpd-info.conf 的内容
将里边的Allow from 更改为all
最后重启Apache
然后敲 service http status/stop/restart/start 等命令试下,发现status命令有点繁琐,不过无伤大雅。
三.安装PHP
1.配置PHP
进入PHP的解压包,开始配置:
# cd /usr/src/php-5.4.11/
执行 ./configure ....(后面命令省略)报错,如下:
checking libxml2 install dir... no checking for xml2-config path... configure: error: xml2-config not found. Please check your libxml2 installation.
libxml2-devel没安装,openssl和openssl-devel没安装的话,后面也会出错,还有bzip2 bzip2-devel、curl curl-devel、gd gd-devel、libjpeg libjpeg-devel、libmcrypt libmcrypt-devel、net-snmp net-snmp-devel也是一样,yum!
# yum install libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl curl-devel gd gd-devel libjpeg libjpeg-devel libmcrypt libmcrypt-devel net-snmp net-snmp-devel
配置时出错可参考文章:wang01ning.blog.163.com/blog/static/860179020104443154501/
完成后,配置:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --enable-fpm --with-mcrypt=/usr/local/libmcrypt
--with-zlib --enable-mbstring --with-openssl --with-mysql
--with-mysqli --with-mysql-sock --with-gd --with-jpeg-dir=/usr/lib
--enable-gd-native-ttf --enable-pdo --with-pdo-mysql
--with-gettext --with-curl --with-pdo-mysql --enable-sockets
--enable-bcmath --enable-xml --with-bz2 --with-gettext
--with-snmp --enable-zip --with-snmp
(红色部分很重要!!!)
配置成功,会有一句:Thank you for using PHP. 出现,表示配置OK啦
2.编译安装
[[email protected] php-5.4.11]# make [[email protected] php-5.4.11]# make install
耐心等待一会就行了,,,
3.PHP的配置文件php.ini
将php.ini-development 文件复制到/usr/local/php/lib下并重命名 为php.ini,这点倒是和Windows上的一样,呵呵
[[email protected] php-5.4.11]# cp php.ini-development /usr/local/php/lib/php.ini
4.配置Apache,让其支持PHP
到 /usr/local/apache2/conf 下找到httpd.conf,
在AddType application/x-gzip .gz .tgz下面,
添加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
在
# Example:
# LoadModule foo_module modules/mod_foo.so
#
下面添加
LoadModule php5_module modules/libphp5.so
保存,重启Apache,遇到问题:
[[email protected] php-5.4.11]# service httpd restart httpd: Syntax error on line 55 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
解决:
[[email protected] php-5.4.11]# setenforce 0
OK
四.测试是否安装好
1.防火墙问题
因为Linux的Firewall,所以Apache服务不能用,首先开启80端口给TCP协议:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
执行完,再:
[[email protected] php-5.4.11]# /etc/rc.d/init.d/iptables save Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
重启读取防火墙IP表:
[[email protected] php-5.4.11]# /etc/init.d/iptables restart Flushing firewall rules: [ OK ] Setting chains to policy ACCEPT: filter [ OK ] Unloading iptables modules: [ OK ] Applying iptables firewall rules: [ OK ] Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
2.
在 /usr/local/apache2/htdocs 下新建一个info.php文件,内容:
<?php
phpinfo();
?>
保存,打开浏览器,输入(作者的Linux机器地址为“http://192.168.0.5/”):
http://192.168.0.5/phpinfo.php,熟悉的phpinfo页面~
(很久之前写的文章,有一些尾巴没修改,PS:现在大部分都是LNMP了)
以上是关于CentOS 5.9裸机编译安装搭建LAMP的主要内容,如果未能解决你的问题,请参考以下文章
centos7.3编译安装LAMP环境并搭建WordPress博客
lamp :在Linux 下搭建apacheMysqlphp