Painless installation and initial configuration PHP 8.0.3 + Apache 2.4 + MySQL 8.0


foreword

The computer configuration used in this blog is as follows

/*------------------------------------------------------
服务器型号:DELL R710
CPU:E5530 * 2
RAM:16GB DDR3 1333 Mhz ECC
硬盘:320GB SATA *4 (组RAID 10)
阵列卡:H700
SystemOS:Windows Server Datacenter 2019 with GUI
-------------------------------------------------------*/

Through this blog you can complete the installation of MySQL 8.0.23, Apache 2.4 and PHP 8.0.3.

And be able to complete the basic configuration between these components, allowing your website/service to complete database access, accessing your website through other computers, and solving cross-domain problems.


MySQL 8.0.23 installation

download

Go to the official website to download: https://dev.mysql.com/downloads/mysql/

The current latest version is MySQL 8.0.23

There are two installation methods on Windows, one is to decompress the zip compressed file and then configure it, and the other is to install it with a graphical interface.

Here choose the first method to install:

insert image description here
After the download is complete, it is transmitted to the server through the FTP service.

Install

unzip Program Files/MySQLinto
insert image description here

Add a mysql.inifile called and add the following content to the file

[mysql]
 
# 设置mysql客户端默认字符集
default-character-set=utf8 
 
[mysqld]
 
#设置3306端口
port = 3306 
 
# 设置mysql的安装目录
basedir=path
 
# 设置mysql数据库的数据的存放目录
datadir=path\data
 
# 允许最大连接数
max_connections=200
 
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
 
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

The path should correspond to your actual installation path

Configure environment variables

In the Windows Server DC version (I guess it is the same in Windows 10)

My Computer--"Right-click Properties--"Advanced System Settings--"Environment Variables

Add a new record in the system environment variable , the content is as follows (the last one,It must be the bin directory in your installation path):
insert image description here

Initialize MySQL

After that, initialize MySQL

Open CMD as an administrator in the installation path

mysqld --initialize --console

Note that a temporary password will be generated here, copy it out

Find a reference picture (I didn’t take a screenshot here)
insert image description here
the temporary password after the colon of this localhost

Next, install MySQL

mysqld --install mysql

Start MySQL without error

net start mysql

Here you need to change the password after the first installation is complete

mysql -u root -p

Log in with your initial password at this time

Change the password with the following command

ALTER USER 'root'@'localhost' IDENTIFIED BY '你要设置的新的密码';
 
flush privileges;

Log out and log in with the new password.

So far, MySQL is installed


PHP8.0.3 installation

download

Go to the official website to download https://windows.php.net/download

Remember to downloadThread SafeVersion, otherwise the Apache service cannot be connected later

After the download is complete, upload it to the server through the FTP serviceinsert image description here

Here I recommend decompressing the file directly into Program File (the name of the folder here is not the name after decompression this time, because the original installation is the none Thread Safe version, so when I configured the Apache server, I found that the necessary components were missing. , I searched online for a long time but didn’t say it was a version problem, until I saw a post on Stack Overflow about how to configure PHP and Apache servers, then I knew it was a version problem)

insert image description here

Install

Change php.ini.developmentthe file name of the file php.ini(it is recommended to copy and back up php.ini.developmentthe file first) insert image description here
and then open CMD in the decompression path, and run the following command

php.exe -v

The version number will be output here, indicating that it can be run
insert image description here

Configure environment variables

Add the decompression path to the environment variable insert image description here
, restart the computer, start the CMD window under a random path, and run the following command

php -v

Output the version number, which indicates that PHP has been installed correctlyinsert image description here


Apache 2.4 installation

download

Go to the official website to download: https://www.apachelounge.com/download/

Choose 64-bit for installation here (it’s not true that someone’s server is running a 32-bit system...)
insert image description here

It is the option of Apache 2.4.46 Win64

Install

After the download is complete, unzip the file

Note, there are two decompression methods here, one is to find a random place to decompress, and the other is to directly decompress to the root directory of the C drive.

Here I recommend decompressing directly to the root directory of the C drive. The easiest way is to run the Apache server without modifying the configuration file. It is very suitable for novices to operate. As for the problem of taking up space on the C drive...my server has only one partition, so don't worry about it question.

The content of the directory after decompression is as follows (sorry I forgot to take a screenshot...)

/*-------------------------------
 * Apache24				文件夹
 * -- Win64 VS16 --		其他文件
 * ReadMe.txt			txt文件
-------------------------------*/

There are steps in the ReadMe.txt here to guide us to install and configure the Apache server.

Apache24Copy this folder directly to the root directory of the C drive here .

It doesn't matter if you don't want to copy the folder to the root of the C drive.

Apache24\conf\httpd.confWe open the file with a text editor

Search for Define SRVROOT, and then change the address to your installation directory.One thing to pay attention to here! ! ! Be sure to replace "" in your installation path with "/", otherwise it will be invalid! ! !

start up

Enter your installation directory, == start CMD with administrator status ==, enter the following command

httpd.exe -k install

Successfully set up automatic operation at startup

At this time, use the shortcut key Win + R to enter service.msc to open the service

If you see Apache2.4 and the startup type is automatic, it means that the automatic operation setting at startup has been completed.

We can see a feather icon in the taskbar.
insert image description here
Double-click the icon to open the Apache monitor, where you can control the start, stop and restart of the Apache server.

The interface is shown in the figure below:

insert image description here

test

Enter localhost in the address of the browser and press Enter to display It Works! , indicating that the installation was successful!
insert image description here

into our own pages

We can replace the index.html in htdocs in the installation directory with our own web content, and then we can access it with a browser.


Configure Apache, PHP, MySQL

<OS 10013> An attempt was made to access a socket in a manner not permitted by the access privileges

When I installed the boot self-starting service, this error occurred, and the content of the prompt was

make_sock: could not bind to address 0.0.0.0:80

Because IIS is installed on my server, port 80 has been occupied.

Here we need to open the Apache configuration file.

The configuration file is conf/httpd.conf in the installation directory

After opening, find Listen 80, here change 80 to 88 or other unoccupied ports, I changed the configuration here to port 88

Save it, and then install the auto-run service at startup.

After that, restart the Apache service in the Apache monitor, visit localhost:88 in the browser, and find that it can run, and the problem is solved!

Apache cannot be accessed by other computers except this machine

There are two steps here. First, open the Apache configuration file and find the following:

<Directory>

Require local

</Directory>

Change Require local to Require all granted.
If your configuration file does not contain this content, but deny or something, change that line to Require all granted.

The second step, firewall settings

Control Panel--"Windows Firewall--"Advanced Settings

clickinbound rules,Thennew rule.
Select port, next step, select TCP, inspecific local portFinally, fill in the port of the Apache service you set (Listen in the Apache configuration file), and then go to the next step and finish. Restart the computer, problem solved.

Let Apache support PHP


insert image description here
The first step is to modify the php.ini file and extension_dirchange the latter to your installation path and add "/ext"

Also, you can add some modules according to your own needs (this is my added module, which is the ones with ";" removed)

extension=bz2
extension=curl
;extension=ffi
;extension=ftp
extension=fileinfo
extension=gd
extension=gettext
;extension=gmp
extension=intl
;extension=imap
;extension=ldap
extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
extension=odbc
extension=openssl
extension=pdo_firebird
extension=pdo_mysql
extension=pdo_oci
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop

Note here! ! !
If your website involves the operation of MySQL and you don't want the following screen to appear,
insert image description here
please be sure to remove the semicolon in front of extension=openssland ! extension=mysqli! !

The second step is to modify the Apache configuration file

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

更改为

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

Insert the following content at the appropriate position you think (insert at the end of all LoadModule)

#php support
LoadModule php_module "PATH/php8apache2_4.dll"
<IfModule dir_module>
	PHPIniDir "PATH/"
	AddType application/x-httpd-php .php
	AddType application/x-httpd-source .phps
</IfModule>

Note that here is a space followed by .phpPATH is your installation path

Also unlock several Modules

insert image description here
Image Source:

https://blog.csdn.net/qq_41189458/article/details/113624155?utm_term=apache24配置php8&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allsobaiduweb~default-0-113624155&spm=3001.4430

Add cross-domain (not adding this will affect access to the database)
insert image description here

After these configurations are complete, save and restart the server.


Summarize

It took me a whole week to install the Apache server this time. From Mac to Windows, I stepped on a lot of pits, but I didn't finish the pits. When you have configured to this step according to the steps, you can happily hang your website on the computer that has just been configured.

There is no end to technology. I hope you will face up to difficulties and solve various problems in the future. This article is just the beginning. I hope you will continue to work hard. come on! ! ! Technician! ! !

I hope all the gods can correct me in the comment area! ! !

Guess you like

Origin blog.csdn.net/qq_17790209/article/details/115679141