以前是用phpstudy集成环境来开发php项目,现在想自己尝试一下手动搭建:
现在nginx很多衍生产品,最近进去找了好一会儿才找到:
下载地址:
http://nginx.org/en/download.html
这个也是和普通软件一样安装,最好是单独建个目录,待会儿和php,mysql装在一起,我就建了lnmp这个目录。
php程序下载地址:
https://windows.php.net/download/
直接解压就安装好了。
cp php.ini-development php.ini
需要开启几个拓展和配置:
extension_dir = "ext"
cgi.fix_pathinfo=1
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_mbstring.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_soap.dll
下载地址:
https://dev.mysql.com/downloads/mysql/
在mysql安装目录里面新建一个my.ini文件,输入内容如下:
[client]
port=3306
default-character-set=utf8
[mysqld]
basedir=D:\lnmp\mysql-5.7.26-winx64
datadir=D:\lnmp\mysqldata
port=3306
character_set_server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER
explicit_defaults_for_timestamp=true
max_connections=200
mysqld --initialize-insecure
这个命令会生成初始密码为空的root,我们可以直接登录。
以管理员省份打开cmd,进入mysql的执行文件目录
d:
cd D:\lnmp\mysql-5.7.26-winx64\bin
D:\lnmp\mysql-5.7.26-winx64\bin> mysqld --install
net start mysql #启动mysql服务
net stop mysql #停止mysql服务
命令:net start mysql
报错:mysql服务无法启动 3534
启动mysql报上面错
处理方法:清空my.ini设置的datadir目录下面的内容,用命令mysqld --initialize-insecure重新初始化,再次启动服务即可成功。
有的地方说使用** mysqld --initialize**进行初始化,这个命令会随机生成一个密码,在data目录下的 whdata.err文件里面,whdata是主机名
2017-07-12T16:48:31.042876Z 1 [Note] A temporary password is generated for root@localhost: =a=-iy/yZ3jl
root@localhost: 后面就是密码,=a=-iy/yZ3jl
登录数据库后重新设置密码:
set password for root@localhost = password(‘root’);
将mysql数据库root用户的密码更改为mysql
更改密码方法二:
mysqladmin -u root -p password root123
root123为将要改的新密码,输入上面命令后会提示你输入原来密码,输入原来密码后更改成功,退出后可用新密码登录。
1、选择数据库
use mysql
2、开启某个用户的远程连接权限
GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;
此命令可以更改远程连接的设置。
3、验证是否修改成功
select host,user from user;
https://dev.mysql.com/doc/refman/5.7/en/windows-start-command-line.html
如果有线上测试环境,这一步可以省了。我就聪明的省了,直接花几块钱买个虚拟机,会给你个100M的在线mysql数据库,以前是6块钱。
或者使用docker来跑mysql也很方便,但是windows下面docker问题蛮多,我就碰到docker经常起不来的尴尬情况。
参考:
https://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html
https://blog.csdn.net/DBDeep/article/details/75193945
我们需要在后台运行的时候隐藏cmd窗口,不至于关掉cmd,php就停了。用到下面这个软件:
RunHiddenConsole.zip,下载地址:
https://redmine.lighttpd.net/attachments/660/RunHiddenConsole.zip
以上弄好之后,我们就需要写个脚本,在开启nginx服务的时候在后台启动php-cgi,脚本内容如下:
在nginx目录下面新建start_nginx.bat,内容如下:
@echo off
REM Windows 下无效
REM set PHP_FCGI_CHILDREN=5
REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
D:\lnmp\nginx-1.17.0\RunHiddenConsole D:/lnmp/php-7.1.30-Win32-VC14-x64/php-cgi.exe -b 127.0.0.1:9000 -c D:/lnmp/php-7.1.30-Win32-VC14-x64/php.ini
echo Starting nginx...
D:\lnmp\nginx-1.17.0\RunHiddenConsole D:/lnmp/nginx-1.17.0/nginx.exe -p D:/lnmp/nginx-1.17.0
这时候我们双击这个脚本,nginx和php服务就起来了。
我现在想要开机的时候自动启动ngixn和php服务,我们把上面那个文件移动到开机启动目录即可。
windows 10 进到如下目录即可:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
也可以参考这个,另一种方式:
https://langliu.github.io/2018/08/26/Nginx在Windows下开机自动启动/
下载地址:
https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.zip
配置参考我的另外一篇文章:
https://blog.csdn.net/zhezhebie/article/details/93867466
同时启动多个php版本:
@echo off
taskkill /F /IM nginx.exe > nul
taskkill /F /IM php-cgi.exe > nul
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI 64位...
D:/lnmp/nginx-1.17.0/RunHiddenConsole D:/lnmp/php-7.1.30-Win32-VC14-x64/php-cgi.exe -b 127.0.0.1:9000 -c D:/lnmp/php-7.1.30-Win32-VC14-x64/php.ini
echo Starting PHP FastCGI 32位...
D:/lnmp/nginx-1.17.0/RunHiddenConsole D:/lnmp/php-7.1.30-nts-Win32-VC14-x86/php-cgi.exe -b 127.0.0.1:9001 -c D:/lnmp/php-7.1.30-nts-Win32-VC14-x86/php.ini
echo Starting nginx...
D:/lnmp/nginx-1.17.0/RunHiddenConsole D:/lnmp/nginx-1.17.0/nginx.exe -p D:/lnmp/nginx-1.17.0
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
expose_php = Off
max_execution_time = 30
max_input_time = 60
memory_limit = 1280M
error_reporting = E_ALL
;error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_STRICT
display_errors = On
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 20M
auto_prepend_file =C:/Users/user/AppData/Roaming/Composer/vendor/autoload.php
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
extension_dir = "ext"
enable_dl = Off
file_uploads = On
upload_max_filesize = 20M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_intl.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysqli.dll
extension=php_msgpack.dll
extension=php_oci8_12c.dll
extension=php_igbinary.dll
extension=php_redis.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
[CLI Server]
cli_server.color = On
[Date]
[filter]
[iconv]
[imap]
[intl]
[sqlite3]
sqlite3.defensive = 1
[Pcre]
[Pdo]
[Pdo_mysql]
pdo_mysql.cache_size = 2000
pdo_mysql.default_socket=
[Phar]
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[Interbase]
ibase.allow_persistent = 1
ibase.max_persistent = -1
ibase.max_links = -1
ibase.timestampformat = "%Y-%m-%d %H:%M:%S"
ibase.dateformat = "%Y-%m-%d"
ibase.timeformat = "%H:%M:%S"
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
[OCI8]
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[browscap]
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 144000
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = 1
[COM]
[mbstring]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[sysvshm]
[ldap]
ldap.max_links = -1
[mcrypt]
[dba]
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.max_wasted_percentage=5
opcache.use_cwd=1
opcache.validate_timestamps=1
opcache.revalidate_freq=2
opcache.revalidate_path=0
opcache.save_comments=1
opcache.fast_shutdown=0
opcache.enable_file_override=0
opcache.optimization_level=0xffffffff
opcache.inherited_hack=1
opcache.dups_fix=0
opcache.blacklist_filename=
opcache.max_file_size=0
opcache.consistency_checks=0
opcache.force_restart_timeout=180
opcache.error_log=D:/lnmp/logs/opcache_error.log
opcache.log_verbosity_level=1
opcache.preferred_memory_model=
opcache.protect_memory=0
opcache.restrict_api=
opcache.mmap_base=
opcache.file_cache=D:/lnmp/logs/opcache
opcache.file_cache_only=0
opcache.file_cache_consistency_checks=1
opcache.huge_code_pages=1
[curl]
[openssl]
[Date]
date.timezone = Asia/ShangHai
;php错误日志记录
error_log = D:/lnmp/logs/php_errors.log
zend_extension=php_opcache.dll