前言:在这里将介绍如何在CentOS下搭建LAMP环境(全部使用源码编译安装),用于web服务器开发。
CentOS安装我选取了64位的CentOS 7这个Linux系统,安装过程也很简单,不再过多叙述,只稍微介绍一下我的分区情况:
分区名大小/boot 200MB
/swap 8GB(不大于物理分区即可)
/ 20GB
/home 剩余空间
Apache编译安装
我选择了httpd 2.2这个版本,可以参考官方说明文档。
安装依赖:安装依赖需要用到的gcc、g++编译器:
########gcc、g++ sudo yum install gcc sudo yum install gcc-c++下面两个是apache的优化工具:
########apr wget .oss.aliyuncs.com/apr-1.5.1.tar.gz tar -zxvf apr-1.5.1.tar.gz cd apr-1.5.1/ ./configure --prefix=/opt/apr sudo make && make install ########apr-util cd Downloads/ wget .oss.aliyuncs.com/apr-util-1.5.4.tar.gz tar -zxvf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --prefix=/opt/apr-util --with-apr=/opt/apr sudo make && make installPerl库,兼容正则表达式库:
cd Downloads/ wget .oss.aliyuncs.com/pcre-8.36.tar.gz tar -zxvf pcre-8.36.tar.gz cd pcre-8.36 ./configure --prefix=/opt/pcre sudo make && make install 安装apache: cd Downloads/ wget http://labfile.oss.aliyuncs.com/httpd-2.2.29.tar.gz tar -zxvf httpd-2.2.29.tar.gz cd httpd-2.2.29 ./configure --prefix=/opt/apache --with-apr=/opt/apr --with-apr-util=/opt/apr-util --with-pcre=/opt/pcre sudo make && make install sudo sed -i 's/^#ServerName.*/ServerName localhost/' /opt/apache/conf/httpd.conf 测试:启动:
sudo /opt/apache/bin/apachectl start获取服务器回应(安装apache最后一步已经将服务器设为localhost):
curl -I 127.0.0.1若安装成功则如下:
关闭:
sudo /opt/apache/bin/apachectl stop MySQL编译安装 安装依赖:注意: MySQL5.5之后的版本使用cmake进行编译。
########若先前编译过,则需要删除刚才编译生成的CMakeCache.txt文件 rm -f CMakeCache.txt sudo yum -y install gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake cmake-gui libaio-devel bison-devel make 编译安装(时间较长): cd Downloads/ wget .oss.aliyuncs.com/mysql-5.6.24.tar.gz tar -zxvf mysql-5.6.24.tar.gz cd mysql-5.6.24 cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/opt/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 sudo make sudo make install 创建mysql用户: id mysql > /dev/null 2>&1 || sudo useradd -r -s /sbin/nologin -M -d /opt/mysql/data mysql 初始化数据目录: sudo chown -R mysql:mysql /opt/mysql/data sudo /opt/mysql/scripts/mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql --defaults-file=/opt/mysql/support-files/my-default.cnf 修改配置文件: sudo sh -c 'cat >> /opt/mysql/my.cnf <<EOF basedir = /opt/mysql datadir = /opt/mysql/data log-error = /opt/mysql/data/error.log pid-file = /opt/mysql/data/mysql.pid port = 3306 EOF' 清除残留文件: sudo sh -c 'for file in /etc/mysql/my.cnf /etc/my.cnf ; do [ -f $file ] && rm -f $file ; done' 启动: sudo /opt/mysql/support-files/mysql.server start