LAMP 环境搭建之源码包编译安装

mysql用的二进制包安装。 Apache php 用的源码包

mysql版本5.5.46 Apache版本2.4.7 PHP版本:5.5
mysql安装部分参考了阿铭linux的内容。这是第二次搭建lamp环境。Apache2.4的版本比2.2的关系依赖包要多几个,PHP那部分有几个包也是源包安装的。视频刚看到lamp环境搭建的前几节。写不好,请勿喷。


安装mysql

mysql下载地址:http://mirrors.sohu.com/mysql/MySQL-5.5/

初始化

[root@localhost lamp]# tar zxvf mysql-5.5.46-linux2.6-x86_64.tar.gz#解压


[root@localhost lamp]#mv mysql-5.5.46-linux2.6-x86_64 /usr/local/mysql#移动位置,并去掉版本好

[root@localhost lamp]#useradd -s /sbin/nologin -M mysql#增加mysql用户。 不能登录 不创建家目录

[root@localhost lamp]#mkdir -p /data/mysql#创建datadir 数据库文件会放在这里

[root@localhost lamp]# chown -R mysql:mysql /data/mysql/#更改属组 属主

[root@localhost lamp]# cd /usr/local/mysql/#进入目录

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql--user定义数据库的所属主,--datadir 定义安装目录



接下来会看到有两个OK.说明执行正确。







[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

#复制启动脚本文件

[root@localhost mysql]# chmod 755 /etc/init.d/mysqld

# 修改启动脚本权限

[root@localhost mysql]# vim /etc/init.d/mysqld

#修改启动脚本。 找到bashedir 增加下面的路径



basedir=/usr/local/mysql#安装位置

datadir=/data/mysql#数据库位置





然后把启动脚本加入系统服务项,设定开机启动

chkconfig --add mysqld



chkconfig mysqld on



service mysqld start

如果启动不了。请到/data/mysql 目录下查看错误日志。这个日志通常是主机名.err。



检查MYSQL石否启动的命令为:

ps aux |grep mysqld



netstat -an |grep 3306











安装Apache2.4.7版本。

下载地址为:http://mirrors.sohu.com/apache/

tar zxvf httpd-2.4.7.tar.gz #解压文件



cd httpd-2.4.7 #进入目录



./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared #编译参数



错误



configure: error:Bundled APR requested but not found at./srclib/.



tar zxvf apr-1.4.6.tar.gz #解压apr包

tar -zxvf apr-util-1.4.1.tar.gz #解压apr-util包

cp -r /lamp/apr-1.4.6 /lamp/httpd-2.4.7/srclib/apr

cp -r /lamp/apr-util-1.4.1 /lamp/httpd-2.4.7/srclib/apr-util # 然后把两个包复制到httpd-2.4.7/srclib/ 里面并且取消版本号。





错误:

configure: error: in /lamp/httpd-2.4.7/srclib/apr':</span></span></span><br></br><span><span style="font-size: medium"><span>configure: error: no acceptable C compiler found in $PATH</span></span></span><br></br><span><span style="font-size: medium"><span>Seeconfig.log' for more details

configure failed for srclib/apr







yum -y install gcc-c++ #安装 gcc



错误:



configure: error: pcre-config for libpcre not found. PCRE is required and available fromhttp://pcre.org/

tar zxvf pcre-8.34.tar.gz

[root@localhost lamp]# cd pcre-8.34

[root@localhost pcre-8.34]# ./configure && make && make install





错误

checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures





yum -y install openssl-devel







把上面4个错误解决后。重新 ./configure 参数编译 无问题就执行

make

make install





/usr/local/apache2/bin/apachectl start # 启动apache

启动完后用以下命令检查apache是否正常启动,

ps aux |grep httpd

netstat -an |grep :80





如果不能启动 请清空防火墙规格。关闭selinux

iptables -F

service iptables save





通过浏览器输入地址访问:http://192.168.137.30 (我服务器的地址) 。若能显示“It works”表明apache正常工作。

设置Apache系统开机是自动开启。

vim /etc/rc.d/rc.local

增加一行 把下面增加进去。

/usr/local/apache2/bin/apachectl start







安装php5.5版本。

tar zxvf php-5.5.9.tar.gz #解压php安装包

cd php-5.5.9 #进入php文件



./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 --with-mcrypt=/usr/local/libmcrypt/ #编译参数





错误configure: error: xml2-config not found. Please check your libxml2 installation.yum install -y libxml2-devel错误configure: error: Please reinstall the BZip2 distribution



yum install -y bzip2 bzip2-devel错误

configure: error: jpeglib.h not found.



yum install libjpeg-devel -y





错误

configure: error: png.h not found.

yum install libpng-devel -y





错误

configure: error: freetype-config not found.

yum install -y freetype freetype-devel



错误

configure: error: mcrypt.h not found. Please reinstall libmcrypt.



tar zxvf mcrypt-2.6.8.tar.gz #提示mcrypt包没有安装。安装mcrypt包 又依赖依赖 libmcrypt, mhash 这两个包。





1.首先编译安装 libmcrypt, mhash, mcrypt 二进制源码包。



下载libmcrypt-2.5.8.tar.gz





tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/related/libmcrypt

make

make install





安装 libltdl,也在libmcrypt源码包里面

cd libmcrypt-2.5.8 /libltdl



./configure --enable-ltdl-install

make

make install



下载mhash-0.9.9.9.tar.gz

tar zxvf mhash-0.9.9.9

cd mhash-0.9.9.9

./configrue --prefix

make

make install





这两个包安装完。然后在安装mcrypt包。





安装mcrypt

tar zxvf mcrypt-2.6.8.tar.gz

LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt #编译参数



make

make install

#mcrypt 没有安装完成。这是php模块。需要等php安装完成之后。在继续安装。













把以上的依赖关系解决完了之后在继续安装PHP

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 --with-mcrypt=/usr/local/libmcrypt/

make

make install





生成php.ini

cp /lamp/php-5.5.9/php.ini-production /usr/local/php/etc/php.ini







apache结合php



Apache的主配置文件为 :/usr/local/apache2/etc/httpd.conf #参数编译的时候指定到/usr/local/apache2/etc/ 这个目录下。

vim /usr/local/apache2/etc/httpd.conf

找到AddType application/x-gzip .gz .tgz 这一行在下面增加

AddType application/x-httpd-php .php

找到:

DirectoryIndex index.html

将中间一样的内容改为:DirectoryIndex index.html index.htm index.php

修改完成后保存退出。

启动前检测apache的配置文件是否正常。

/usr/local/apache2/bin/apachectl -t

如果显示“Syntax OK” 表示正常。

启动apache

/usr/local/apache2/bin/apachectl start

检测是否启动成功。

netstart -lnp |grep httpd



/usr/local/apache2/bin/apachectl graceful 加载apache配置文件 不用重启







/usr/local/apache2/bin/apachectl -t 查看php配置文件是否正常







/usr/local/php/bin/php -i |more 能查看php安装信息。。./configure 内容 等等







cat /usr/local/apache2/build/config.nice 查看apache 安装的编译代码









cat /usr/local/mysql/bin/mysqlbug |grep -i confi 参看musql安装的编译参数

原文链接: https://www.cnblogs.com/zhaofuyun/p/5092386.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/226671

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 下午1:19
下一篇 2023年2月13日 下午1:20

相关推荐