LAMP环境的搭建

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

1.安装mysql数据库
tar -zxvf mysql-5.1.58.tar.gz
cd mysql-5.1.58
./configure --prefix=/usr/local/mysql  --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl--with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
make
make install
创建MySQL数据库服务器的配置文件
cp support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql/
初始化mysql数据库
bin/mysql_install_db --user=mysql 
修改文件及其目录的权限,使其目录或文件的宿主为root,宿组为mysql,(data的宿主为mysql)
chown -R root  .   
chown -R mysql data
chgrp -R mysql .    
启动mysql数据库
/usr/local/mysql/bin/mysqld_safe --user=mysql &   
netstat -tnl|grep 3306 

设置mysql启动脚本文件
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
编辑/etc/rc.d/init.d/mysqld
指定mysql安装的目录basedir
/etc/init.d/mysqld restart
/usr/local/mysql/bin/mysql -uroot -p

2.安装apache服务器

创建apache用户和用户组
/usr/sbin/groupadd apache 
/usr/sbin/useradd -g apache -M -s /sbin/nologin apache    -M 参数说明给apache不创建家目录

tar -zxvf httpd-2.2.15.tar.gz
cd httpd-2.2.15
./configure --prefix=/usr/local/httpd/ --enable-deflate --enable-headers --enable-modules=so --enable-so --with-mpm=worker --enable-rewrite --enable-cgi --enable-file-cache --enable-cache --enable-disk-cache --enable-mem-cache
make
make install
修改apache运行的用户和用户组daemon为apache
vim /usr/local/httpd/conf/httpd.conf
65 User apache
66 Group apache
启动apache服务
/usr/local/httpd/bin/apachectl start
查看apache是否启动成功
[root@mail httpd-2.2.15]# netstat -antlp |grep "LISTEN" |grep "80"
tcp        0      0 :::80                       :::*                        LISTEN      19706/httpd
设置开机自动重启apache服务
vim /etc/rc.d/rc.local 最后添加
/usr/local/httpd/bin/apachectl start

3.安装PHP

tar -zxvf php-5.2.13.tar.gz
cd php-5.2.13
./configure --prefix=/usr/local/php                                            指定PHP安装路径
--with-apxs2=/usr/local/httpd/bin/apxs                                     告诉PHP查找Apache目录
--with-mysql=/usr/local/mysql                                                   指定mysql安装路径
--with-mysqli=/usr/local/mysql/bin/mysql_config                    指定mysql启动文件存放目录
--with-config-file-path=/usr/local/php/etc
--with-ttf
--with-libxml-dir
--with-xmlrpc
--with-openssl
--with-zlib
--with-freetype-dir
--with-gd
--with-gettext
--with-jpeg-dir
--with-png-dir
--with-mhash
--with-curl
--with-curlwrappers
--with-mcrypt
--with-iconv=/usr/local/libiconv
--enable-short-tags
--enable-sockets
--enable-xml
--enable-zend-multibyte
--enable-soap
--enable-mbstring
--enable-static
--enable-inline-optimization
--enable-gd-native-ttf
--enable-inline-optimization
--enable-exif --enable-mbregex

在编译PHP时候出现下面错误信息,安装相应的软件包即可
1)If configure fails try --with-xpm-dir=<DIR>configure: error: freetype.h not found.
yum install gd

2)configure: error: libpng.(a|so) not found.

yum install libjpeg
yum install libjpeg-devel
yum install libpng
yum install libjpeg-devel

3)configure: error: Please reinstall the iconv library.
tar -zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.9.2
./configure --prefix=/usr/local/libiconv
make
make install

4)configure: error: mcrypt.h not found. Please reinstall libmcrypt.
yum install libmcrypt libmcrypt-devel

5)configure: error: Please reinstall libmhash - I cannot find mhash.h
yum install libmhash mhash-devel

make
make install

4)LAMP整合

拷贝PHP主配置文件
cp php.ini-dist /usr/local/lib/php.ini

配置apache主配置文件,添加下面内容

vim /usr/local/httpd/conf/httpd.conf
LoadModule php5_module   modules/libphp5.so  共享对象打开
#AddType application/x-gzip .tgz
AddType application/x-httpd-php .php  添加PHP应用程序
DirectoryIndex index.html index.php   添加PHP默认主页类型

重启启动apache服务

/usr/local/httpd/bin/apachectl stop
/usr/local/httpd/bin/apachectl start

编写PHP测试网页
vim /usr/local/httpd/htdocs/ phpinfo.php
<?php

  phpinfo();
?>

在客户端测试LAMP整合是否successful

 

6)安装phpMyAdmin
tar -zxvf phpMyAdmin-3.2.4-all-languages.tar.gz
mkdir -p /var/www/
mv phpMyAdmin-3.2.4-all-languages /var/www/phpMyAdmin/
cp /var/www/phpMyAdmin/config.sample.inc.php /var/www/phpMyAdmin/config.inc.php
vim /var/www/phpMyAdmin/config.inc.php   指定下面选项即可
cfg[Servers][i]['host'] = '127.0.0.1';      把localhost修改为127.0.0.1
cfg[Servers][i]['user'] = 'root';                指定mysql服务器的用户名,可以是其他用户,但必须要给该用户授权
cfg[Servers][i]['password'] = 'mysql';   指定mysql数据库密码
创建phpMyAdmin.conf配置文件
vim /usr/local/httpd/conf/extra/phpMyAdmin.conf
Alias /phpMyAdmin /var/www/phpMyAdmin 
    <Location /phpMyAdmin> 
        Order deny,allow 
        Deny from all 
        Allow from 127.0.0.1 
        Allow from 192.168.1.115     指定客户端连接的IP地址
     </Location>

编辑apache的主配置文件添加下面内容
vim /usr/local/httpd/conf/httpd.conf
Include conf/extra/phpMyAdmin.conf
重启apache服务就大功告成啦
/usr/local/httpd/bin/apachectl restart

 

 










本文转自 sfzhang 51CTO博客,原文链接:http://blog.51cto.com/sfzhang88/851918,如需转载请自行联系原作者

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
打赏
0
0
0
0
234
分享
相关文章
一键安装LAMP环境
资源编排服务ROS(Resource Orchestration Service)支持通过创建资源栈的方式一键安装LAMP环境。
快速搭建LAMP环境
CentOS 7.7的ECS实例(云服务器)。通过本教程的操作,您可以基于ECS实例快速搭建一套LAMP环境。
385 0
快速搭建LAMP环境
安装搭建lamp服务环境的准备工作
安装搭建lamp服务环境的准备工作:
137 0
搭建LAMP环境
新手一起来学啊!!!
402 0
搭建LAMP环境
Day5快速搭建LAMP环境
LAMP是Linux、Apache、MySQL、PHP的简称。 web服务器主要功能是提供网上信息浏览服务。
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等