本教程操作系统是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启动项
要修改的配置如下
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
# 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
# make
# make install
# 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>
找到AddType application/x-gzip .gz .tgz 在下面添加AddType application/x-httpd-php .php
找到#ServerName www.example.com:80改为ServerName localhost:80
wq保存
重启动apache:
# /etc/init.d/httpd restart
查看是否启动:# netstat -lnp |grep httpd
# curl localhost 查看是否正常显示It works!
测试php
# echo "<?php phpinfo(); ?>" > /usr/local/httpd/htdocs/1.php