建网站框架LAMP之:PHP的安装
作者:互联网
下载并解压php7源码包:
https://www.php.net/downloads.php
2. 文件php-7.3.8.tar.gz放在/usr/local/src
3. tar -zxvf /usr/local/src/php-7.3.8.tar
4. mkdir /usr/local/zwk_php
mv /usr/local/src/php-7.3.8 /usr/local/zwk-php
5. cd /usr/local/zwk-php
./configure --prefix=/usr/local/zwk_php --with-apxs2=/usr/local/zwk_apache/httpd-2.4.41/bin/apxs --with-config-file-path=/usr/local/zwk_php/etc --with-mysql=/usr/local/zwk_mysql --with-pdo-mysql=/usr/local/zwk_mysql --with-mysqli=/usr/local/zwk_mysql/bin/mysql_config --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
在上一步编译PHP的过程中,我遇到了这些错误:
configure: error: xml2-config not found. Please check your libxml2 installation.
安装所需的包然后继续编译:
yum install -y libxml2-devel
configure: error: Cannot find OpenSSL’s <evp.h>
安装所需的包然后继续编译:
yum install -y openssl openssl-devel
configure: error: Please reinstall the BZip2 distribution
安装所需的包然后继续编译:
yum install -y bzip2 bzip2-devel
configure: error: jpeglib.h not found.
安装所需的包然后继续编译:
yum install -y libpng libpng-devel
configure: error: freetype-config not found.
安装所需的包然后继续编译:
yum install -y freetype freetype-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
安装所需的包然后继续编译:
yum install -y epel-release
yum install -y libmcrypt-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.
config.status: creating php7.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: main/php_config.h is unchanged
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mysql
出现这样的提示信息,这就说明PHP7配置编译参数完成。
由于没有设置swap大小或设置内存太小,编译程序会出现virtual memory exhausted: Cannot allocate memory的问题,可以用swap扩展内存的方法。
在执行free -m的是时候提示Cannot allocate memory:
(swap文件可以放在自己喜欢的位置如/var/swap)
[root@Byrd byrd]# free -m
total used free shared buffers cached
Mem: 512 108 403 0 0 28
-/+ buffers/cache: 79 432
Swap: 0 0 0
[root@Byrd ~]# mkdir /opt/images/
[root@Byrd ~]# rm -rf /opt/images/swap
[root@Byrd ~]# dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 82.7509 s, 25.3 MB/s
[root@Byrd ~]# mkswap /opt/images/swap
mkswap: /opt/images/swap: warning: don’t erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=59daeabb-d0c5-46b6-bf52-465e6b05eb0b
[root@hz mnt]# swapon /opt/images/swap
[root@hz mnt]# free -m
total used free shared buffers cached
Mem: 488 481 7 0 6 417
-/+ buffers/cache: 57 431
Swap: 999 0 999
内存太小,增加内存可以解决。
使用完毕后可以关掉swap:
[root@hz mnt]# swapoff swap
[root@hz mnt]# rm -f /opt/images/swap
swap文件也可以不删除,留着以后使用,关键是你的虚拟机硬盘够用。
接下来就是编译和安装:
make
make install
然后把配置文件放到/usr/local/php7/etc/目录下改名为php.ini:
cp php.ini-production /usr/local/php7/etc/php.ini
安装完成以后,我们可以查看:
#ls /usr/local/zwk_apache/httpd/modules/libphp*
/usr/local/apache2.4/modules/libphp7.so
查看httpd中有没有加载PHP模块:
/usr/local/zwk_apache/httpd /bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php7_module (shared)
可以看到,已经加载PHP7模块。
查看PHP7加载的模块(都是静态模块):
/usr/local/zwk_php/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
查看PHP信息:
/usr/local/zwk_php/bin/php -i
11.4 Apache和PHP结合
httpd的主配置文件是 /usr/local/zwk_apache/httpd/conf/httpd.conf,对于这个文件,我们要做4处修改:
vim /usr/local/zwk_apache/httpd /conf/httpd.conf #做下面修改
ServerName www.example.com:80
AllowOverride none Require all granted #目的是允许所有请求,如果不做修改则访问时候会显示403错误AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php #注意php和.php之间有空格
配置完成,保存退出。
可以测试一下配置语法是否正确:
/usr/local/zwk_apache/httpd /bin/apachectl -t
Syntax OK
说明配置语法没问题。
然后重新加载配置文件:
/usr/local/zwk_apache/httpd /bin/apachectl graceful
启动服务:
/usr/local/zwk_apache/httpd /bin/apachectl start
查看是否启动:
netstat -lntp | grep 80
tcp6 0 0 :::80 ::
标签:php,建网站,config,module,LAMP,usr,shared,PHP,local 来源: https://blog.csdn.net/ailloy888/article/details/99705195