本文是简单介绍基于天翼云的Linux环境下,按照apache, php,  mysql官网源码编译手动安装的过程。 如果你期望通过已有的一些安装包快速安装的话,可以忽略本文。

第1部分 Apache

安装Apache 2.4.x。

选择官网下载源码编译的方法安装:

Step1: 从官网提供的link下载httpd源码,并解压

wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

gzip -d httpd-2.4.7.tar.gz

tar xvf httpd-2.4.7.tar

 

Step2: 下载编译apache所需的依赖包 APR,APR-util, apr-iconv

wget apache.petsads.us//apr/apr-1.5.0.tar.gz

wget apache.petsads.us//apr/apr-util-1.5.3.tar.gz

wget apache.petsads.us//apr/apr-iconv-1.2.1.tar.gz

wget http://sourceforge.net/projects/pcre/files/pcre/8.34/pcre-8.34.tar.gz/download

上面的连接可能已经过期不存在了,现在(2016年2月16号测试)官方提供了更快捷的依赖包,命令如下:

获取apr包,解压后直接将srclib里的apr复制到httpd源码目录中去

wget http://archive.apache.org/dist/httpd/httpd-2.4.7-deps.tar.gz

gzip -d httpd-2.4.7-deps.tar.gz

tar xvf httpd-2.4.7-deps.tar

 

在同一个目录中解压后apr相关源码已经自动解压在httpd-2.4.7/srclib中了,就无需如以前一样做一些文件复制操作,赞一个。

 

Step3: 如果系统没有 安装pcre,则需要安装pcre.

wget http://sourceforge.net/projects/pcre/files/pcre/8.34/pcre-8.34.tar.gz

gzip -d pcre-8.34.tar.gz

tar xvf pcre-8.34.tar

 

安装pcre

 

cd pcre-8.34

./configure --prefix=/usr/local/pcre

make

make install

 

Step4: 回到httpd2.4.7目录,进行编译和安装httpd到/home/apache

./configure --prefix=/home/apache/ --with-pcre=/usr/local/pcre/ -with-included-apr --enable-nonportable-atomics=yes --with-z

 

make

make install

 

Step5: 检验是否安装成功

进入/home/apache/

 

Step6: 启动apache

apachectrl start

如果启动是出现下面类似的错误,可能有几种问题

“AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message”

网上大部分是建议去掉注释即可。

关于这个错误可以参考官文:

http://wiki.apache.org/httpd/CouldNotDetermineServerName

我修改了etc/hosts,成功解决问题。

 

第2部分 PHP的安装和配置

参考官方文档:http://php.net/manual/zh/install.php

现在地址http://php.net/downloads.php

官方PHP所有的版本下载地址:http://php.net/releases/

 

Step1 下载PHP源文件

http://php.net/releases/

Step2 安装一些必备的依赖包,这些依赖包在天翼云的Centos系统中默认不存在。

yum -y install libxml2-devel

yum -y install curl-devel

yum -y install libjpeg-devel

yum -y install libpng-devel

yum -y install freetype-devel

 

Step3 编译和安装

./configure --prefix=/home/php5.5.8 --with-apxs2=/home/apache/bin/apxs --with-mysql --with-mysqli --with-gd --enable-mbstring --enable-sockets --enable-shared --with-pdo-mysql --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64 --with-png-dir=/usr/lib64 --with-curl

 

make

make install

 

运行自动化测试发现两个错误:

FAILED TEST SUMMARY

---------------------------------------------------------------------

Bug #52202 (CURLOPT_PRIVATE gets clobbered) [ext/curl/tests/bug52202.phpt]

DOMDocument::validate() should validate an external DTD declaration [ext/dom/tests/DOMDocument_validate_external_dtd.phpt]

Bug #32001 (xml_parse*() goes into infinite loop when autodetection in effect), using UTF-* [ext/xml/tests/bug32001.phpt]

 

Step4 配置php.ini

 

cp php.ini-production /home/php5.5.8/lib/php2.ini

 

第3部分 安装和配置mysql

mysql官方提供了很好的安装方法和步骤,这里整理下其中的一种安装方法。

http://dev.mysql.com/doc/refman/5.6/en/installing.html

 

http://dev.mysql.com/doc/refman/5.6/en/linux-installation-yum-repo.html

官方提供的这个新的方法还没试,因为之前下载了安装包,所以没有通过添加yum repository来做。看起来官方提供的新方法更简单。本文记录的是以前的方法,先要下载rpm包。

Step1 下载安装文件

 

Step2 创建相关用户和用户组

shell> groupadd mysql

shell> useradd -r -g mysql -s /bin/false mysql

 

Step3 检查系统中是否已安装mysql或一些mysql lib; 需要卸载,否则会有冲突。

rpm -qa|grep -i mysql

如有的话,就卸载,注意不需要卸载它的依赖包

rpm -e mysql-libs-5.1.61-4.el6.x86_64 –nodeps

 

Step4 本地安装mysql server

yum localinstall MySQL-server-5.6.15-1.el6.x86_64.rpm

 

Step5本地安装mysql client

yum localinstall MySQL-client-5.6.15-1.el6.x86_64.rpm

 

Step6 启动msyql并执行安全安装脚本,以便删除系统初始带的test数据库以及一些账户,从而使得mysql server环境更安全。

/usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

如果出现下面的问题,检查一下mysql 是否启动成功。

运行#/usr/bin/mysql_secure_installation

报错:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

解决方法:启动mysql.

发表评论