第一步:前期准备:准备虚拟机,最小化安装;彻底卸载mysql:关闭selinux;删除mysql用户:
[root@lilong ~]# rpm -qa|grep mysql
qt-mysql-4.6.2-26.el6_4.x86_64
mysql-server-5.1.71-1.el6.x86_64
mysql-libs-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
[root@lilong ~]# yum remove -y qt-mysql-4.6.2-26.el6_4.x86_64 mysql-server-5.1.71-1.el6.x86_64 mysql-libs-5.1.71-1.el6.x86_64 mysql-5.1.71-1.el6.x86_64
[root@lilong ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
[root@lilong local]# userdel mysql
第二步:安装mysql
[root@lilong tmp]# tar zxvf mysql-advanced-5.6.24-linux-glibc2.5-x86_64.tar.gz
[root@lilong local]# useradd -s /sbin/nologin mysql
[root@lilong local]# useradd -s /sbin/nologin mysql
[root@lilong local]# cd /data/
[root@lilong data]# mkdir mysql
[root@lilong /]# chown -R mysql:mysql /data/mysql/
[root@lilong mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
[root@lilong mysql]# echo $?
0
[root@lilong mysql]# cd support-files/
[root@lilong support-files]# pwd
/usr/local/mysql/support-files
[root@lilong support-files]# ls
binary-configure magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@lilong support-files]# vim mysql.server
datadir=/data/mysql
[root@lilong support-files]# cp mysql.server /etc/init.d/mysqld
[root@lilong support-files]# chmod 755 /etc/init.d/mysqld
[root@lilong support-files]# chkconfig --add mysqld
[root@lilong support-files]# chkconfig mysqld on
[root@lilong support-files]# service mysqld start
Starting MySQL. SUCCESS!
[root@lilong support-files]#
[root@lilong mysql]# ln -fs /usr/local/mysql/bin/* /usr/bin/
第三步:安装apache
[root@lilong tmp]# tar zxvf httpd-2.2.16.tar.gz
[root@lilong httpd-2.2.16]# yum install -y gcc
[root@lilong httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
[root@lilong httpd-2.2.16]# echo $?
0
[root@lilong httpd-2.2.16]# make && make install
[root@lilong httpd-2.2.16]# echo $?
0
第四步:安装php(libmcrypt-2.5.6源码包下载地址:ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz)
[root@lilong tmp]# tar zxvf php-5.3.28.tar.gz
[root@lilong tmp]# cd php-5.3.28
[root@lilong tmp]# yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
[root@lilong tmp]# tar zxvf libmcrypt-2.5.6.tar.gz
[root@lilong tmp]# cd libmcrypt-2.5.6
[root@lilong libmcrypt-2.5.6]# ./configure
[root@lilong libmcrypt-2.5.6]# make && make install
[root@lilong libmcrypt-2.5.6]# echo $?
0
[root@lilong libmcrypt-2.5.6]# cd ..
[root@lilong tmp]#cd php-5.3.28
[root@lilong 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
[root@lilong php-5.3.28]# echo $?
0
[root@lilong php-5.3.28]# make && make install
[root@lilong php-5.3.28]# echo $?
0
第五步:apache和php的结合
[root@lilong conf]# pwd
/usr/local/apache2/conf
[root@lilong conf]# vim 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
完成以上配置后,测试apache文件可显示正常:
[root@lilong conf]# /usr/local/apache2/bin/httpd -t
Syntax OK
第六步:测试解析php
[root@lilong conf]# cd ../htdocs/
[root@lilong htdocs]# ls
index.html
[root@lilong htdocs]# vim 1.php
<?
echo "php解析正常";
?>
如果在确认配置文件正常的情况下,提示404错误,重启系统即可。
第六步:apache测试
[root@lilong ~]# /usr/local/apache2/bin/httpd -t(查看配置文件是否正确)
httpd: apr_sockaddr_info_get() failed for lilong
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@lilong conf]# /usr/local/apache2/bin/httpd -l(静态加载的模块)
[root@lilong conf]# /usr/local/apache2/bin/httpd -M(加载的模块)
[root@lilong conf]# apachectl graceful不杀死进程,重新加载
第七步:php测试
[root@lilong ~]# vim 1.php
<?
echo "lilong";
echo "\n";
?>
[root@lilong ~]# /usr/local/php/bin/php 1.php
lilong
[root@lilong bin]# /usr/local/php/bin/php -m(php加载的模块)
[root@lilong bin]# /usr/local/php/bin/php -i(查看php参数)
[root@lilong php-5.3.28]# cp php.ini-development /usr/local/php/etc/php.ini
[root@lilong /]# /usr/local/php/bin/php -i |grep -i configuration(通过该命令查看上一条命令复制的配置文件已经加载)
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => /usr/local/php/etc/php.ini
Configuration
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in Unknown on line 0
[root@lilong htdocs]# vim 2.php
<?
phpinfo();
?>
通过浏览器可查看本机php的详细信息
[root@lilong htdocs]# ldd /usr/local/apache2/modules/libphp5.so (查看某个动态模块在哪里)
本文出自 “诗意人生” 博客,请务必保留此出处http://linuxleo.blog.51cto.com/3394274/1661569