Home > Article > Backend Development > How to set up a php environment under win
How to build a php environment under win: 1. Download apache and configure it; 2. Download PHP and extract it to the php folder in the wamp directory; 3. Download and install mysql; 4. Modify the configuration file That’s it.
The operating environment of this article: Windows 7 system, PHP version 5.6, Dell G3 computer.
Building a PHP operating environment under window10
Before development, I have always used the PHP integrated environment (eg: phpstudy, xampp, etc.), but I have never tried to use PHP mysql Apache independently builds a PHP running environment locally, so I suddenly wanted to try setting it up today to see what troubles I might encounter along the way. First of all, the building tools we need are:
First of all, I installed apache,
apache download address http://www.apachelounge.com/download/, according to Your computer configuration download
#Determine whether the download is 32-bit or 64-bit based on your computer configuration. Here I created a wamp folder on the D drive and unzipped the downloaded apache in this directory. Next, run cmd as an administrator, then step by step into the d:\wamp\Apache\bin directory, and execute httpd -k install # in this directory. ##Command,
The first time I executed thehttpd -k install installation command, I encountered the problem shown above, which should be caused by httpd.confThe default path in the configuration file is wrong, you can manually rewrite it to your actual path.
During the process, I also encountered the situation where apache could not be installed. Later, I checked that the previously installed apache had been set as a system service and could be deleted. The deletion operation is as follows (note that it is also performed as an administrator): Operation: Enterservices.msc in the start bar , open the system service list: as shown
Of course, I also encountered other problems during this period: Right-clickApache2.4 in the above picture -》Properties
#It was found that the path of the executable file was wrong, or the path of the previous integrated environment (of course, this has been modified by me). This can be modified as follows: Enter"regedit" in the startup search barOpen the registry inHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services Find the required service Apache2.4 under \ and change its "ImagePath" key value to the actual path. Of course, the introduction here is only for the situation where your apache cannot be started. If you execute the
sc delete apache2.4command, you do not need to perform the above operations. When you finish executing httpd -k install and the following content appears, it means that your local apache has been successfully installed According to my judgment, the errors in the red box can be ignored Of course, you can also solve this error: localhost.localdomain. Set the 'ServerName' directive globally to suppress this message. The solution to this error when starting apache: Change the ServerName in the apache configuration file httpd.conf to an available domain name or configure ServerName as follows: localhost:80You enter
Installation reference link reference link
2.php installationDownload address: https://windows.php.net/ downloads/releases/然后将下载的文件解压到wamp目录下的php文件夹(不要下载非线程安全的版本,里面没有phpX(5,7)apache2_4.dll的拓展文件),配置apache的时候要用到。
接下来就是下载MySQL链接地址https://dev.mysql.com/downloads/mysql/,
我是下载的MySQL5.7版本的,根据你的操作系统下载32bit或者64bit
将下载的文件解压到wamp目录下的mysql文件夹。
打开D:/wamp/apache/conf文件夹下的httpd.conf文件
找到#LoadModule xml2enc_module modules/mod_xml2enc.so这一行,在这一行下面添加一下内容
PHPIniDir "C:/wamp/php5.6/" LoadModule php5_module "C:/wamp/php5.6/php5apache2_4.dll"
然后再找到 AddType application/x-gzip .gz .tg 这一行再下面添加
AddType application/x-httpd-php .php
apache的配置算是完成了。
然后再打开D:/wamp/php 文件夹下的php.ini-developement文件的文件名改为php.ini,然后对文件进行编辑,
; extension_dir = "./"
; On windows:
extension_dir = "d:/wamp/php5.6/ext"
date.timezone = Asia/Shanghai
取消此行的注释,并且填写ext文件夹的实际路径.
然后就是开启一些php的扩展文件
接下来就是配置MySQL了,打开进入到D:/wamp/mysql目录下新建my.ini配置文件,贴入一下内容
[mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mysqld] #设置3306端口 port = 3306 # 设置mysql的安装目录 basedir=D:\wamp\mysql # 设置mysql数据库的数据的存放目录 datadir=D:\wamp\mysql\data # 允许最大连接数 max_connections=200 # 服务端使用的字符集默认为8比特编码的latin1字符集 character-set-server=utf8 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB
以管理员的身份运行cmd,进入到D:/wamp/mysql/bin目录下安装MySQL服务,输入mysqld install(注意是mysqld不是mysql一定不要眼花)
命令行显示该行,表示安装成功
接下来输入mysqld --initialize创建data文件夹,否则后面无法启动MySQL服务;
然后输入net start mysql就可以启动MySQL服务了
输入mysql -u root -p,然后输入密码即可连接MySQL服务
可能会出现以下错误
这里现在下载的MySQL版本默认都不支持无密码验证,需要我们手动设置修改,打开my.ini文件,在文件末尾加上一句:
skip-grant-tables
然后重启MySQL(net stop mysql/net start mysql),此时可以不用密码进行连接,但许多功能受到了限制。先连接MySQL,然后选择user数据库修改root用户的密码。
update user set authentication_string=password("你设置的密码") where user = "root";
断开MySQL连接,将设置文件my.ini文件里刚刚加入的skip-grant-tables删除,重启MySQL服务,使用你设置的密码登陆。
推荐学习:《PHP视频教程》
The above is the detailed content of How to set up a php environment under win. For more information, please follow other related articles on the PHP Chinese website!