本文作者:不许人间见白头

Lamp(apache2.4mysql5.5php5.5)centos6版本

不许人间见白头 3周前 ( 11-22 03:42 ) 70
Lamp(apache2.4mysql5.5php5.5)centos6版本摘要: 本教程操作系统是Centos6.8安装编译需要的组件# yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel...

本教程操作系统是Centos6.8

安装编译需要的组件

# yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

安装mysql

# cd /usr/local/src

# wget  http://mirrors.ahaoyw.com/autoconf/lin/Mysql/mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz //下载mysql

# tar -zxvf mysql-5.5.61-linux-glibc2.12-x86_64.tar.gz       //解压

# mv mysql-5.5.61-linux-glibc2.12-x86_64 /usr/local/mysql    //拷贝文件

# useradd -M -s  /sbin/nologin mysql                  //新建mysql独立账号,不给登入权限

# cd /usr/local/mysql                          //进入配置文件

# mkdir -p /home/mysqldata ; chown -R mysql:mysql /home/mysqldata   //新建data存放路径,并附属data文件夹所属组为mysql

#  ./scripts/mysql_install_db --user=mysql --datadir=/home/mysqldata    //初始化数据库并指定路径

# cp support-files/my-large.cnf /etc/my.cnf       //拷贝mysql配置文件到etc目录下并改名my.cnf

# cp support-files/mysql.server  /etc/init.d/mysqld    //把启动配置程序拷贝到系统启动下

# chmod 755 /etc/init.d/mysqld

# vi /etc/init.d/mysqld     //编辑mysql启动项

image.png

要修改的配置如下

basedir=/usr/local/mysql

datadir=/home/mysqldata

也就是截图中的

# chkconfig --add mysqld

# chkconfig mysqld on

# service mysqld start

# /usr/local/mysql/bin/mysqladmin -u root password 你的密码 //设置MySQL密码

安装apache

(apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要下载apr。)

安装apr

apr官网地址https://mirrors.cnnic.cn/apache/apr/

也可以到https://mirrors.aliyun.com/apache/apr/

####安装apr####

# cd /usr/local/src

# wget mirrors.ahaoyw.com/autoconf/lin/httpd/apr-1.5.2.tar.gz

# tar -zxvf apr-1.5.2.tar.gz

# cd apr-1.5.2

# ./configure --with-apr=/usr/local/apr

# make  && make install

###安装apr-util#####

# cd /usr/local/src

# wget http://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz

# tar -zxvf apr-util-1.6.1.tar.gz

# cd apr-util-1.6.1

#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

# make && make install

# cd /usr/local/src

# wget mirrors.ahaoyw.com/autoconf/lin/httpd/httpd-2.4.34.tar.gz  //下载apache

# tar -zxvf httpd-2.4.34.tar.gz                 //解压apache

# cd httpd-2.4.34                 //进入apache目录

# ./configure --prefix=/usr/local/httpd --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared  --enable-headers=shared --enable-rewrite=shared --enable-static-support   --with-apr=/usr/local/apr  --with-apr-util=/usr/local/apr-util --with-mpm=prefork   

报错解决办法。执行完下面安装pcre在执行初始化

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

# yum install pcre pcre-devel -y

# make && make install

image.png

# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

# chmod 755 /etc/init.d/httpd 设置权限

# /etc/init.d/httpd start

安装php

# cd /usr/local/src

#wget http://mirrors.sohu.com/php/php-5.5.16.tar.gz

# tar -zxvf php-5.5.16.tar.gz 

# cd php-5.5.16

#  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/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=/www/server/jpeg --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


报错configure: error: mcrypt.h not found. Please reinstall libmcrypt

#yum install -y  libmcrypt-devel

image.png

# make

# make install

image.png

# cp php.ini-production /usr/local/php/etc/php.ini 

结合php

# vi /usr/local/httpd/conf/httpd.conf

找到

<IfModule dir_module>

    DirectoryIndex index.html

</IfModule> 

改为

<IfModule dir_module>

     DirectoryIndex index.html index.htm index.php

</IfModule>

image.png

找到AddType application/x-gzip .gz .tgz 在下面添加AddType application/x-httpd-php .php

image.png

找到#ServerName www.example.com:80改为ServerName localhost:80

image.png

wq保存

重启动apache:

 # /etc/init.d/httpd restart

查看是否启动:# netstat -lnp |grep httpd

image.png

# curl localhost   查看是否正常显示It works!

image.png

测试php

# echo "<?php phpinfo(); ?>" > /usr/local/httpd/htdocs/1.php

image.png

文章版权及转载声明:

作者:不许人间见白头本文地址:https://www.ahaoyw.com/article/362.html发布于 3周前 ( 11-22 03:42 )
文章转载或复制请以超链接形式并注明出处阿豪运维笔记