centos LAMP第一部分-环境搭建 Linux软件删除方式,mysql安装,apache,PHP,apache和php结合,phpinfo页面,ldd命令 第十九节课
打命令之后可以输入: echo $?
上半节课
Linux软件删除方式
mysql安装
apache
下半节课
PHP
apache和php结合
排错
phpinfo页面
ldd命令
apache下面的一个软件httpd,大家会把httpd误认为是apache
康盛镜像:http://www.aminglinux.com/study_v2/download.html
Linux软件删除方式
源码包删除:直接删除目录
rpm删除:rpm -e
yum 删除 yum remove
echo $?
是否编译成功或安装成功
免编译的包一般都带有:icc-glibc23
mysql
yum安装的mysql,本地root密码默认为空
http://bbs.qcloud.com/thread-5583-1-1.html
下载mysql
/usr/local/src 源码包放置地方
二进制免编译包:mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
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)安装方法是一样的。
mysql-5.1.40-linux-i686-icc-glibc23.tar.gz //icc表示用gcc编译
skip-networking 不让mysql监听3306端口,只用本地Unix socket
本地用/tmp/mysql.sock 连接数据库,不用tcp/ip
步骤:
tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz //下载免编译安装包 mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql/ useradd -s /sbin/nologin mysql //新建mysql用户 cd /usr/local/mysql mkdir -p /data/mysql //新建数据库数据目录 chown -R mysql:mysql /data/mysql //更改数据目录的属主属组 ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql //初始化 cp support-files/my-large.cnf /etc/my.cnf //拷贝配置文件
vi /etc/my.cnf //修改配置文件 cp support-files/mysql.server /etc/init.d/mysqld //拷贝启动脚本
vi !$ //修改启动脚本 basedir=/usr/local/mysql ,datadir=/data/mysql chmod 755 /etc/init.d/mysqld //更改启动脚本权限 vim /etc/init.d/mysqld #修改datadir chkconfig --add mysqld chkconfig mysqld on //加入到系统服务列表并设置启动级别 service mysqld start //启动mysql
ps -aux|grep mysql //是否有mysql进程
netstat -lnp|grep 3306
apache
APR是一个使apache在Linux下和Windows下都可以运行的一个东西,缺少它apache编译不了,apache2.2自带 apache2.4默认没有
./configure的时候报错
APR Version: 1.5.0
checking for APR... reconfig
先要安装perl 然后再装apache 2.4需要perl
apr:支持apache移植的包,不管在Windows还是Linux都能运行
http2.4.X需要apr和apr-util
/usr/local/apache2/bin/apxs是perl脚本,所以安装php 需要先安装perl
编译时不加安装路径会安装在/usr/local/apache2下
编译时可以指定不编译某个模块
主要的两种工作模式
worker:进程和线程共存
prefork:一个父进程生成很多子进程
--enable-so :安装动态扩展模块,dso:动态加载,动态库
so文件:动态加载模块文件,xx.so
c文件 :静态模块文件,xx.c
旧版本的apache,如果不知道编译选项,查看编译选项: cat /usr/local/apache2/build/config.nice
查看编译选项: /usr/local/src/httpd-2.2.16/configure --help
检查apache的配置文件是否有问题: ./bin/httpd -t 或 /usr/local/apache2/bin/httpd -t 等价 /usr/local/apache2/bin/apachectl -t
配置文件路径: /usr/local/apache2/bin/conf/httpd.conf
查看静态已加载模块 -l: /usr/local/apache2/bin/httpd -l
查看加载的所有模块 -M 大写M: /usr/local/apache2/bin/httpd -M
apache控制脚本: /usr/local/apache2/bin/apachectl start /stop /restart /graceful /-t
graceful:重新加载配置文件,不杀死apache进程
restart:杀死apache进程,再启动
测试是否安装成功,下载整个网页: curl localhost
步骤
安装apache rpm -qa |grep httpd //查看是否已经安装过apache rpm -e httpd-2.2.15-39.el6.centos.x86_64 wget http://archive.apache.org/dist/httpd/httpd-2.2.27.tar.bz2 tar jvxf httpd-2.2.27.tar.bz2 cd httpd-2.2.27 ./configure --prefix=/usr/local/apache2 //指定安装目录 --enable-mods-shared=most //也可以是all不过不安全 --enable-so make && make install /usr/local/apache2/bin/apachectl start ps -aux |grep httpd netstat -lnp |grep 80
更改配置文件,不报servername的错误
PHP
apache将php当作一个模块调用:--enable-so :安装扩展模块
有一些包没有的话,安装PHP要依赖的包,要先安装一下epel源: yum install -y epel-release
比如: yum install -y libjpeg-devel
不知道包名可以yum list一下
yum list |grep -i mcrypt yum install mcrypt-y
make的过程:把源代码文件gcc成可执行文件
php执行文件 解析php文件: /usr/local/php/bin/php xx.php
列出PHP已经安装的模块 小写m -m: /usr/local/php/bin/php -m
查看php的参数,跟phpinfo()网页输出一样 -i: /usr/local/php/bin/php -i
可以查看编译选项
可以查看配置文件路径
可以查看配置文件是否加载
php配置文件
php.ini-development
php.ini-production
步骤
安装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 //一定要加 结合apache 要先安装perl否则会报错 --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql //一定要加 结合mysql --with-libxml-dir --with-gd // 网站验证码需要用到,验证码有问题需要检查是否有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 make && make install ls /usr/local/src/php-5.3.28/php.ini-development cp /usr/local/src/php-5.3.28/php.ini-development /usr/local/php/etc/php.ini //将php.ini从源码包拷贝过来 /usr/local/php/bin/php -i |grep -i loaded configuration //查看是否已经加载php.ini /usr/local/apache2/bin/apxs -i -a -c mod_status.c //apache安装扩展模块需要用apxs 这个文件
apache和php结合
/usr/local/apache2/bin/conf/httpd.conf
查看静态已加载模块 -l: /usr/local/apache2/bin/httpd -l
查看加载的所有模块 -M : /usr/local/apache2/bin/httpd -M
/usr/local/apache2/bin/apachectl start /stop /restart /graceful /-t
/usr/local/php/bin/php xx.php
列出PHP已经安装的模块 -m: /usr/local/php/bin/php -m
查看php的参数-i: /usr/local/php/bin/php -i
查看是否已经加载php.ini文件: /usr/local/php/bin/php -i |grep -i loaded configuration
---------------------------------------
apache会自动加载php模块
在apache目录下查找php模块: ls /usr/local/apache2/modules/libphp5.so
查找apache的配置文件,是否有一行LoadModule php5_module modules/libphp5.so: /usr/local/apache2/bin/conf/httpd.conf
查看是否已经加载php模块: /usr/local/apache2/bin/httpd -M
配置apache结合php
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>
找到:
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
检查语法: /usr/local/apache2/bin/apachectl -t
最后重启: /usr/local/apache2/bin/apachectl restart
将1.php 放到 /usr/local/apache2/htdocs/下: mv 1.php /usr/local/apache2/htdocs/
测试: curl localhost/1.php
//phpinfo页面 1.php <?php phpinfo(); ?>
------------------------------------------------
排错
第一步检查模块
/usr/local/apache2/bin/apachectl -M |grep -i php
检查apache目录下是否有libphp5.so文件: /usr/local/apache2/modules/libphp5.so
php5 module
vi /usr/local/apache2/conf/httpd.conf
查看libphp5.so缺少了哪个依赖库文件
ldd命令检查: /usr/local/apache2/modules/libphp5.so
第二步检查类型是否加上addtype
看一下有无x-httpd-php .php: cat /usr/local/apache2/conf/httpd.conf |grep -i 'addtype'
第三步检查防火墙和selinux
selinux有没有关: getenforce
iptables -F && iptables-save
第四步重启apache
修改了httpd.conf必须要重启apache: /usr/local/apache2/bin/apachectl restart /graceful
不行的话先杀死apache再重启: killall httpd
MySQL初始化
apache安装
apache动态库
apache自带ab压测工具
查看php是否缺少某个功能模块
我安装的步骤
--安装mysql cd /download &&wget -c http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz //下载免编译包 tar -zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz //解压 mkdir -p /usr/local/mysql mv mysql-5.1.73-linux-x86_64-glibc23/ /usr/local/mysql useradd -s /sbin/nologin mysql //新建mysql用户 cd /usr/local/mysql mkdir -p /data/mysql //新建数据库数据目录 chown -R mysql:mysql /data/mysql //更改数据目录的属主属组 cd scripts //打开脚本目录 . mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql & //初始化 注意前面一点 表示执行脚本mysql_install_db echo $? cp support-files/my-large.cnf /etc/my.cnf //拷贝配置文件 vi /etc/my.cnf //修改配置文件 cp support-files/mysql.server /etc/init.d/mysqld //拷贝启动脚本 vi !$ //修改启动脚本 basedir=/usr/local/mysql ,datadir=/data/mysql chmod 755 /etc/init.d/mysqld //更改启动脚本权限 chkconfig --add mysqld chkconfig mysqld on //加入到系统服务列表并设置启动级别 chkconfig --list |grep mysql service mysqld start //启动mysql /usr/local/mysql/bin/mysql //检查mysql能否链接 ps -aux|grep mysql //是否有mysql进程 netstat -lnp|grep 3306 遇到的问题:FATAL ERROR: Could not find ./bin/my_print_defaults的解决办法 http://blog.haohtml.com/archives/9674
f
--安装apache cd /download &&wget -c http://archive.apache.org/dist/httpd/httpd-2.2.27.tar.bz2 & tar jvxf httpd-2.2.27.tar.bz2 cd httpd-2.2.27 mkdir -p /usr/local/apache2 yum install gcc -y ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so make && make install /usr/local/apache2/bin/apachectl start ps -aux |grep httpd netstat -lnp |grep 80 遇到的问题:安装Apache时./configure出现`/usr/local/src/httpd-2.2.21/srclib/apr`:的解决方法 没有安装gcc http://blog.sina.com.cn/s/blog_963086810100uyrb.html Making all in xml/expat make[3]: Entering directory `/download/httpd-2.2.27/srclib/apr-util/xml/expat' /bin/sh ./libtool --silent --mode=compile gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -o lib/xmlparse.lo -c lib/xmlparse.c /bin/sh ./libtool --silent --mode=compile gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -o lib/xmltok.lo -c lib/xmltok.c /bin/sh ./libtool --silent --mode=compile gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -o lib/xmlrole.lo -c lib/xmlrole.c /bin/sh ./libtool --silent --mode=link gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -no-undefined -version-info 5:0:5 -rpath /usr/local/apache2/lib -o libexpat.la lib/xmlparse.lo lib/xmltok.lo lib/xmlrole.lo make[3]: Leaving directory `/download/httpd-2.2.27/srclib/apr-util/xml/expat' make[3]: Entering directory `/download/httpd-2.2.27/srclib/apr-util' /bin/sh /download/httpd-2.2.27/srclib/apr/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/download/httpd-2.2.27/srclib/apr-util/include -I/download/httpd-2.2.27/srclib/apr-util/include/private -I/download/httpd-2.2.27/srclib/apr/include -I/download/httpd-2.2.27/srclib/apr-util/xml/expat/
f
--安装php cd /download &&wget -c http://cn2.php.net/distributions/php-5.3.28.tar.gz & tar zxf php-5.3.28.tar.gz cd php-5.3.28 mkdir -p /usr/local/php yum install -y libxml2-devel yum install -y openssl openssl-devel yum install -y bzip2 bzip2-devel yum install -y libmcrypt-devel ./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 make && make install echo $? mkdir -p /usr/local/php/etc/ ls /download/php-5.3.28/php.ini-development cp /download/php-5.3.28/php.ini-development /usr/local/php/etc/php.ini //将php.ini从源码包拷贝过来 /usr/local/php/bin/php -i |grep -i 'loaded configuration' //查看是否已经加载php.ini /usr/local/apache2/bin/apxs -i -a -c mod_status.c //apache安装扩展模块需要用apxs 这个文件 ---------------------------------------------------------- 解决方法:缺少libxml2-devel包 http://www.apelearn.com/study_v2/chapter17.html hecking whether to enable LIBXML support... yes checking libxml2 install dir... no checking for xml2-config path... configure: error: xml2-config not found. Please check your libxml2 installation. [root@steven php-5.3.28]# --prefix=/usr/local/php -bash: --prefix=/usr/local/php: 没有那个文件或目录 checking libxml2 install dir... no checking for xml2-config path... rpm -qa | grep libxml2 libxml2-python-2.7.6-17.el6_6.1.x86_64 libxml2-2.7.6-17.el6_6.1.x86_64 rpm -ql libxml2-2.7.6-17.el6_6.1.x86_64 /usr/bin/xmlcatalog /usr/bin/xmllint /usr/lib64/libxml2.so.2 /usr/lib64/libxml2.so.2.7.6 /usr/share/doc/libxml2-2.7.6 /usr/share/doc/libxml2-2.7.6/AUTHORS /usr/share/doc/libxml2-2.7.6/ChangeLog.gz /usr/share/doc/libxml2-2.7.6/Copyright /usr/share/doc/libxml2-2.7.6/NEWS /usr/share/doc/libxml2-2.7.6/README /usr/share/doc/libxml2-2.7.6/TODO /usr/share/man/man1/xmlcatalog.1.gz /usr/share/man/man1/xmllint.1.gz /usr/share/man/man3/libxml.3.gz yum install -y libxml2-devel [root@steven php-5.3.28]# echo $? [root@steven php-5.3.28]# ls /usr/local/php
F
--php和apache结合 /usr/local/apache2/bin/apachectl -M |grep -i php ldd /usr/local/apache2/modules/libphp5.so cat /usr/local/apache2/conf/httpd.conf |grep -i 'addtype' getenforce iptables -F && iptables-save /usr/local/apache2/bin/apachectl restart /usr/local/apache2/bin/httpd -l /usr/local/apache2/bin/httpd -M /usr/local/php/bin/php -m /usr/local/php/bin/php -i ls /usr/local/apache2/modules/libphp5.so vi /usr/local/apache2/conf/httpd.conf 配置apache结合php 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> 找到: 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 /usr/local/apache2/bin/apachectl -t //检查语法 vi /usr/local/apache2/htdocs/1.php killall httpd /usr/local/apache2/bin/apachectl start curl localhost/1.php //测试PHP能否解释 //phpinfo页面 1.php <?php phpinfo(); ?> ---------------------------------------------------------------------- http://bbs.chinaunix.net/thread-1952338-1-1.html httpd: Syntax error on line 100 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: undefined symbol: zend_ini_boolean_displayer_cb /usr/local/apache2/conf/httpd.conf里有写libphp5.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule php5_module modules/libphp5.so ldd /usr/local/apache2/modules/libphp5.so //ldd检查libphp5.so动态库文件无问题 cd logs cat error_log //查看apache错误日志 [Sun Oct 11 13:01:35 2015] [notice] Digest: generating secret for digest authentication ... [Sun Oct 11 13:01:35 2015] [notice] Digest: done [Sun Oct 11 13:01:35 2015] [notice] Apache/2.2.27 (Unix) DAV/2 configured -- resuming normal operations [Sun Oct 11 13:11:11 2015] [error] [client 192.168.0.101] File does not exist: /usr/local/apache2/htdocs/favicon.ico [Sun Oct 11 13:11:18 2015] [error] [client 192.168.0.101] File does not exist: /usr/local/apache2/htdocs/favicon.ico # /usr/local/apache2/bin/apachectl -t httpd: Syntax error on line 100 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: undefined symbol: zend_ini_boolean_displayer_cb
F
配置好apache的vhost之后,可以访问一下设置好的域名,看一下会不会弹出apache的测试页面
无问题的话,就可以安装Discuz! 之类的程序了
比如在浏览器里输入
http://www.123.com
F
安装好lamp之后,访问日志可能会报timezone问题
这时候修改一下php.ini文件里的date.timezone即可
grep date.timezone /usr/local/php-fpm/etc/php.ini
# grep date.timezone /usr/local/php-fpm/etc/php.ini
; http://php.net/date.timezone
;date.timezone =
date.timezone = 'Asia/Shanghai'
http://www.linuxidc.com/Linux/2013-07/86963.htm
php的常用扩展
# pwd
/usr/local/php-fpm/include/php/ext
[root@centos ext]# ll
total 68
drwxr-xr-x 3 root root 4096 Dec 18 14:56 date
drwxr-xr-x 2 root root 4096 Dec 18 14:56 dom
drwxr-xr-x 3 root root 4096 Dec 18 14:56 ereg
drwxr-xr-x 2 root root 4096 Dec 18 14:56 filter
drwxr-xr-x 3 root root 4096 Dec 18 14:56 gd
drwxr-xr-x 2 root root 4096 Dec 18 14:56 hash
drwxr-xr-x 2 root root 4096 Dec 18 14:56 iconv
drwxr-xr-x 2 root root 4096 Dec 18 14:56 json
drwxr-xr-x 2 root root 4096 Dec 18 14:56 libxml
drwxr-xr-x 4 root root 4096 Dec 18 14:56 mbstring
drwxr-xr-x 3 root root 4096 Dec 18 14:56 pcre
drwxr-xr-x 2 root root 4096 Dec 18 14:56 pdo
drwxr-xr-x 2 root root 4096 Dec 18 14:56 session
drwxr-xr-x 2 root root 4096 Dec 18 14:56 spl
drwxr-xr-x 3 root root 4096 Dec 18 14:56 sqlite3
drwxr-xr-x 2 root root 4096 Dec 18 14:56 standard
drwxr-xr-x 2 root root 4096 Dec 18 14:56 xml
iconv
mb_convert_encoding的
http://www.cnblogs.com/pinocchioatbeijing/archive/2012/03/20/2407869.html
1. 何为PDO?
PDO(PHP数据对象) 是一个轻量级的、具有兼容接口的PHP数据连接拓展,是一个PHP官方的PECL库,随PHP 5.1发布,需要PHP 5的面向对象支持,因而在更早的版本上无法使用。它所提供的数据接入抽象层,具有与具体数据库类型无关的优势,为它所支持的数据库提供统一的操作接口。目前支持的数据库有Cubrid、FreeTDS / Microsoft SQL Server / Sybase、Firebird/Interbase 6、IBM DB2、IBM Informix Dynamic Server、MySQL 3.x/4.x/5.x、Oracle Call Interface、ODBC v3 (IBM DB2, unixODBC and win32 ODBC)、PostgreSQL、SQLite 3 and SQLite 2、Microsoft SQL Server / SQL Azure等。由于PDO是在底层实现的统一的数据库操作接口,因而利用它能够实现更高级的数据库操作,比如存储过程的调度等。
unixODBC,这是Unix类操作系统的ODBC驱动程序管理器
f