安装 LAMP

卸载 并安装 MYSQL

rpm -qa | grep mysql 
rpm -e mysql-libs-5.1.71-1.el6.x86_64

yum remove mysql-libs-5.1.71-1.el6.x86_64

cd /usr/local/src/
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz

tar zxvf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.30-linux-glibc2.5-x86_64  /usr/local/mysql
useradd -M -s /sbin/nologin  mysql
mkdir -p /data/mysql
chown mysql /data/mysql
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/my-default.cnf  /etc/my.cnf
vim /etc/my.cnf
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock

cp support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysqld    
basedir=/usr/local/mysql
datadir=/data/mysql
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install -y libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel libjpeg-turbo-devel freetype freetype-devel libcurl-devel libtool-ltdl-devel libmcrypt-devel pcre-devel gcc zlib-devel

wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz

cd 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

make && make install

cd /usr/local/src

wget http://am1.php.net/distributions/php-5.3.27.tar.gz

tar zxf php-5.3.27.tar.gz

cd php-5.3.27

./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

make && make install

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

 

apache结合php

Apache主配置文件为:/usr/local/apache2/conf/httpd.conf

vim /usr/local/apache2/conf/httpd.conf

找到:

AddType application/x-gzip .gz .tgz

在该行下面添加:

AddType application/x-httpd-php .php

找到:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

将该行改为:

<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

找到:

#ServerName www.example.com:80

修改为:

ServerName localhost:80

测试LAMP是否成功

启动apache之前先检验配置文件是否正确:

/usr/local/apache2/bin/apachectl -t

如果有错误,请继续修改httpd.conf, 如果是正确的则显示为 “Syntax OK”, 启动apache的命令为:

/usr/local/apache2/bin/apachectl start

查看是否启动:

[root@localhost ~]# netstat -lnp |grep httpd
tcp        0      0 :::80                       :::*   LISTEN      7667/httpd

如果有显示这行,则启动了。 也可以使用curl命令简单测试:

[root@localhost ~]# curl localhost
<html><body><h1>It works!</h1></body></html>

只有显示这样才正确。

测试是否正确解析php:

vim /usr/local/apache2/htdocs/1.php

写入:

<?php
    echo "php解析正常";
?>

保存后,继续测试:

curl localhost/1.php

看是否能看到如下信息:

[root@localhost ~]# curl localhost/1.php
php解析正常[root@localhost ~]#

只有显示如阿铭这样才正确。

初次使用浏览器访问我们的web服务的时候,你可能无法访问,这是因为防火墙的缘故。请运行下面的命令:

[root@localhost ~]# iptables -F

这样就可以清除系统默认的防火墙规则,放行80端口。

posted @ 2016-08-01 14:19    阅读(162)  评论(0编辑  收藏  举报