lamp环境搭建

关闭selinux    vim /etc/selinux/config
#SELINUX=enforcing  注释掉
#SELINUX=targeted   注释掉
SELINUX=disabled   添加

1安装编译工具和库文件
yum install make apr* autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd? kernel keyutils? patch? perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel

yum install "Development tools"

编译安装一些软件

tar zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=/usr/local/apr
make && make install


tar zxvf apr-util-1.3.12.tar.gz
cd apr-util
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/usr/local
make && make install

tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/usr/local
make && make install


tar zxvf mcrypt.2.6.8.tar.gz
cd mcrypt.2.6.8
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./configure
make && make install


我安装的mysql 是免编译的那种
groupadd -r mysql   添加mysql组
useradd -r -s /sbin/nologin -g mysql mysql  创建mysql用户并加入mysql组
mkdir -p /data/mysql  创建mysql数据库存放目录
chown -R mysql.mysql /data     设置数据库目录权限
tar zxvf mysql-5.5.28-linux2.6-x86_64.tar.gz --prefix=/usr/local/
cd /usr/local
ls -sv mysql-5.5.28-linux2.6-x86_64 mysql
cd mysql
chown -R mysql.mysql .
scripts/mysql_install_db --datadir=/mydata/data --user=mysql
chown -R root .
cp mysql/support-file/my-lame.cnf /etc/my.cnf
vim /etc/my.cnf 添加 datadir = /mydata/data

设置service启动
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 3 mysqld on

设置库文件环境变量
vim /etc/ld.so.conf.d/mysql.d  写入 /usr/local/mysql/lib
在执行   ldconfig -v
ln -sv /usr/local/mysql/include /usr/include/mysql

编辑 vim /etc/profile.d/mysql.sh
写入 export PATH=$PATH:/usr/local/mysql/bin

重启linux   就直接可以用mysql命令了



编译apache
tar zxvf httpd-2.4.3.tar.gz
cd httpd-2.4.3
mkdir /usr/local/apache2
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-ssl --enable-ssl enable-module=so --enable-rewrite --enable-cgid --enable-cgi

make && make install

/usr/local/apache2/bin/apachectl -k start
vim /usr/local/apache2/conf/httpd
找到DirectoryIndex index.html  
修改为 DirectoryIndex index.html index.php
找到Options Indexes FollowSymlinks
修改为 Options FollowSymlinks

找到 AllowOverride None
改为 AllowOverride All
LoadModule rewrite_module modules/mod_rewrite.so 取消前面的注释,开启apache支持伪静态

vim /etc/profile  添加apache服务环境变量
在最后添加 export PATH=$PATH:/usr/local/apache2/bin
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

chown daemon.daemon -R /usr/local/apache2/htdocs  更改目录所有者
chmod /usr/local/apache2/htdocs -R 更改apache网站目录权限


安装php
mkdir /usr/local/php5
tar zxvf php-5.4.9.tar.gz 
cd php-5.4.9
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-freetype --with-jpeg --with-png --with-zlib --with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-lnline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-tff -with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gertext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt --with-libmcrypt=/usr/local


cp php.ini-production /usr/local/php5/etc/php.ini 复制php配置文件到安装目录
rm -rf /etc/php.ini 删除系统自带的配置文件
ln -s /usr/local/php5/etc/php.ini /etc/php.ini  创建配置文件软链接
vim /etc/php.ini
找到:;open_basedir=.:/tmp/   防止php木马跨站
找到:;date.timezone =
修改为; date.timezone = PRC
找到 expose_php = On
修改为 expose_php = Off 禁止显示php版本的信息
找到display_errors = On
修改为 display_errors = Off 关闭错误提示

配置apache支持php
vim /usr/local/apache2/conf/httpd.conf 
在LoadModule php5_module modules/libphp5.so 在这行下面添加
AddType application/x-http-php.php
service httpd restart 重启apache
service mysqld restart 重启mysql

测试
vim /usr/local/apache2/htdocs/index.php
写入  <?php
phpinfo();
?>
保存

在浏览器输入服务器ip地址  可以看到相关配置就ok了







你可能感兴趣的:(lamp)