LAMP架构应用实战——PHP环境安装配置

2020-12-19 18:35

阅读:648

标签:evel   需要   退出   服务器配置   serve   please   off   device   编译安装   

LAMP架构应用实战——PHP环境安装配置

LAMP架构应用实战——PHP服务

PHP的安装依赖于前面的Apache和MySQL

一:安装环境准备

因些首先服务器上查看下是否安装以上两种服务
1、检查安装路径
[root@Centos /]# ls -ld /application/apache
lrwxrwxrwx. 1 root root 25 Sep 12 03:44 /application/apache -> /application/apache2.4.23
[root@Centos /]# ls -ld /application/mysql-5.1.72
drwxr-xr-x. 11 mysql mysql 4096 Sep 19 09:16 /application/mysql-5.1.72
2、查看服务是否启动
[root@Centos extra]# chkconfig --list|grep httpd
httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@Centos extra]# chkconfig --list|grep mysql
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3、查看端口
[root@Centos extra]# netstat -lnt|egrep "3306|80"
tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN
tcp 0 0 :::80 :::
LISTEN

二:安装配置所需的库文件

1、检查安装PHP所需要LIB库
[root@Centos tools]# rpm -qa Zlib-devel libxml2-evel libjpeg-devel freetype-devel libpng-devel
#没有显示表明系统没有安装相应的软件包
通过下面的命令进行安装
[root@Centos tools]# yum groupinstall "x software development"
同样也可以通过下面的命令安装
[root@Centos tools]# yum install zlib libxml libjpeg freetype libpng gd curl libiconv Zlib-devel libxml2-evel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
2、安装libiconv库
下载地址:http://ftp.gnu.org/pub/gnu/libiconv/
[root@Centos tools]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.7.tar.gz
--2016-09-20 01:34:01-- http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.7.tar.gz
Resolving ftp.gnu.org... 208.118.235.20, 2001:4830:134:3::b
Connecting to ftp.gnu.org|208.118.235.20|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://113.215.21.31:80/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/ftp.gnu.org/pub/gnu/libiconv/libiconv-1.7.tar.gz [following]
--2016-09-20 01:34:02-- http://113.215.21.31/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/ftp.gnu.org/pub/gnu/libiconv/libiconv-1.7.tar.gz
Connecting to 113.215.21.31:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2941046 (2.8M) [application/x-gzip]
Saving to: “libiconv-1.7.tar.gz”
100%[==========================>] 2,941,046 979K/s in 2.9s
2016-09-20 01:34:07 (979 KB/s) - “libiconv-1.7.tar.gz” saved [2941046/2941046]
解压编译安装
[root@Centos tools]# tar zxf libiconv-1.7.tar.gz
[root@Centos tools]# cd libiconv-1.7
[root@Centos libiconv-1.7]# ./configure --prefix=/application/libiconv
[root@Centos libiconv-1.7]# echo $?
0
[root@Centos libiconv-1.7]# make
[root@Centos libiconv-1.7]# echo $?
0
[root@Centos libiconv-1.7]# make install
[root@Centos libiconv-1.7]# echo $?
0

三:安装PHP

1、下载PHP软件
[root@Centos ~]# cd /Downloads/tools/
[root@Centos tools]# wget http://mirrors.sohu.com/php/php-5.4.22.tar.gz
--2016-09-19 23:20:34-- http://mirrors.sohu.com/php/php-5.4.22.tar.gz
Resolving mirrors.sohu.com... 221.236.12.140
Connecting to mirrors.sohu.com|221.236.12.140|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://113.215.21.25:80/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/mirrors.sohu.com/php/php-5.4.22.tar.gz [following]
--2016-09-19 23:20:39-- http://113.215.21.25/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/mirrors.sohu.com/php/php-5.4.22.tar.gz
Connecting to 113.215.21.25:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15311831 (15M) [application/octet-stream]
Saving to: “php-5.4.22.tar.gz”
100%[=======================>] 15,311,831 1.29M/s in 12s
2016-09-19 23:20:51 (1.20 MB/s) - “php-5.4.22.tar.gz” saved [15311831/15311831]
2、解压软件
[root@Centos /]# cd /Downloads/tools/
[root@Centos tools]# tar zxf php-5.4.22.tar.gz
3、编译安装PHP
[root@Centos php-5.4.22]# ./configure \

--prefix=/application/php-5.4.22 \
--with-apxs2=/application/apache/bin/apxs \
--with-mysql=/application/mysql-5.1.72 \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/application/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

checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@Centos php-5.4.22]# echo $?
1
[root@Centos php-5.4.22]# yum install libxml2 libxml2-devel -y
重新编译
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+-----------------------------------------+
| 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 poin|
+-----------------------------------------+
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --enable-zend-multibyte
[root@Centos php-5.4.22]# echo $?
0
[root@Centos php-5.4.22]# make
..........................................中间内容省略
Build complete.
Don‘t forget to run ‘make test‘.
[root@Centos php-5.4.22]# make install
..........................................中间内容省略
Installing PEAR environment: /application/php-5.4.22/lib/php/
[PEAR] Archive_Tar - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
[PEAR] PEAR - installed: 1.9.4
Wrote PEAR system config file at: /application/php-5.4.22/etc/pear.conf
You may want to add: /application/php-5.4.22/lib/php to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util - installed: 1.2.1
/Downloads/tools/php-5.4.22/build/shtool install -c ext/phar/phar.phar /application/php-5.4.22/bin
ln -s -f /application/php-5.4.22/bin/phar.phar /application/php-5.4.22/bin/phar
Installing PDO headers: /application/php-5.4.22/include/php/ext/pdo/
[root@Centos php-5.4.22]# echo $?
0

四:配置PHP

1、建立一个软链接
[root@Centos php-5.4.22]# ln -s /application/php-5.4.22 /application/php
[root@Centos php-5.4.22]# ls -l /application/php
lrwxrwxrwx. 1 root root 23 Sep 20 02:27 /application/php -> /application/php-5.4.22
2、查看配置文件
[root@Centos php-5.4.22]# ls php.ini
php.ini-development php.ini-production
将配置文件放到安装路径下
[root@Centos php-5.4.22]# cp php.ini-production /application/php/lib/php.ini
[root@Centos php-5.4.22]# ls /application/php/lib/php.ini
/application/php/lib/php.ini
3、配置Apache服务支持PHP
[root@Centos php-5.4.22]# cd /application/apache/conf/
[root@Centos conf]# ls
1.txt b.log extra httpd.conf httpd.conf.0918 httpd.conf.2016-09-09 httpd.conf.bak index.html magic mime.types original
[root@Centos conf]# cp httpd.conf httpd.conf.20160920
[root@Centos conf]# vi httpd.conf
可以查看下安装文件里面关于配置支持PHP的描述
[root@Centos php-5.4.22]# grep x-httpd-php .php INSTALL
grep: .php: No such file or directory
INSTALL: AddType application/x-httpd-php .php .phtml
INSTALL: AddType application/x-httpd-php-source .phps
INSTALL: AddType application/x-httpd-php .php
INSTALL: SetHandler application/x-httpd-php
INSTALL: SetHandler application/x-httpd-php
INSTALL: SetHandler application/x-httpd-php-source
INSTALL:RewriteRule (.
.php)s$ $1 [H=application/x-httpd-php-source]
INSTALL:type=magnus-internal/x-httpd-php exts=php
INSTALL:Service fn="php4_execute" type="magnus-internal/x-httpd-php" [inikey=value inike
INSTALL:
INSTALL:ObjectType fn="force-type" type="magnus-internal/x-httpd-php"
INSTALL: server and assign it the style x-httpd-php. All files in it will
INSTALL: AddType application/x-httpd-php .php
INSTALL: AddType application/x-httpd-php-source .phps
INSTALL:AddType application/x-httpd-php .php
INSTALL: replace the line AddType application/x-httpd-php .php with:
其实只需要增加如下即可

If the AddEncoding directives above are commented-out, then you

# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

修改默认用户

running httpd, as with most system services.

#
User php
Group php
默认是 deamon修改成PHP,可自由修改,如果用户不存在,需添加
修改默认首页文件

DirectoryIndex index.php index.html

默认只有index.html
保存退出后可对比下两个文件看看修改过的内容有哪些
[root@Centos conf]# diff httpd.conf httpd.conf.20160920
160,161c160,161

User daemon
Group daemon
249c249

DirectoryIndex index.html
378,379d377

五:测试配置

检查Apache语法与重启服务
[root@Centos conf]# /application/apache/bin/apachectl -t
AH00543: httpd: bad user name php
[root@Centos conf]# useradd php -s /sbin/nologin -M
[root@Centos conf]# /application/apache/bin/apachectl -t
Syntax OK
[root@Centos conf]# /application/apache/bin/apachectl graceful
查看进程与端口
[root@Centos conf]# lsof -i tcp:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 1866 root 4u IPv6 14604 0t0 TCP :http (LISTEN)
httpd 20498 php 4u IPv6 14604 0t0 TCP
:http (LISTEN)
httpd 20499 php 4u IPv6 14604 0t0 TCP :http (LISTEN)
httpd 20500 php 4u IPv6 14604 0t0 TCP
:http (LISTEN)
[root@Centos conf]# ps -ef|grep http
root 1866 1 0 02:22 ? 00:00:00 /application/apache2.4.23/bin/httpd -k start
php 20498 1866 0 03:05 ? 00:00:00 /application/apache2.4.23/bin/httpd -k start
php 20499 1866 0 03:05 ? 0:00:00 /application/apache2.4.23/bin/httpd -k start
php 20500 1866 0 03:05 ? 00:00:00 /application/apache2.4.23/bin/httpd -k start
root 20584 2091 0 03:05 pts/0 00:00:00 grep http
PHP会向httpd.conf添加模块
[root@Centos conf]# grep php httpd.conf
LoadModule php5_module modules/libphp5.so
User php
Group php
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
由于之前配置Apache 服务器配置了虚拟主机,所以现在访问默认站点目录肯定访问不了,所以在主配置文件中将虚拟主机功能暂时注释掉
[root@Centos conf]# grep httpd-vhosts /application/apache/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf
[root@Centos conf]# sed -i ‘s#Include conf/extra/httpd-vhosts.conf##Include conf/extra/httpd-vhosts.conf#g‘ /application/apache/conf/httpd.conf
[root@Centos conf]# grep httpd-vhosts /application/apache/conf/httpd.conf
#Include conf/extra/httpd-vhosts.conf
[root@Centos conf]# /application/apache/bin/apachectl -t
Syntax OK
[root@Centos conf]# /application/apache/bin/apachectl graceful
[root@Centos conf]# cd /application/apache/htdocs/
[root@Centos htdocs]# vi index.php
phpinfo();
?>
~
本地客户端浏览输入http://192.168.1.2
技术图片
技术图片
长按关注微信公众号——友侃有笑

LAMP架构应用实战——PHP环境安装配置

标签:evel   需要   退出   服务器配置   serve   please   off   device   编译安装   

原文地址:https://blog.51cto.com/mingongge/2555691


评论


亲,登录后才可以留言!