您的位置:首页 > 运维架构 > Linux

CentOS-6.7-x86_64下LAMP的搭建

2016-02-29 22:15 344 查看
1. 操作系统环境 操作系统环境为CentOS-6.7-x86_64,服务器系统采用最小化安装,无桌面2. 安装相关工具
yum -y install gcc pcre pcre-devel libaio python-devel

3. apache编译安装
apr的编译安装
wget http://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.gz tar –xvf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/usr/local/apr && make && make install

apr-util的编译安装
wget http://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.bz2 tar –xvf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4
./configure  --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install

httpd的编译安装
wget http://mirrors.aliyun.com/apache/httpd/httpd-2.4.18.tar.bz2 tar –xvf httpd-2.4.18.tar.bz2
cd httpd-2.4.18
./configure \
--prefix=/usr/local/apache2 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install

查看配置选项及其含义执行./configure --help可以查看各种配置选项及其含义,这里的配置选项含义--prefix:指定httpd的安装路径--sysconfdir: 指定httpd的配置路径--enable-so:启用动态加载模块支持,使httpd具备进一步扩展功能的能力--enable-rewrite:启用网页地址重写功能,用于网站的优化及目录迁移维护--enable-charset-lite:启动字符集支持,以便支持使用各种字符集编码的网页--enable-cgi:启用CGI脚本程序支持,便于扩展网站的应用访问能力修改配置文件
vim /usr/local/apache2/conf/httpd.conf

加上下面一行,重启apacheServerName localhost:80设置service方式启动apache将启动脚本复制为/etc/init.d/httpd
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

可以这样来停止、启动和重启apache
service httpd stop/start/restart
/etc/init.d/httpd stop/start/restart
/usr/local/apache2/bin/apachectl stop/start/restart

设置开机启动或许是因为兼容性不好,无法使用chkconfig设置开机启动
chkconfig --add httpd

但是可以修改/etc/rc.local设置apache开机启动,在/etc/rc.local添加/usr/local/apache2/bin/apachectlstart
echo "/usr/local/apache2/bin/apachectl start &" >> /etc/rc.d/rc.local

测试安装结果在浏览器中输入:http://ip/,如果浏览器中出现Itworks!则表明Apache服务器可以使用。4. mysql二进制包安装 (源码编译安装参考http://sky66.blog.51cto.com/2439074/1742653)添加用户和群组
useradd mysql -r -s /sbin/nologin -M

配置相关目录和文件属主和所属群组
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz tar -xvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.11-linux-glibc2.5-x86_64 /usr/local/mysql
cd/usr/local/mysql/
mkdir data
chown -R mysql.mysql .

初始化MySQL系统授权表
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

(会生成一个随机密码,注意保存登录时用)
./bin/mysql_ssl_rsa_setup

将目录属主更改为root,避免mysql用户将目录删除
chown -R root .
chown -R mysql data

创建mysql数据库服务器的配置文件
cp ./support-files/my-default.cnf /etc/my.cnf

可按需修改新的配置文件选项,不修改配置选项,mysql则按默认配置参数运行. 如下修改配置文件/etc/my.cnf是用于以防编码为utf8时存在乱码 [mysqld] character_set_server=utf8init_connect='SETNAMES utf8' [client] default-character-set=utf8配置mysql服务开机自动启动拷贝启动文件到/etc/init.d/下并重命令为mysqld
cp ./support-files/mysql.server /etc/init.d/mysqld

检查自启动项列表中没有mysqld这个,如果没有就添加mysqld:
chkconfig --list mysqld
chkconfig --add mysqld

设置MySQL在345等级自动启动
chkconfig --level 345 mysqld on

或用这个命令设置开机启动:
chkconfig mysqld on

mysql服务的启动/重启/停止
service mysqld start/restart/stop

mysql加入PATH环境变量
vim /etc/profile

在最后,添加: exportPATH="/usr/local/mysql/bin:$PATH" 保存,退出,然后运行:
source /etc/profile

访问mysql数据库连接mysql,输入初始化生成的随机密码
mysql -uroot -p

修改root新密码如123456
mysql>alter user 'root'@'localhost' identified by '123456';
mysql>quit;

使用新密码重新连接mysql
mysql -uroot -p

5. PHP编译安装为了让PHP5支持 GIF、PNG和JPEG图片格式,需安装GD2库,但在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件安装libxml2最新库文件
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.3.tar.gz tar –xvf  libxml2-2.9.3.tar.gz
cd libxml2-2.9.3
./configure --prefix=/usr/local/libxml2 && make && make install

安装zlib最新库文件
wget http://120.52.73.49/nchc.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz tar –xvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure--prefix=/usr/local/zlib && make && make install

安装libpng最新库文件
wgetftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.21.tar.xz
tar -xvf libpng-1.6.21.tar.xz
cd libpng-1.6.21
./configure --prefix=/usr/local/libpng && make && make install

安装jpeg最新库文件
wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz tar –xvf jpegsrc.v9b.tar.gz
cd jpegsrc.v9b
./configure --prefix=/usr/local/jpeg/ --enable-static && make && makeinstall

安装freetype最新库文件
wget http://ftp.twaren.net/Unix/NonGNU//freetype/freetype-2.6.tar.gz tar -xvf freetype-2.6.tar.gz
cd freetype-2.6
./configure --prefix=/usr/local/freetype && make && make install

安装gd最新库文件
wget https://github.com/libgd/libgd/releases/download/gd-2.1.1/libgd-2.1.1.tar.xz tar -xvf libgd-2.1.1.tar.xz
cd libgd-2.1.1
./configure \
--prefix=/usr/local/gd \
--with-jpeg=/usr/local/jpeg \
--with-png=/usr/local/libpng \
--with-freetype=/usr/local/freetype
make && make install

PHP安装
wget http://cn2.php.net/distributions/php-5.6.18.tar.xz tar –xvf php-5.6.18.tar.xz
cd php-5.6.18
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-libxml-dir=/usr/local/libxml2 \
--with-png-dir=/usr/local/libpng \
--with-jpeg-dir=/usr/local/jpeg \
--with-freetype-dir=/usr/local/freetype \
--with-gd \
--with-zlib-dir=/usr/local/zlib \
--enable-soap \
--enable-mbstring=all \
--enable-sockets
make && make install

问题与解决问题1:配置时可能会出现下面的错误: checking for MySQL support... yes checking for specified location of the MySQL UNIX socket... no checking for MySQL UNIX socket location... no configure: error: Cannot find libmysqlclient_r under /usr/local/mysql. Note that the MySQLclient library is not bundled anymore! 其实这跟PHP没有关系,那是因为在编译APACHE的时候,使用--with-mpm模块,所以就必须在编译MYSQL的时候加上 --enable-thread-safe-client.参数还有第二种解决方法比较方便:编译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可
cd /usr/local/mysql/lib/
ln -s libmysqlclient.so.20.2.0 libmysqlclient_r.so

问题2:编译时提示make: *** [ext/gd/gd.lo] 错误 1php源码包里有gd扩展,与--with-gd=/usr/local/gd有冲突,只用--with-gd就行了修改配置文件安装完成后,需要建立PHP配置文件。在使用configure命令安装配置时使用“--with-config-file-path=/usr/local/php/etc/”选项,指定了配置文件的位置。将源码包下面的php.ini-development 文件复制到/usr/local /php/etc/中,并改名为php.ini即可,如下示:
cp ./php.ini-development /usr/local/php/etc/php.ini

修改php.ini 把;date.timezone前面的分号去掉,改成date.timezone = PRC 整合ApachePHP在Apache的配置文件/usr/local/apache2/conf/httpd.conf,找到AddTypeapplication/x-gzip .gz .tgz指令选项,并在其下方添加如下示: # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress.Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .html .htm .php .phtml AddType application/x-httpd-php-source .html .htm .phps 修改完成后必须重启Apache服务器,才能重新加载配置文件使修改生效。 测试PHP环境在/usr/local/apache2/htdocs目录下建一个test.php或test.phtml的文件,内容如下示: <?php phpinfo(); ?> 打开浏览器,在地址栏输入http://ip/test.php来运行该文件,如果出现php信息页面,说明LAMP环境安装成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  服务器 LAMP