LAMP环境搭建
1. 安装mysql###############################
注意,刚开始安装出错,原因是二进制包下载错了,本机centos是32位的,却下载了个64位的二进制包
###############################
# cd /usr/local/src/
# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
#二进制包免编译,若是64位系统,则下载这个包,32位则下载下面排错时的包
# tar zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz
# mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/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
./scripts/mysql_install_db: line 249: ./bin/my_print_defaults: cannot execute binary file
Neither host 'chen' nor 'localhost' could be looked up with
./bin/resolveip
Please configure the 'hostname' command to return a correct
hostname.
If you want to solve this at a later stage, restart this script
with the --force option
########################
此时出现错误,经过搜集资料,发现是因为本机系统为32位,却下载了一个64位的二进制包
使用命令如下命令查看本机系统是32位,还是64位
# getconf LONG_BIT
32
########################
#重新下下载一个对应包,再进行之前的操作,错误解决
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
#出现两个OK则正确安装上了
# cp support-files/my-large.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y #由于系统自带此文件,需要将它覆盖掉
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# vim /etc/init.d/mysqld #修改basedir和basedir,如下:
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/data/mysql
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
Starting MySQL............. SUCCESS!
#成功安装并启动mysql
2. 安装apache
# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz
# tar zxvf httpd-2.2.31.tar.gz
# cd httpd-2.2.31
# ./configure --prefix=/usr/local/apache2 --with-included-apr--with-pcre --enable-mods-shared=most
# echo $? #检查上一步是否出错,若为0则未出错,非0则有错
0
# make && make install
# echo $?
0
【如何指定使用worker/prefork】http://www.lishiming.net/thread-944-1-1.html
【apache两种工作模式】http://www.lishiming.net/thread-838-1-2.html
3.安装php
# wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
# tar zxf php-5.3.28.tar.gz
# cd 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
######################
执行上面命令的过程中会遇到一些依赖缺少的提示,下面列出我遇到的依赖问题:错误:configure: error: xml2-config not found. Please check your libxml2 installation.解决:yuminstall -ylibxml2-devel错误:configure: error: jpeglib.h not found.解决:yuminstall -ylibjpeg-devel错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.解决:yuminstall-ylibmcrypt-devel由于版权原因,可能无法直接安装上面的包,在百度经验里找到了一个解决办法:http://jingyan.baidu.com/article/54b6b9c0e94f1e2d583b4782.html错误:checking for recode support... yesconfigure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.解决:yuminstall -ylibrecode-devel
######################
重新编译执行如上操作,出现以下提示,则表明安装成功:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE.By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
# echo $?
0
# make && make install
# echo $?0#cp php.ini-production /usr/local/php/etc/php.ini #拷贝配置文件
4. 配置apache结合php
vim /usr/local/apache2/conf/httpd.conf找到:
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
改为:
Options FollowSymLinks
AllowOverride None
Order deny,allow
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
如果显示Syntax OK,则没有问题了。然后启动服务:
/usr/local/apache2/bin/apachectl start
检查Apache是否正常启动:
# ps aux |grep httpd
root 67330.01.0289129952 ? Ss 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 67340.00.9289128716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 67350.00.9289128716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 67360.00.9289128716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 67370.00.9289128716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
daemon 67380.00.9289128716 ? S 03:58 0:00 /usr/local/apache2/bin/httpd -k start
root 67530.00.0 6052 788 pts/0 S+ 04:01 0:00 grep httpd
5. 测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:
<?php
echo "php解析正常";
?>
保存后,继续测试:
curl localhost/1.php
页:
[1]