LAMP环境可以运行php网站如discuz论坛,他是用php脚本写的一套网站程序,可以用这个程序运行这个网站,当然还有其他用php脚本写的流行网站,如wordpress(写博客)、phpwind(被阿里收购)、discuz(被腾讯收购) 。这里mysql-5.1.40包是免编译的二进制包,因为mysql编译很慢很复杂。
源码包的名字很简单,就一个版本号然后就是.tag.gz
二进制包都会带 glibc
还有i686或者 x86字眼
1. 安装mysql
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
注意:上面的地址是32位机器用的,如果你的机器是64位,下载这个包(http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz)安装方法是一样的。
[root@aming src]#tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
[root@aming src]#mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql
[root@aming src]#cd /usr/local/mysql
[root@aming mysql]#ls 会看到解压完的文件和目录
[root@aming mysql]#mkdir -p /data/mysql
[root@aming mysql]#useradd -s /sbin/nologin -M mysql (-M是不创建家目录,家目录下没有mysql目录)
[root@aming mysql]#chown -R mysql:mysql /data/mysql
[root@aming mysql]#cp support-files/my-large.cnf /etc/my.cnf
[root@aming mysql]#vi /etc/my.cnf,key_buffer_size=128M,#log-bin=mysql-bin,#binlog-format=mixed #server-id=1
[root@aming mysql]#cp support-files/mysql.server /etc/init.d/mysqld
[root@aming mysql]#chmod 755 /etc/init.d/mysqld
[root@aming mysql]#vi /etc/init.d/mysql,basedir=/usr/local/mysql,datadir=/data/mysql
[root@aming mysql]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql (这一步是初始化,正常会看到两个OK,并且初始化后ls /data/mysql会看到mysql和test两个目录)
[root@aming mysql]#chkconfig --add mysqld
[root@aming mysql]#chkconfig mysqld on
[root@aming mysql]#service mysqld start
2. 安装apache
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
[root@aming src]#tar zvxf httpd-2.2.16.tar.gz
[root@aming src]#cd httpd-2.2.16
[root@aming httpd-2.2.16]#ls可以看到INSTALL和README
[root@aming httpd-2.2.16]#yum install gcc
[root@aming httpd-2.2.16]#./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
[root@aming httpd-2.2.16]#make
[root@aming httpd-2.2.16]#make install
3. 安装php
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
[root@aming src]#tar zxvf php-5.3.28.tar.gz
[root@aming src]#cd php-5.3.28
[root@aming php-5.3.28]#./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 (报错解决方法:1、xml2-config not found,[root@aming php-5.3.28]#yum list |grep -i ’xml2‘ [root@aming php-5.3.28]#yum install -y libxml2-devel。2、cannot find openssl [root@aming php-5.3.28]#yum list |grep -i openssl [root@aming php-5.3.28]#yum install -y openssl-devel 3、error:please reinstall the BZIP2 [root@aming php-5.3.28]#yum list |grep bzip2 [root@aming php-5.3.28]#yum install -y bzip2-devel 4、error:jpeglib not found [root@aming php-5.3.28]#yum list |grep -i jpeg [root@aming php-5.3.28]#yum install libjpeg-turbo-devel openjpeg-devel
5、error:png not found [root@aming php-5.3.28]#yum list |grep png [root@aming php-5.3.28]#yum install -y libpng-devel 6、error:freetype not found [root@aming php-5.3.28]#yum list|grep freetype [root@aming php-5.3.28]#yum install -y freetype-devel 7、error:mcrypt not found,please reinstall libmcrypt 32位epel yum源下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
64位下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm ,rpm -ivh http://www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm,[root@aming php-5.3.28]#yum list |grep -i mcrypt [root@aming php-5.3.28]#yum install -y libmcrypt-devel)
[root@aming php-5.3.28]#make(make完之后需要检测,echo $? 如果是0则是正常)
[root@aming php-5.3.28]# make install
4、启动apache
/usr/localapache2/bin/apachectl start(在启动前,看看配置文件有没有错,/usr/local/apache2/bin/apachectl -t,正常显示OK)
5. 配置apache结合php
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
vim /usr/local/apache2/conf/httpd.conf找到:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
改为:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
6. 测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:
<?php
echo "php解析正常";
?>
保存后,继续测试:
curl localhost/1.php
php不能解析的原因:
检查apache有没有调用php模块,/usr/local/apache2/bin/apachectl -M,如果没有php模块,查看:ls /usr/localapache2/modules/libphp5.so,如果有,则检查vi /usr/localapache2/conf/httpd.cnf有没有LoadModule php5-module modules/libphp5.so,这三个是编译的时候通过apxs自动写进去的。有没有AddType application/x-httpd-php.php
如何开启开机启动apache:vi /etc/rc.local 加入/usr/local/apache2/bin/apachectl start
查看php加载了哪些模块:/usr/local/php -m
查看php已经编译的选项:/usr/local/php/bin/php |head
查看php的配置文件;/usr/local/php/bin/php -i
查看mysql编译参数:cat /usr/local/mysql/bin/mysqlbug |grep configure
查看apache有哪些模块:/usr/local/apache2/bin/apachectl(httpd) -M
参考资料:http://blog.sina.com.cn/s/blog_7e47087d01017bqy.html
http://www.cnblogs.com/52linux/archive/2012/03/24/2415637.html
http://www.j3j5.com/post-285.html
http://blog.csdn.net/bullbat/article/details/7909490/
http://blog.sina.com.cn/s/blog_65d94e4c010195ys.html
apache的动态和静态 http://www.cnblogs.com/eoiioe/archive/2008/12/23/1360476.html(2.0和2.2一样) http://blog.sina.com.cn/s/blog_6238358c01017gdu.html
apache 日志中记录代理IP以及真实客户端IP http://www.lishiming.net/thread-960-1-1.html
apache只记录指定URI的日志 http://www.lishiming.net/thread-981-1-1.html
apache的order allow deny http://www.lishiming.net/thread-832-1-1.html
apache开启压缩 http://www.aminglinux.com/bbs/thread-5528-1-1.html
apache虚拟主机开启php的短标签 http://www.aminglinux.com/bbs/thread-5370-1-1.html
apache options参数 http://www.aminglinux.com/bbs/thread-1051-1-1.html
apache 禁止trace或track防止xss攻击 http://www.aminglinux.com/bbs/thread-1045-1-1.html
apache 配置https 支持ssl http://www.aminglinux.com/bbs/thread-1029-1-1.html
apache的proxy代理总访问后端web的第一个虚拟主机 http://www.aminglinux.com/bbs/thread-941-1-1.html
apache 自定义header http://www.aminglinux.com/bbs/thread-830-1-1.html
apache的keepalive和keepalivetimeout http://www.aminglinux.com/bbs/thread-556-1-1.html
apache2.2到2.4配置文件变更 http://www.aminglinux.com/bbs/thread-7292-1-1.html
apache配置所有的虚拟主机都指向第一个 http://www.aminglinux.com/bbs/thread-491-1-1.html
httpd-2.4版本编译安装方法 http://www.aminglinux.com/bbs/thread-7283-1-1.html
apache启动脚本加入系统服务列表 http://www.aminglinux.com/bbs/thread-7344-1-1.html
php5.5、5.6编译安装方法 http://www.aminglinux.com/bbs/thread-7284-1-1.html
安装mysql时出错无法初始化缺少libstdc++.so.5 http://www.aminglinux.com/bbs/thread-6580-1-1.html