首页 > 代码库 > 【CentOS】LAMP相关

【CentOS】LAMP相关

安装

http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.52-linux2.6-x86_64.tar.gz (免编译安装) //以上包均在搜狐镜像下载
http://mirrors.sohu.com/apache/httpd-2.4.23.tar.bz2 //之前做实验2.4的Apache会有点问题,所以先做2.2的
http://mirrors.sohu.com/apache/httpd-2.2.31.tar.gz //2.2

包下载好之后,先全部解压tar

解压完毕后,先安装MySQL,然后在安装Apache,最后在安装PHP,因为PHP会依赖前两者的一些模块

 

一、安装MySQL
1.mv mysql.... /usr/local/mysql
2.useradd -s /sbin/nologin mysql
3.mkdir -p /data/mysql
4.chown -R mysql:mysql /data/mysql
5../scripts/mysql_install_db --user=mysql --datadir=/data/mysql

//出现的第一个错误
//Installing MySQL system tables...
//./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
//解决办法,yum install -y libaio-devel 然后很顺利,这一步成功了

6.cp support-files/my-large.cnf /etc/init.d/my.cnf
7.cp support-files/mysql.server /etc/init.d/mysqld
8.chmod 755 /etc/init.d/mysqld
9.vim /etc/init.d/mysqld 在里面修改datadir=/data/mysql,basedir=/usr/local/mysql
10.chkconfig --add mysqld
11.chkconfig mysqld on
12.service mysqld start or /etc/init.d/mysqld start

 

二、安装Apache(httpd2.2)
1../configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so

//出现的第一个错误
//configure: error: in `/usr/local/src/httpd-2.2.31/srclib/apr‘:
//configure: error: no acceptable C compiler found in $PATH,直接安装gcc编译器既可以解决

2.make && make install(我居然忘记这一步了卧槽)

 

三、安装php
1../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

//然后炒鸡开心啊,马上就出现问题了!!
//Sorry, I cannot run apxs. Possible reasons follow:

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)

The output of /usr/local/apache2/bin/apxs follows:
./configure: line 8417: /usr/local/apache2/bin/apxs: No such file or directory
//这个问题居然是我犯二上面没有执行第二部所造成了,啊啊啊啊啊啊啊啊啊啊啊啊

//configure: error: xml2-config not found. Please check your libxml2 installation.原以为安装libxml2就好了,结果还是出现这个问题,然后安装个libxml2-devel就没问题了
//configure: error: Cannot find OpenSSL‘s <evp.h>,解决办法 yum install -y openssl openssl-devel
//configure: error: Please reinstall the BZip2 distribution,解决办法 yum install -y bzip2 bzip2-devel
//configure: error: jpeglib.h not found.解决办法 yum install -y libjpeg-devel
//configure: error: png.h not found.解决办法 yum install -y libpng libpng-devel
//configure: error: freetype-config not found.解决办法 yum install -y freetype freetype-devel
//configure: error: mcrypt.h not found. Please reinstall libmcrypt.解决办法 yum install -y libmcrypt-devel

2.make && make install
3.cp php.ini-development(因为我们是测试用,所以使用这个) /usr/local/php/etc/php.ini

 

四、Apache结合PHP
Apache主配置文件为:/usr/local/apache2/conf/httpd.conf(超级重要!!)在里面可以配置很多东西
1.如果php不能解析,在此文件里面找到AddType application/x-gzip .gz .tgz,然后在下面加上 AddType application/x-httpd-php .php
2.如果/usr/local/apache2/bin/apachectl -t 出现有错误(其实不算错误吧),则在#ServerName localhost:80中把#去掉
3.如果发现php文件执行不了,那是因为默认吧php文件都放在 /usr/local/apache2/htdocs
因为配置文件里面有这句话DocumentRoot "/usr/local/apache2/htdocs"

在启动前,/usr/local/apache2/bin/apachectl -t检测,
-M 列出装载的MOD

/usr/local/php/bin/php 1.php (执行脚本)
-M 列出加载了的模块
-I 查看参数

遇到php不能解析,相关步骤:
1./usr/local/apache2/bin/apachetcl -M |grep -i php看看有没有加载php5module
2.vi /usr/local/apache2/conf/httpd.conf看看有没有AddType(修改了必须重启)
3.getenforce 看看selinux有没有关

 

【CentOS】LAMP相关