之前在另一篇文章里介绍过《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.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
这时候会报错:
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
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
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 #服务器到本地
整篇介绍完毕,大家在安装过程中有什么问题,欢迎留言~