一个朋友在阿里云上买了ECS云主机,选择是最新的centos7.2 64位操作系统,帮忙配置一下环境。在这里做一下记录:
一、安装apache2.4
cd
mkdir lamp
cd lamp
wget http://apache.fayea.com//httpd/httpd-2.4.23.tar.gz
tar -zxvf httpd-2.4.23.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
我在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就可以解决~
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:
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 #测试登录
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 #服务器到本地
(责任编辑:最模板) |