PHP installation configuration (Windows and Linux)-one is enough

PHP


PHP stands for "Hypertext Preprocessor" and is a universal open source scripting language. PHP is a scripting language executed on the server side, similar to the C language, and is a commonly used website programming language. PHP's unique syntax is a mixture of C, Java, Perl, and PHP's own syntax. Conducive to learning, widely used, mainly suitable for the field of Web development.
Originally an abbreviation of Personal Home Page, it has been officially renamed "PHP: Hypertext Preprocessor"

LAMP/LNMP series environment construction:
Student party white prostitution server-no, no, are you still buying a student computer?
Apache installation and configuration (Windows and Linux)
-you can install and configure MySql Linux-have you lost your studies?
PHP installation and configuration (Windows and Linux)-one article is enough.
Nginx installation and configuration (Window and Linux)-package teaching package.
I know there are integrated software and pagodas, but I want to take it step by step, knowing it, and knowing why .
You don't know that I have been tortured for a long time, and there are some pits that I have never stepped on before.

Windows


1. Download

Official website download address https://windows.php.net/download
Select the latest version to download
More versions such as different VC and Thread Safe are introduced in the left navigation.
Insert picture description here

2. Unzip

The file name can be changed to be more concise
Insert picture description here

3. Configuration

Apache installation configuration can refer to here
Insert picture description here

#加载PHP
LoadModule php7_module 'D:/tools/php7/php7apache2_4.dll'

#将PHP配置文件加载到Apache配置文件中,共同生效
PHPIniDir 'D:/tools/php7'

#配置Apache分配工作给PHP模块,把PHP代码交给PHP处理
#即.php后缀名的文件
AddType application/x-httpd-php .php

Insert picture description here

4.php.ini file

The php.ini file of the above configuration does not exist by default. It exists in development and production formats and needs to be formatted.
Insert picture description here
Insert picture description here

5. Test configuration (this step can be skipped)

Restart the Apache service, open cmd, go to the Apache decompression directory/bin, and enter the command

httpd -M

Insert picture description here

6. Test the PHP code

Insert picture description here
Insert picture description here

<?php
	//测试
	echo 'hello world';
?>

Start the Apache service, visit http://localhost/test.php in the browser , pay attention to the same as the file name So
Insert picture description here
far, all is good (~ ̄▽ ̄)~

Linux


Execute the following commands in sequence

1. Download and unzip

cd /usr/local/src/ #切换目录
wget http://cn2.php.net/distributions/php-7.4.10.tar.bz2 #下载
wget http://xmlsoft.org/downloads.html/
tar jxvf php-7.4.10.tar.bz2 #解压

Insert picture description here

2. Installation

cd /usr/local/src/php-7.4.10
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=mysqlnd --with-mysqli --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 --enable-fpm

When you execute configure, it will report Error, saying XXX not found, etc., and you can install it accordingly until it is correct

  • Package ‘libxml-2.0’, required by ‘virtual:world’, not found
    yum install -y libxml2-devel
  • Package ‘openssl’, required by ‘virtual:world’, not found
    yum install -y openssl openssl-devel
  • Package ‘sqlite3’, required by ‘virtual:world’, not found
    yum install sqlite-devel
  • configure: error: Please reinstall the BZip2 distribution
    yum install -y bzip2 bzip2-devel
  • Package ‘krb5’, required by ‘virtual:world’, not found
    yum install krb5-devel
  • Package ‘libcurl’, required by ‘virtual:world’, not found
    yum install libcurl-devel
  • Package ‘libjpeg’, required by ‘virtual:world’, not found
    yum install libjpeg-devel
  • Package ‘libzip’, required by ‘virtual:world’, not found
    yum install libzip-devel
  • Package ‘libxslt’, required by ‘virtual:world’, not found
    yum install libxslt-devel
  • Package ‘freetype2’, required by ‘virtual:world’, not found
    yum install freetype-devel
  • Package ‘libpng’, required by ‘virtual:world’, not found
    yum install libpng-devel
  • Package ‘oniguruma', required by'virtual:world', not found ( this is a bit troublesome )
cd /usr/local/src/
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxvf oniguruma-6.9.4.tar.gz
yum install autoconf automake libtool #有询问输入y
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install

Insert picture description here

3.php.ini

Copy and format php.ini, same as Windows

cp php.ini-development php.ini /usr/local/php7/ #拷贝
cp php.ini /usr/local/php7/
/usr/local/php7/bin/php -m #查看PHP加载模块
/usr/local/apache2.4/bin/apachectl -M #查看httpd加载模块

Insert picture description here

4. Configure Apache

vim /usr/local/apache2.4/conf/httpd.conf #编辑配置文件
#修改以下四点
#1.ServerName 195行
ServerName www.example.com:80
#2.Directory 204行
<Directory />
    AllowOverride none
    Require all granted
</Directory>
#3.DirectoryIndex 253行
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
#4.AddType 391行
AddType application/x-httpd-php .php

:wq #保存退出(先按ESC)
/usr/local/apache2.4/bin/apachectl -t #测试配置语法
/usr/local/apache2.4/bin/apachectl graceful #重新加载配置文件

Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here

5. Start the service

/usr/local/apache2.4/bin/apachectl start
ps -ef|grep httpd #查看httpd进程
netstat -lntp|grep 80 #查看80端口
curl localhost #测试

Insert picture description here

6. Test

iptables -I INPUT -p tcp --dport 80 -j ACCEPT #开放80端口或配置服务器安全组
vim /usr/local/apache2.4/htdocs/test.php #编辑测试文件
<?php
	phpinfo();
?>
:wq #保存退出(先按ESC)

Insert picture description here
You can succeed by following this step.

The original is not easy, please do not reprint ( this is not a wealthy visits worse ) the
blogger's homepage: https://blog.csdn.net/qq_45034708
If the article is helpful to you, remember to follow, like and collect ❤

Guess you like

Origin blog.csdn.net/qq_45034708/article/details/108542598