LAMP架构搭建

    xiaoxiao2025-02-13  12

    一、MySQL数据库安装

    1. 系统环境 CentOS 6.4 x86_64 Mini 版本安装 2. 基础软件包安装

    [root@song /]# yum install gcc vim make wget -y

    3. 下载

    [root@song /]# cd /usr/local/src #下载mysql [root@song src]# wget downloads.mysql.com/archives/get/file/mysql-5.5.40-linux2.6-x86_64.tar.gz

    4. 解压安装

    [root@song src]# tar -zxf mysql-5.5.40-linux2.6-x86_64.tar.gz # 设置安装路径 [root@song src]# mv mysql-5.5.40-linux2.6-x86_64 /usr/local/mysql

    5. 创建MySQL用户

    [root@song src]# useradd -s /sbin/nologin -M mysql

    6. 准备数据目录

    # 进入MySQL安装目录 [root@song src]# cd /usr/local/mysql # 创建MySQL数据目录 [root@song mysql]# mkdir -p /var/lib/mysql # 设置目录权限 [root@song mysql]# chown -R mysql:mysql /var/lib/mysql

    7. 初始化数据库

    [root@song mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql when specifying MySQL privileges ! Installing MySQL system tables... OK Filling help tables... OK

    8. 拷贝配置文件

    [root@song mysql]# /bin/cp support-files/my-large.cnf /etc/my.cnf

    9. 拷贝启动脚本

    # 拷贝启动脚本 [root@song mysql]# /bin/cp support-files/mysql.server /etc/init.d/mysqld # 修改权限 [root@song mysql]# chmod 755 /etc/init.d/mysqld

    10. 修改启动脚本

    [root@song mysql]# vim /etc/init.d/mysqld # 修改设置内容如下 basedir=/usr/local/mysqldatadir=/var/lib/mysql

    11. 把MySQL添加到服务

    # 添加到service列表 [root@song mysql]# chkconfig --add mysqld # 设置开机启动 [root@song mysql]# chkconfig mysqld on

    12. 启动MySQL服务

    [root@song mysql]# service mysqld startStarting MySQL... SUCCESS!

    13. 查看验证MySQL启动进程

    [root@song mysql]# ps -e | grep mysql 1830 pts/1 00:00:00 mysqld_safe 2121 pts/1 00:00:00 mysqld

    14. 配置MySQL环境变量

    将 MySQL 客户端命令路径加入 PATH 环境变量中去。

    # 设置PATH环境变量 [root@song mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh [root@song mysql]# source /etc/profile.d/mysql.sh

    15. 登录MySQL测试

    [root@song mysql]# mysql Your MySQL connection id is 1 Server version: 5.5.40-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. ... ... mysql>

    二、Apache服务安装

    apache可以通过yum的方式来安装,也可以通过源码编译的方式来安装,这里采用编译源码的方式进行安装。 1. 系统环境 CentOS 6.4 x86_64 Mini 版本安装 2. 下载解压apache安装包

    [root@song /]# cd /usr/local/src [root@song src]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.31.tar.gz [root@song src]# tar zxf httpd-2.2.31.tar.gz *

    3. 安装必要的库和工具*

    [root@song src]# yum install -y pcre pcre-devel apr apr-devel zlib-devel gcc make

    4. 配置编译参数

    [root@song src]# cd httpd-2.2.31 [root@song httpd-2.2.31]# ./configure \ --prefix=/usr/local/apache2 \ --with-included-apr \ --enable-so \ --enable-deflate=shared \ --enable-expires=shared \ --enable-rewrite=shared \ --with-pcre

    5. 编译安装

    [root@song httpd-2.2.31]# make [root@song httpd-2.2.31]# make install

    6. 配置apache环境变量

    [root@song httpd-2.2.31]# echo 'export PATH=$PATH:/usr/local/apache2/bin' > /etc/profile.d/http.sh [root@song httpd-2.2.31]# source /etc/profile.d/http.sh

    7. apache的启动和停止

    apachectl start # 启动 apachectl stop # 停止 apachectl restart # 重启 apachectl -t # 检查语法 apachectl -M # 查看加载模块

    8. 将apache加入系统服务

    # 拷贝服务脚本 [root@song httpd-2.2.31]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd [root@song httpd-2.2.31]# vim /etc/init.d/httpd # 第一行下边添加2行内容 #!/bin/sh # chkconfig: 2345 61 61 # description: Apache # 添加到系统服务 并设置开机启动 [root@song httpd-2.2.31]# chkconfig --add httpd [root@song httpd-2.2.31]# chkconfig httpd on

    9. 验证服务是否正常

    [root@song httpd-2.2.31]# service httpd start httpd: apr_sockaddr_info_get() failed for vip # 出现警告信息 httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName 解决警告信息的方法:去掉 ServerName www.example.com:80 行的注释#。

    三、PHP系统安装

    1. 下载解压安装包

    [root@song /]# cd /usr/local/src [root@song src]# wget http://cn2.php.net/get/php-5.5.38.tar.gz/from/this/mirror -O php-5.5.38.tar.gz [root@song src]# tar zxf php-5.5.38.tar.gz

    2. 下载依赖库和工具

    [root@song src]# yum install -y epel-release [root@song src]# yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel \ libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel

    3. 编译配置安装选项

    [root@song src]# cd php-5.5.38 [root@song php-5.5.38]# ./configure \ --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-config-file-path=/usr/local/php/etc \ --with-mysql=/usr/local/mysql \ --with-libxml-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-iconv-dir \ --with-zlib-dir \ --with-bz2 \ --with-openssl \ --with-mcrypt \ --enable-soap \ --enable-gd-native-ttf \ --enable-mbstring \ --enable-sockets \ --enable-exif \ --disable-ipv6

    4. 编译安装

    [root@song php-5.5.38]# make [root@song php-5.5.38]# make install

    5. 拷贝php配置文件

    [root@song php-5.5.38]# cp php.ini-production /usr/local/php/etc/php.ini

    6. 配置php环境变量

    [root@song php-5.5.38]# echo 'exportPATH=$PATH:/usr/local/php/bin' > /etc/profile.d/php.sh [root@song php-5.5.38]# source /etc/profile.d/php.sh

    到此为止,php完成基本的编译安装,后续解析php还得另外配置。

    四、配置支持php解析

    1. 修改apache配置文件

    <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Allow from all # Deny修改为Allow </Directory>

    2. 支持php脚本解析

    AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php # 添加这1行

    3. 添加php索引支持

    <IfModule dir_module> DirectoryIndex index.html index.htm index.php # 添加php索引 </IfModule>

    4. 测试配置语法和重启apache服务

    [root@song ~]# apachectl -t Syntax OK [root@song ~]# service httpd restart

    5. 测试php解析 编写测试文件:vim /usr/local/apache2/htdocs/index.php

    <?php echo "hello php!" ?>

    命令行curl测试:

    [root@song htdocs]# curl localhost/index.php hello php![root@song htdocs]#

    解析 php 成功!

    最新回复(0)