安装php的程序环境
检查apache及mysql的安装情况
[[email protected] /]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME
mysqld 1743 mysql 10u IPv4 12158 0t0 TCP *:mysql(LISTEN)
[[email protected] /]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODENAME
httpd 1567 root 4u IPv6 11482 0t0 TCP *:http (LISTEN)
httpd 1570 daemon 4u IPv6 11482 0t0 TCP *:http (LISTEN)
httpd 1571 daemon 4u IPv6 11482 0t0 TCP *:http (LISTEN)
[[email protected] /]#
apache和mysql必须安装好才能安装php
检查安装php所需lib库
[[email protected] /]# yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-develcurl-devel –y
[[email protected] /]# rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-develgd-devel curl-devel
zlib-1.2.3-29.el6.x86_64
gd-2.0.35-11.el6.x86_64 +m
libxml2-devel-2.7.6-21.el6_8.1.x86_64
freetype-devel-2.3.11-17.el6.x86_64y
libpng-1.2.49-2.el6_7.x86_64
libpng-devel-1.2.49-2.el6_7.x86_64
gd-devel-2.0.35-11.el6.x86_64
zlib-devel-1.2.3-29.el6.x86_64
freetype-2.3.11-17.el6.x86_64
curl-7.19.7-52.el6.x86_64
安装libiconv
[[email protected] /]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[[email protected] libiconv-1.14]# ./configure --prefix=/usr/local/libiconv
[[email protected] libiconv-1.14]# make && make install
[[email protected] libiconv-1.14]# cd ../
开始安装php
rz -y
tar xf php-5.3.27.tar.gz
cd php-5.3.27
编译:
./configure --prefix=/application/php5.3.27--with-apxs2=/application/apache/bin/apxs --with-mysql=/application/mysql--with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd--with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv--enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap--enable-mbstring --enable-static --enable-gd-native-ttf --with-curl --with-xsl--enable-ftp --with-libxml-dir
1047 yum install openssl-devle -y
编译(Configure)出现的错误:
1.
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannotfind OpenSSL‘s <evp.h>
解决办法:
yum install openssl-devel –y
2.
configure: error: xslt-confignot found. Please reinstall the libxslt >= 1.1.0 distribution
解决办法:
yum install libxslt-devel –y
=====================》》》》》编译成功!
make && make install
[[email protected] php-5.3.27]# echo$?
0
[[email protected] php-5.3.27]# ln-s /application/php5.3.27/ /application/php
[[email protected] php-5.3.27]# ll/application/php/
total 20
drwxr-xr-x 2 root root 4096 Jul 920:18 bin
drwxr-xr-x 2 root root 4096 Jul 920:18 etc
drwxr-xr-x 3 root root 4096 Jul 920:18 include
drwxr-xr-x 3 root root 4096 Jul 920:18 lib
drwxr-xr-x 3 root root 4096 Jul 920:18 man
配置php
[[email protected] php-5.3.27]# ll php.ini-*
-rw-r--r-- 1 101 101 69606 Jul 11 2013 php.ini-development =======è>>开发环境
-rw-r--r-- 1 101 101 69627 Jul 11 2013 php.ini-production =============》》产品环境
比较两者的区别:
[[email protected] php-5.3.27]# diff `ls php.ini-*`
521c521
< error_reporting = E_ALL | E_STRICT
---
> error_reporting = E_ALL & ~E_DEPRECATED
538c538
< display_errors = On
---
> display_errors = Off
549c549
< display_startup_errors = On
---
> display_startup_errors = Off
593c593
< track_errors = On
---
> track_errors = Off
611c611
< html_errors = On
---
> html_errors = Off
751c751
< ; removed in PHP 5.4.
---
> ; scheduled removed in PHP 5.4.
845c845
< ;cgi.redirect_status_env =
---
> ;cgi.redirect_status_env =
1318c1318
< mysqlnd.collect_memory_statistics = On
---
> mysqlnd.collect_memory_statistics = Off
1587c1587
< session.bug_compat_42 = On
---
> session.bug_compat_42 = Off
1596c1596
< session.bug_compat_warn = On
---
> session.bug_compat_warn = Off
[[email protected] php-5.3.27]#
拷贝php配置文件到php默认目录并更改文件名称为php。ini:
[[email protected] php-5.3.27]# cpphp.ini-production /application/php/lib/php.ini ===========》》php的配置文件
小结:
1. 正式配置文件一般关闭LOG,不输出LOG
2. php的配置文件目录:/application/php/lib
配置apache支持php
安装php默认产生的文件及配置
[[email protected] /]# ll /application/apache/modules/
total 28888
-rw-r--r-- 1 root root 9115Jul 7 00:42 httpd.exp
-rwxr-xr-x 1 root root 29566389 Jul 9 20:18 libphp5.so
[[email protected] /]# grep libphp5 /application/apache/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
执行下面的命令编辑apache的主配置文件http.conf
[[email protected] php-5.3.27]# cd /application/apache/conf/
[[email protected] conf]# cp httpd.confhttpd.conf.ori ===========è> 养成备份的好习惯
[[email protected] apache]# vi/application/apache/conf/httpd.conf ====切换到 311gg,添加如下
AddType application/x-httpd-php .php.phtml
AddType application/x-httpd-php .source.phps
:wq
修改damon用户为ett
[[email protected] apache]# vi/application/apache/conf/httpd.conf ====切换到 65gg,添加如下
# running httpd, as with most system services.
#
User daemon ========== www
Group daemon ========== www
注意:如果不存在www用户,一会保存好配置,需要执行useradd www –M -s /sbin/nologin 建立www。
然后转到166行修改默认的首页文件,本例中添加一个index.php:
# is requested.
#
<IfModule dir_module>
DirectoryIndexindex.php index.html
提示:养成备份的习惯,再就是可以diff(比对文件)
[[email protected] conf]# diff httpd.confhttpd.conf.
httpd.conf.20160712 httpd.conf.bak httpd.conf.ori
[[email protected] conf]# diff httpd.confhttpd.conf.ori
67,68c67,68
< User www
< Group www
---
> User daemon
> Group daemon
100,101c100
< #ServerName 192.168.1.128:80
<
---
>
169c168
< DirectoryIndex index.php index.html
---
> DirectoryIndex index.html
312,313d310
< AddType application/x-httpd-php .php .phtml
< AddType application/x-httpd-php .source .phps
[[email protected] conf]# useradd www -M -s/sbin/nologin
[[email protected] conf]# id www
uid=816(www) gid=816(www)groups=816(www)
[[email protected] conf]#
[[email protected] conf]# cd/application/apache/conf/extra/
[[email protected] extra]# ll
total 60
-rw-r--r-- 1 root root 2859 Jul 7 00:44 httpd-autoindex.conf
-rw-r--r-- 1 root root 1753 Jul 7 00:44 httpd-dav.conf
-rw-r--r-- 1 root root 2344 Jul 7 00:44 httpd-default.conf
-rw-r--r-- 1 root root 1103 Jul 7 00:44 httpd-info.conf
-rw-r--r-- 1 root root 5078 Jul 7 00:44 httpd-languages.conf
-rw-r--r-- 1 root root 949 Jul 7 00:44 httpd-manual.conf
-rw-r--r-- 1 root root 3789 Jul 7 00:44 httpd-mpm.conf
-rw-r--r-- 1 root root 2207 Jul 7 00:44 httpd-multilang-errordoc.conf
-rw-r--r-- 1 root root 11530 Jul 7 00:44 httpd-ssl.conf
-rw-r--r-- 1 root root 817 Jul 7 00:44 httpd-userdir.conf
-rw-r--r-- 1 root root 1507 Jul 7 08:17 httpd-vhosts1.conf
-rw-r--r-- 1 root root 1507 Jul 7 08:55 httpd-vhosts.conf
[[email protected] extra]# cat httpd-vhosts.conf
#
# Virtual Hosts
。。。。。。。。。。。。。。。。。。
# match a ServerName or ServerAlias inany <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/www"
ServerName www.etiantian.org
ServerAlias www.etiantian.org
ErrorLog "logs/www-error_log"
CustomLog "logs/www-access_log" common
</VirtualHost>
<VirtualHost*:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/blog"
ServerName blog.etiantian.org
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log"common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/bbs"
ServerName bbs.etiantian.org
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
[[email protected] extra]# cd /var/html/blog/
[[email protected] blog]# ll
total 8
-rw-r--r-- 1 root root 26 Jul 7 08:13 index.html
[[email protected]]# vi index.php
<?php
phpinfo();
?>
"index.php" 3L, 22C written
[[email protected] blog]#
[[email protected] extra]# cd /var/html/blog/
[[email protected] blog]# vi index.php
<?php
//$link_id=mysql_connect(‘主机名‘,‘用户‘,‘密码‘);
$link_id=mysql_connect(‘localhost‘,‘root‘,‘oldboy123‘) o
rmysql_error();
if($link_id){
echo "mysql successful byoldboy !";
}else{
echo mysql_error();
}
?>
"index.php" 15L, 256C written
[[email protected] blog]#
LAMP搭建成功!!!!!