源码编译搭建LAMP环境 一、将 LAMP 相关软件包上传刡 linux 上
[root@node63 ~]# ls
anaconda-ks.cfg install.log mysql-5.5.30.tar.gz 公共的 视频 文档 音乐
httpd-2.2.25.tar.gz install.log.syslog php-5.4.14.tar.bz2 模板 图片 下载 桌面
1. 安装apache
[root@node63 ~]# tar zxvf httpd-2.2.25.tar.gz -C /usr/local/src/
[root@node63 ~]# cd /usr/local/src/httpd-2.2.25/
[root@node63 httpd-2.2.25]# yum -y install openssl*
[root@node63 httpd-2.2.25]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl
[root@node63 httpd-2.2.25]# make -j 4
[root@node63 httpd-2.2.25]# make install
[root@node63 httpd-2.2.25]# echo $?
apache的配置文件:
[root@node63 httpd-2.2.25]# ls /usr/local/apache2/conf/httpd.conf
/usr/local/apache2/conf/httpd.conf
存放网站根目录
[root@node63 httpd-2.2.25]# ls /usr/local/apache2/htdocs/*
/usr/local/apache2/htdocs/index.html
启动apache
[root@node63 httpd-2.2.25]# cp /usr/local/apache2/bin/apachectl /etc/init.d/ #拷贝到init下,以便于使用service httpd start来管理
参照
[root@node63 httpd-2.2.25]# vim /etc/init.d/apachectl
启动时,要比network启动晚一些,先让网络服务器启动起来,其他依靠网络相关的服务才可以启动
# chkconfig: 2345 64 36
# description: Activates/Deactivates all network interfaces configuredto \start at boot time.
设置开机启动:
[root@node63 httpd-2.2.25]# chkconfig --add apachectl
[root@node63 httpd-2.2.25]# chkconfig --list apachectl
apachectl 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[root@node63 httpd-2.2.25]# /etc/init.d/apachectl start
httpd: apr_sockaddr_info_get() failed for node63.xg.cn
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[root@node63 httpd-2.2.25]# chkconfig apachectl on
测试 在浏览器输入ip地址。
源码apacche运行身份是: daemon ; rpm安装的httpd运行身份是:apache
安装mysql
mysql服务器安装:mysql-5.5.30.tar.gz
安装前,如果没有mysql用户,则建立mysql用户
[root@node63 ~]# useradd mysql
[root@node63 ~]# vim /etc/passwd
#不让 mysql 用户登录系统
改成: mysql:x:501:501::/home/mysql:/sbin/nologin
[root@node63 ~]# tar zxvf mysql-5.5.30.tar.gz -C /usr/local/src/
[root@node63 ~]# cd /usr/local/src/mysql-5.5.30/
[root@node63 mysql-5.5.30]# yum install -y cmake
开始编译:
[root@node63 mysql-5.5.30]# mkdir /server/
[root@node63 mysql-5.5.30]# cmake -DCMAKE_INSTALL_PREFIX=/server/mysql-5.5 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/server/mysql/data -DMYSQL_USER=mysql
cmake -DCMAKE_INSTALL_PREFIX=/server/mysql-5.5 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/server/mysql/data -DMYSQL_USER=mysql
[root@node63 mysql-5.5.30]# make -j 4
[root@node63 mysql-5.5.30]# make install
[root@node63 mysql-5.5.30]# echo $?
0
配置mysql运行环境
[root@node63 mysql-5.5.30]# chown -R mysql:mysql /server/mysql-5.5/
复制mysql配置文件
[root@node63 mysql-5.5.30]# cp /usr/local/src/mysql-5.5.30/support-files/my-large.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
设置mysql服务开机启动:
[root@node63 mysql-5.5.30]# cp /usr/local/src/mysql-5.5.30/support-files/mysql.server /etc/init.d/mysql5.5
[root@node63 mysql-5.5.30]# chmod +x /etc/init.d/mysql5.5
[root@node63 mysql-5.5.30]# vim /etc/init.d/mysql5.5
将原文件中:
basedir=
datadir=
修改成:
basedir=/server/mysql-5.5
datadir=/server/mysql-5.5/data
加入开机启动项:
[root@node63 mysql-5.5.30]# chkconfig mysql5.5 on
[root@node63 mysql-5.5.30]# chkconfig --list mysql5.5
mysql5.5 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
初始化mysql数据库:
[root@node63 mysql-5.5.30]# cd /usr/local/src/mysql-5.5.30/scripts/
[root@node63 scripts]# chmod +x mysql_install_db
[root@node63 scripts]# ./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/server/mysql-5.5 --datadir=/server/mysql-5.5/data/ --user=mysql
开启mysql
[root@node63 scripts]# /etc/init.d/mysql5.5 start
Starting MySQL... [确定]
测试登录:
[root@node63 scripts]# mysql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test
安装PHP
[root@node63 ~]# tar -jxvf php-5.4.14.tar.bz2 -C /usr/local/src/
[root@node63 php-5.4.14]# cd /usr/local/src/php-5.4.14/
[root@node63 php-5.4.14]# ./configure --prefix=/server/php-5.4 --with-mysql=/server/mysql-5.5 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/server/php-5.4
./configure --prefix=/server/php-5.4 --with-mysql=/server/mysql-5.5 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/server/php-5.4
[root@node63 php-5.4.14]# make -j 4
[root@node63 php-5.4.14]# make install
[root@node63 php-5.4.14]# echo $?
生成php配置文档:php.ini
[root@node63 ~]# cp /usr/local/src/php-5.4.14/php.ini-production /server/php-5.4-nginx/php.ini
httpd.exp libphp5.so
让apache支持PHP模块:
[root@node63 php-5.4.14]# vim /usr/local/apache2/conf/httpd.conf
#添加红色内容
<IfModule dir_module>
DirectoryIndex index.html index.php #默认首页支持index.php
</IfModule>
在此文件311行下,添加:
AddType application/x-httpd-php .php
测试Apache及php支持
重启服务,测试:
[root@node63 php-5.4.14]# cd /usr/local/apache2/htdocs/
[root@node63 htdocs]# ls
index.html
[root@node63 htdocs]# mv index.html index.html.back
[root@node63 htdocs]# vim index.php
<?php
phpinfo();
?>
[root@node63 htdocs]# /etc/init.d/apachectl stop
[root@node63 htdocs]# /etc/init.d/apachectl start