LAMP宿主机安装-php环境

徘徊边缘 提交于 2020-07-28 04:16:56

1. httpd 安装 rpm包

yum install httpd

systemctl start httpd

httpd -v

Server version: Apache/2.4.6 (CentOS)
Server built:   Apr  2 2020 13:13:23

 

2. mysql 安装rpm包

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

yum -y install mysql-community-release-el7-5.noarch.rpm

yum install mysql-community-server

此中含有依赖( mysql-community-libs  mysql-community-devel),有此两个libs和devel,php configure时mysql目录编译可不指定

mysql --version

mysql  Ver 14.14 Distrib 5.6.48, for Linux (x86_64) using  EditLine wrapper

此中,/usr/bin/apxs 安装包

yum install -y httpd-devel

 

3. PHP安装

wget http://cn2.php.net/distributions/php-5.6.30.tar.gz  ( 下载速度过慢,建议本地浏览器下载上传 )

php依赖

yum -y install libxml2 libxml2-devel curl curl-devel openssl openssl-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel gmp-devel mysql-devel ncurses ncurses-devel unixODBC-devel net-snmp-devel libmcrypt libmcrypt-devel net-snmp mhash-devel

yum -y install openldap openldap-devel

yum -y install libxslt-devel    # libxslt相关组件

yum install -y perl*(以上仍报错,用这个,此命令包1600左右)

 

./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip

make && make install

配置相关php.ini配置
首先我们需要配置的是php.ini这个文件

安装目录有2个文件:php.ini-development和php.ini-production
php.ini-production 线上版本使用
php.ini-development 开发版本使用

我们选择development进行配置
cp php.ini-development /usr/local/php/lib/php.ini

php-fpm配置

拷贝php-fpm配置文件
cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf


4. 设置php-fpm脚本启动并且开机自启动

将php给我们准备好的init.d.php-fpm。
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

将php-fpm服务添加到chkconfig列表
chkconfig --add php-fpm

设置开机自启动
chkconfig php-fpm on

以后重启和停止php的方式为
service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload

 

5. 配置httpd添加php模块

cat /etc/httpd/conf/httpd.conf

1> ServerName开启

ServerName www.example.com:80      #根据需求开启

2> 将Require all denied 改为Require all granted
<Directory />
    AllowOverride none
    Require all granted
</Directory>

3> 增加一行AddType application/x-httpd-php .php
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php

4> 增加索引页index.php
在DirectoryIndex index.html后面 增加索引页index.php
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

重启httpd

 

6. 测试php安装效果

cat > /var/www/html/phpinfo.php <<EOF

<?php phpinfo(); ?>

EOF

curl http://localhost/phpinfo.php 

或者浏览器访问公网ip

 

#############################################################################################

 

 

附加  nginx-php 配置

nginx主配置文件
location ~ \.php$ {
    root                 html;
    fastcgi_pass         127.0.0.1:9000;
    fastcgi_index        index.php;
    fastcgi_param        SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    include              fastcgi_params;
}

nginx主目录
server {
    listen        80;
    server_name   localhost;

    location / {
        #root    html;
        root     /var/www/html;
        index    index.html index.htm
    }

}

然后重启nginx,并测试

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!