再谈centOS7.2 LAMP源码安装及注意要点

摘要:之前在另一篇文章里介绍过《centOS7 LAMP安装及注意要点》,用的是yum自带安装。 一个朋友在阿里云上买了ECS云主机,选择是最新的centos7.2 64位操作系统,帮忙配置一下环境。在这里做一下记录: 一、安装apache2.4 cd mkdir lamp cd lamp wget http://apache.fayea.com/httpd/httpd-2.4.25.tar.g

之前在另一篇文章里介绍过《centOS7 LAMP安装及注意要点》,用的是yum自带安装。

一个朋友在阿里云上买了ECS云主机,选择是最新的centos7.2 64位操作系统,帮忙配置一下环境。在这里做一下记录:

1 (81).jpg

一、安装apache2.4

cd mkdir lamp cd lamp wget http://apache.fayea.com/httpd/httpd-2.4.25.tar.gz tar -zxvf httpd-2.4.25.tar.gz ./configure --prefix=/usr/local/apache2 --enable-modules=all --enable-cache=static --enable-mem-cache=static --enable-file-cache=static --enable-disk-cache=static --enable-ssl=satic --enable-deflate=static --enable-expires=static --enable-rewrite=static --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

 

#如果想配置SSL:

#openssl wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz tar -zxvf openssl-1.0.2n.tar.gz cd openssl-1.0.2n ./config -fPIC --prefix=/usr/local/openssl/ enable-shared make make install ln -s /usr/local/openssl/lib/*.so.* /usr/lib64 ln -s /usr/local/openssl/lib/*.so.* /usr/lib sed -i \'s:#LoadModule ssl_module modules/mod_ssl.so:LoadModule ssl_module modules/mod_ssl.so:\' /usr/local/apache2/conf/httpd.conf sed -i \'s:#LoadModule socache_shmcb_module modules/mod_socache_shmcb.so:LoadModule socache_shmcb_module modules/mod_socache_shmcb.so:\' /usr/local/apache2/conf/httpd.conf sed -i \'s:#Include conf/extra/httpd-ssl.conf:Include conf/extra/httpd-ssl.conf:\' /usr/local/apache2/conf/httpd.conf 下面的命令可以被用来产生一个自签名的证书。(来自网络) 首先,生成2048位的加密私钥 /usr/local/openssl/bin/openssl genrsa -out server.key 2048 然后,生成证书签名请求(CSR),这里需要填写许多信息,如国家,省市,公司等 /usr/local/openssl/bin/openssl req -new -key server.key -out server.csr 最后,生成类型为X509的自签名证书。有效期设置3650天,即有效期为10年 /usr/local/openssl/bin/openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt cp server.* /usr/local/apache2/conf/ sed -i \'s:#SSLCertificateChainFile "/usr/local/apache2/conf/server.crt":SSLCertificateChainFile "/usr/local/apache2/conf/server.crt":\' /usr/local/apache2/conf/extra/httpd-ssl.conf #apache ./configure --prefix=/usr/local/apache2 --enable-modules=all --enable-cache=static --enable-mem-cache=static --enable-file-cache=static --enable-disk-cache=static --enable-ssl=static --enable-deflate=static --enable-expires=static --enable-rewrite=static --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-ssl=/usr/local/openssl

这时候会报错:

error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

如何解决了, 原来它依赖apr和apr-util包;我们先安装它的依赖包吧

1、apr

cd lamp wget http://apache.fayea.com/apr/apr-1.5.2.tar.gz tar -zxvf apr-1.5.2.tar.gz cd apr-1.5.2 #在configure前,要先安装apr的依赖 yum install -y autoconf libtool ./buildconf ./configure --prefix=/usr/local/apr make make install

我在configure的时候,也报了一个错:

executing libtool commands rm: cannot remove \'libtoolT\': No such file ordirectory

如何解决了,在网上google一下,去configure里的文件$RM "$cfgfile"注释掉

vim configure $RM "$cfgfile" #前面加一个”#“,就可以~

然后再./configure 、make、make install

2、apr-util

cd lamp wget http://apache.fayea.com/apr/apr-util-1.5.4.tar.gz tar -zxvf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make make install

这样apr-util就安装完毕了

3、pcre

这个pcre也要安装一下,不然编译的时候也会报错。

cd lamp wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.zip yum install -y unzip #默认没有zip解压工具,先安装 unzip pcre-8.39.zip cd pcre-8.39 ./configure --prefix=/usr/local/pcre make make install

好了,这个时候再编译apache就不会再报错了,同时指定--with-apr等目录就可以了。

可能报错1:把apr和apr-util拷贝到apache/srclib里。

cp -fr apr-util-1.5.4 ./httpd-2.4.23/srclib/apr-util cp -rf apr-1.5.2 ./httpd-2.4.23/srclib/apr

可能报错2:

error: mod_deflate has been requested but can not be built due to prerequisite failures

解决方法:

yum install zlib-devel

安装zlib就可以解决~

可能报错3:

configure: error: You need a C++ compiler for C++ support

解决方法:

yum install -y gcc gcc-c++

4、测试apache

vi /usr/local/apache2/conf/httpd.conf #把servename改成以下 ServerName localhost:80

启动apache并测试:

/usr/local/apache2/bin/apachectl start curl localhost

应该可以看到 it works,表示安装成功。

二、Mysql5.7

centos7.2默认的数据库:mariadb;收购免不免费,先不讨论。习惯了mysql,我们就安装最新版的。

先卸载:mariadb

#查看是否存在 rpm -qa | grep mariadb #卸载 rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

下载mysql:(如果是centos6,请下载el6版本的)

cd lamp wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-common-5.7.14-1.el7.x86_64.rpm wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-libs-5.7.14-1.el7.x86_64.rpm wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.14-1.el7.x86_64.rpm wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.14-1.el7.x86_64.rpm

再安装一下mysql需要的扩展:

yum install -y libaio

rpm安装mysql:

rpm -ivh mysql-community-common-5.7.14-1.el7.x86_64.rpm --nosignature rpm -ivh mysql-community-libs-5.7.14-1.el7.x86_64.rpm --nosignature rpm -ivh mysql-community-client-5.7.14-1.el7.x86_64.rpm --nosignature rpm -ivh mysql-community-server-5.7.14-1.el7.x86_64.rpm --nosignature

cd /usr/bin mysqld --initialize-insecure --user=mysql #初始化 chown mysql:mysql -R /var/lib/mysql #修改权限 systemctl start mysqld #启动 mysqladmin -u root password #设置mysql 密码 mysql -u root -p #测试登录

可能出现的错:

libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.14-1.el6.x86_64

解决方法:

wget http://mirror.centos.org/centos/6/os/x86_64/Packages/numactl-2.0.9-2.el6.x86_64.rpm rpm -ivh numactl-2.0.9-2.el6.x86_64.rpm

Mysql5.7安装完毕。

三、PHP7.0.10安装

cd lamp wget http://tw1.php.net/distributions/php-7.0.10.tar.gz tar -zxvf php-7.0.10.tar.gz cd php-7.0.10

在编译之前,先安装一些PHP扩展依赖:

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel bzip2 bzip2-devel libxslt-devel

安装完毕后,接着安装PHP:

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-apxs2=/usr/local/apache2/bin/apxs --enable-fileinfo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-sysvshm --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --enable-calendar --with-xsl --enable-ctype --with-kerberos --enable-exif --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug --with-bz2 --enable-opcache make make install

安装完毕,现在要使apache支持php:

vim /usr/local/apache2/conf/httpd.conf #找到DirectoryIndex DirectoryIndex index.html index.htm default.html index.php default.php #找到AddType AddType application/x-httpd-php .php #重启apache /usr/local/apache2/bin/apachectl -k restart

整个安装完毕。

四、问题

在配置虚拟主机的时候,要使得外网能访问,得先防火墙80端口打开:

firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload #重启防火墙 #阿里云,默认selinux是关闭的,所以不用担心

一些注意细节,可以参考我的另一篇《centOS7 LAMP安装及注意要点》

最后设置一下apache开机自启动:

cd /lib/systemd/system vim httpd.service [Unit] Description=ApacheServer After=network.target [Install] WantedBy=multi-user.target [Service] Type=forking ExecStart=/usr/local/apache2/bin/apachectl -k start ExecReload=/usr/local/apache2/bin/apachectl -k restart ExecStop=/usr/local/apache2/bin/apachectl -k stop PrivateTmp=true #保存退出 #设置开机自启动 systemctl enable httpd.service

因为我用的是“SecureCRT”,所以安装一下lrzsz,这样方便上传和下载文件

yum install lrzsz rz #本地到服务器 sz #服务器到本地

整篇介绍完毕,大家在安装过程中有什么问题,欢迎留言~