Install ngnix+Mysql+php running environment under Windows
Many friends don't want to use an integrated environment. They feel that the integrated environment takes up content, runs too many things and takes up resources. They like to configure some of their own environments.
(As long as the environment is suitable, if you find it troublesome under Windows, you can refer to this " How to quickly build a Web development environment, build a PHP development environment, and build an ngnix service environment on Linux ")
An article has been compiled below to teach you how to install the php running environment under window, ngnix+Mysql+php, and detect wnmp.
Preparation before installation:
1. System Windows 10
2. Nginx 1.20.2 download address: http://nginx.org/en/download.html
Note: It is recommended to choose the stable version. Pay attention to select the windows version
3. Mysql 5.7.35 download address: https://downloads.mysql.com/archives/community/
Note: Select the Windows version for version
4. PHP 7.4 download address: PHP: Downloads
Note: For the version, choose windows download, and it is recommended to choose the stable version.
start installation
1. Directory structure
In order to be more intuitive and clear, decompress Mysql, Nginx, php and other compressed packages into the wnmp directory. To be more intuitive, please check the directory structure . It mainly contains important directories and files.
wnmp ├─ mysql5.7 │ ├─ bin │ └─ my.ini ├─ nginx │ ├─ conf │ ├─ html │ └─ nginx.exe ├─ php │ └─ php74 │ └─ php.ini └─ wwwroot
2. Mysql installation
1. Create a new my.ini with content:
[mysqld] # Set port 3306 port=3306 #Set the installation directory of mysql #Set the storage directory for the data of the mysql database and configure it according to your own path basedir=D:/Wnmp/mysql5.7 #According to its own path configuration, data creates a folder for itself in the decompressed root directory. datadir=D:/Wnmp/mysql5.7/data #Maximum number of connections allowed max_connections=200 #The number of allowed connection failures. This is to prevent someone from trying to attack the database system from this host max_connect_errors=10 #The character set used by the server defaults to UTF8 character-set-server=utf8mb4 # The default storage engine that will be used when creating new tables default-storage-engine=INNODB # Use "mysql_native_password" plug-in authentication by default default_authentication_plugin=mysql_native_password [mysql] #Set the default character set of mysql client default-character-set=utf8mb4 [client] #Set the port used by default when the mysql client connects to the server port=3306 default-character-set=utf8mb4
2. Open the cmd command tool, enter the directory where mysql is decompressed, and execute the command. Note that the cmd command tool needs to be run in administrator mode, and execute the following command
#Enter directory # Install database mysqld --install # initialization mysqld --initialize --console
# Start service net start mysql # Log in to mysql mysql -uroot -p # By default there is no password and just press Enter Enter password: # Change the password to: 123456789 alter user root@localhost identified by '123456789';
3. Successful connection through remote tool
3. PHP installation
1. Modify the configuration file
After extracting the file to the directory, rename the php.ini-production configuration file to php.ini
Note: When starting the website, the php service must also be opened, and the port number needs to be consistent with the configuration, such as: run the command ./php-cgi.exe -b 127.0.0.1:9009
4. nginx installation
1. Run nginx
Enter the decompression directory and directly double-click to run nginx.exe. Run the service. If successful, open it in the browser: http://127.0.0.1/ and a welcome message will appear.
Summarize
1. The web service nginx has been started
2. Mysql service has been started
3. Unzip php, modify the configuration file php.ini, and start the php service php-cgi.exe -b 127.0.0.1:9009
Next, prepare how to create a new site locally and associate these.
Next we run a php file
1. Running PHP files does not require the Mysql service, so whether the database service Mysql is enabled or not will not affect it.
2. Nginx needs to start the service, just double-click nginx. It can be accessed through the browser: http://127.0.0.1 , which means success.
3. The default directory is the html directory under the nginx installation directory. Create a new php file inside, phpinfo.php
<?php phpinfo();?>
4. But when we accessed it directly through http://127.0.0.1/phpinfo.php , we found that we were downloading files because the php script was not configured.
Open the nginx.conf configuration file, open the comments as shown below, and restart nginx
Note: If you still download files after restarting, you can change the browser or clear the browser cache.
5. After configuring according to the above steps, when accessing http://127.0.0.1/phpinfo.php , an error occurs. An error occurred. This is because the php server has not been started yet.
Open the php installation directory php74, find php-cgi.exe , and execute the command. Pay attention to the port number. Then the error will not be displayed and the page can be opened.
php-cgi.exe -b 127.0.0.1:9000
Note: Downloading the PHP version for Windows will come with the php-cgi.exe file
6. If a blank page appears, or php reports an error, or No input file specified
Please check the nginx.conf configuration file to see if there is a problem with the php configuration, or replace it with this one
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
Access successful
Continuously updating...