linux php环境搭建教程-PHP问题

资源魔 40 0

linux php环境搭建的办法:起首猎取相干装置包;而后装置Apache和mysql;接着修正设置装备摆设文件“httpd.conf”;最初设置环境变量以及开机自启,并编译装置PHP便可。

1、猎取装置包

  • PHP下载地点:http://cn.php.net/distributions/php-7.2.6.tar.gz
  • Apache下载地点:http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.33.tar.gz
  • MySQL下载地点: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz

2、装置Apache

1. 依赖包装置

1) 装置编译器gcc、gcc-c++

yum install -y gcc gcc-c++

2) 装置依赖包expat-devel、zlib-devel、openssl-devel

yum install -y expat-devel zlib-devel openssl-devel

2) 装置依赖包apr

留意:假如依赖包没有存正在,则去网站找最新的包,改为相应版本号下载便可

wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.gz
tar zxvf apr-1.6.2.tar.gzcd apr-1.6.2
./configure --prefix=/usr/local/apr
make && make install

3) 装置依赖包apr-util

wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar zxvf apr-util-1.6.0.tar.gzcd apr-util-1.6.0
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

4) 装置依赖包pcre

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
tar zxvf pcre-8.41.tar.gzcd pcre-8.41
./configure --prefix=/usr/local/pcre
make && make install

留意:将apr、apr-util装置包拷贝到Apache装置包的srclib目次中

称号辨别定名为apr、apr-util,没有要前面的版本号

2. 装置进程

1) 解压Apache装置包

tar zxvf httpd-2.4.33.tar.gz

留意: 将apr、apr-util装置包拷贝到Apache装置包的srclib目次中

称号辨别定名为apr、apr-util,没有要前面的版本号

2) 编译、装置

cd httpd-2.4.28
./configure --prefix=/usr/local/server/apache \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-pcre=/usr/local/pcre \--with-mysql=shared,mysqlnd                                                                                    
--enable-so \
--enable-ssl \
--enable-deflate \
--enable-rewrite \
--enable-headers \
--enable-expires \
--disable-cgid\
--disable-cgi

3. 修正设置装备摆设文件httpd.conf

vim /usr/local/server/apache/conf/httpd.conf

去掉ServerName后面的 #

并将ServerName前面的网址改成localhost:80

4. 将httpd退出零碎效劳并设置开机自启

1) 将httpd退出零碎效劳

cp /usr/local/server/apache/bin/apachectl /etc/init.d/httpd

2) 修正/etc/init.d/httpd,正在第3行退出如下内容

# chkconfig: 345 85 15# description: Activates/Deactivates Apache Web Server

留意: 代码中的 # 不成以去掉

3) 设置零碎效劳开机自启

systemctl enable httpd

4) 启动Apache

service httpd start

3、装置MySQL

1. 装置前预备

1) 解压装置包

tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz mv mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/server/mysql

2) 创立用户以及用户组并调配相应的权限

groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql .   #留意前面有个点

2. mysql的初始化并做根本设置装备摆设

1) 初始化mysql

cd /usr/local/server/mysql
bin/mysqld \
--initialize \
--user=mysql \
--basedir=/usr/local/server/mysql \
--datadir=/usr/local/server/mysql/data \

留意 : 假如报错 , 则缺哪一个库yum装置便可 bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

yum install libaio

2) 设置装备摆设mysql

vim my.cnf  # 创立设置装备摆设文件

本示例仅保障mysql能够失常运转,更多设置装备摆设请参考民间文档阐明

[mysqld]skip-grant-tablesbasedir = /usr/local/server/mysqldatadir = /usr/local/server/mysql/dataport = 3306

将设置装备摆设文件软链接到 /etc/ 目次

rm -rf /etc/my.cnfln -s /usr/local/server/mysql/my.cnf /etc/my.cnf

3. 启动mysql并设置root用户明码

1) 启动mysql

support-files/mysql.server start  # 启动MySQLbin/mysql -uroot -p  # 这里间接回车,毋庸输出明码

2) 重置root用户明码

use mysql;
update user set authentication_string='' where user='root';
exit;

3 ) 删除了/etc/my.cnf文件的 skip-grant-tables , 重启mysql效劳

  support-files/mysql.server restart  #重启mysql

4 ) 用root用户进行登录

  mysql -u root -p  
  passwrod:间接回车

5 ) 应用ALTER修正root用户明码,初始化终了 。加入,应用新明码登录

  ALTER user 'root'@'localhost' IDENTIFIED BY 'new_password';

4. 设置环境变量以及开机自启

1) 设置环境变量

编纂profile文件

vim /etc/profile

增加下列信息到profile尾部

export PATH=$PATH:/usr/local/server/mysql/bin

使环境变量立刻失效

source /etc/profile

2) 设置开机自启

cp support-files/mysql.server /etc/init.d/mysqld  
systemctl enable mysqld

5. 防火墙设置

CentOS默许开启了 firewall 防火墙,上面咱们应用firewall开启3306l端口

1) 开启以前咱们先查问下3306端口能否开启

firewall-cmd --query-port=3306/tcp

2) 咱们能够抉择暂时开启或许永世开启3306端口

firewall-cmd --add-port=3306/tcp  # 暂时开启3306端口  firewall-cmd --permanent --zone=public --add-port=3306/tcp  # 永世开启3306端口

3) 重启firewall

firewall-cmd --reload

6. 近程拜访

1) 给予任何主机拜访mysql的权限

create user root@'%' identified by 'your_password';                                                           
grant all privileges on *.* to root@'%';

2) 使权限修正失效

FLUSH PRIVILEGES;

4、装置PHP

1. 装置步骤

1) 装置依赖包

yum -y install wget vim pcre pcre-devel openssl openssl-devel \
libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng \
libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib \
zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel \
curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel \
nss_ldap jemalloc-devel cmake boost-devel bison automake libevent \
libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt \
mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel \
libcurl libcurl-devel openjpeg-devel libcurl.x86_64 libcurl-devel.x86_64 \
libjpeg-turbo libjpeg-turbo-devel libpng freetype  libpng-devel \
freetype-devel icu libicu libicu-devel  openldap openldap-clients \
openldap-devel openldap-serverscp -frp /usr/lib64/libldap* /usr/lib/

2) 解压PHP装置包

tar zxvf php-7.2.6.tar.gz

3) 编译装置

cd php-7.2.6
./configure --prefix=/usr/local/server/php \
--with-apxs2=/usr/local/server/apache/bin/apxs \
--with-config-file-path=/usr/local/server/php \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-libmbfl \
--enable-ftp \
--with-gd \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \make && make install

2. 设置装备摆设php.ini

1) 将设置装备摆设文件拷贝到PHP装置目次

cp php.ini-* /usr/local/server/php/

2) 天生php.ini

cp php.ini-development /usr/local/server/php/php.inicp /usr/local/server/php/etc/php-fpm.conf.default /usr/local/server/php/etc/php-fpm.conf


3 ) 修正php.ini设置装备摆设文件

expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2
extension_dir = "/usr/local/server/php/lib/php/extensions/no-debug-zts-20170718/"



3. 修正httpd.conf

载入PHP模块,如httpd.conf中有下列代码则间接去掉后面#便可,不则退出

LoadModule php7_module modules/libphp7.so

正在底部退出如下代码使患上Apache能够解析php文件

<IfModule mod_php7.c>
	AddType application/x-httpd-php .php</IfModule>

找到以下代码,正在index.html前面退出index.php

<IfModule dir_module>
    DirectoryIndex index.html</IfModule>

重启Apache

service httpd restart

4. 测试PHP能否胜利装置

创立/usr/local/server/apache/htdocs/index.php

vim /usr/local/server/apache/htdocs/index.php

正在index.php中编写如下代码

<?php

   phpinfo();?>

假如呈现如下页面则装置胜利

MYSQL8.0装置后 phpMyAdmin无奈登岸处理

MYSQL8.0的明码验证形式从mysql_native_password改成了caching_sha2_password

vim my.cnf

default_authentication_plugin=mysql_native_password

进入mysql修正一下明码以及加密插件

use mysql;  
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';    
FLUSH PRIVILEGES;

以上就是linux php环境搭建教程的具体内容,更多请存眷资源魔其它相干文章!

标签: linux php教程 PHP7 php故障解决 php使用问题

抱歉,评论功能暂时关闭!