1)安装MySQL
下载MySQL安装包到/usr/local/src中,解压后的文件放到/usr/local/mysql目录里(gz的解压zxvf,bz2的jxvf)。
mkdir -p /data/mysql
useradd -s /sbin/nologin mysql
cd /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql(遇到错误,只需yum安装即可)
配置文件:
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld
需要修改的地方有 “datadir=/data/mysql”,还有basedir=/usr/local/mysql;
service mysqld start
显示两个ok就表示成功了。
2)安装Apache
进入到解压的目录中2.2.24版本的;
./configure --prefix=/usr/local/apache2 --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre
如果不能编译C记得安装gcc;
报错后安装:yum install -y zlib-devel pcre pcre-devel apr apr-devel
make;make install
Apache 的 的 mpm 工作模式
查看 apache 工作模式的命令是:
/usr/local/apache2/bin/apachectl -M
3)PHP安装
进入到解压的目录里
./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
错误解决方法:yum install -y libxml2-devel
yum install -y openssl openssl-devel
yum install -y bzip2 bzip2-devel
yum install -y libpng libpng-devel
yum install -y freetype freetype-devel
yum install -y epel-release
yum install -y libmcrypt-devel
yum install -y libjpeg-turbo-devel (这个错误可能会提示)
编译,安装:make;make install
cp php.ini-production /usr/local/php/etc/php.ini
vi /usr/local/apache2/conf/httpd.conf
找到:
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
将Deny from all改为Allow from all
然后找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
再找到:
DirectoryIndex index.html
将该行改为:
DirectoryIndex index.html index.htm index.php
再将#ServerName www.example.com:80改为ServerName localhost:80
查看配置文件是否有问题:/usr/local/apache2/bin/apachectl -t
没有问题就启动服务:/usr/local/apache2/bin/apachectl start
测试PHP解析
vim /usr/local/apache2/htdocs/1.php
编辑下面的内容:
<?php
echo "php works.";
?>
用网页,curl测试。
如果运行不太流畅查看规则,iptables -nvL,清除规则iptables -F,service iptables save。