windows下手动配置nginx+php+mysql环境,并且开机自动启动

网友投稿 1618 2022-09-28

windows下手动配置nginx+php+mysql环境,并且开机自动启动

windows下手动配置nginx+php+mysql环境,并且开机自动启动

以前是用phpstudy集成环境来开发php项目,现在想自己尝试一下手动搭建:

1.安装nginx

现在nginx很多衍生产品,最近进去找了好一会儿才找到: -:​​​ 这个也是和普通软件一样安装,最好是单独建个目录,待会儿和php,mysql装在一起,我就建了lnmp这个目录。

2.安装php

php程序-:​​​ 直接解压就安装好了。

复制开发环境ini为默认配置文件

cp php.ini-development php.ini

需要开启几个拓展和配置:

extension_dir = "ext"cgi.fix_pathinfo=1extension=php_curl.dllextension=php_fileinfo.dllextension=php_mbstring.dllextension=php_openssl.dllextension=php_pdo_mysql.dllextension=php_soap.dll

到这里,php就配置好了。

3.安装mysql

-:​​​ --initialize-insecure

这个命令会生成初始密码为空的root,我们可以直接登录。

注册windows服务

以管理员身份打开cmd,进入mysql的执行文件目录

不是管理员会报错:

Install/Remove of the Service Denied!

如果出错一定要清理掉data下面的文件,不然初始化会报错,说data里面已经有数据存在。

d:cd D:\lnmp\mysql-5.7.26-winx64\binD:\lnmp\mysql-5.7.26-winx64\bin> mysqld --install

然后会提示服务注册成功。这会让mysql开机自动启动。

net start mysql #启动mysql服务net stop mysql #停止mysql服务

命令:net start mysql 报错:mysql服务无法启动 3534 启动mysql报上面错 处理方法:清空my.ini设置的datadir目录下面的内容,用命令mysqld --initialize-insecure重新初始化,再次启动服务即可成功。

使用下面的命令可以直接在输出上面看到密码:

mysqld --initialize --console

注意:

有的地方说使用** 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

重置mysql密码

登录数据库后重新设置密码:

set password for root@localhost = password(‘root’);

将mysql数据库root用户的密码更改为mysql

更改密码方法二:

mysqladmin -u root -p password root123

mysql8.0使用:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456$%'; FLUSH PRIVILEGES;

root123为将要改的新密码,输入上面命令后会提示你输入原来密码,输入原来密码后更改成功,退出后可用新密码登录。

开启远程登陆

1、选择数据库

use mysql

2、开启某个用户的远程连接权限

GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘root’ WITH GRANT OPTION;

此命令可以更改远程连接的设置。 3、验证是否修改成功

select host,user from user;

​​或者使用docker来跑mysql也很方便,但是windows下面docker问题蛮多,我就碰到docker经常起不来的尴尬情况。

我们需要在后台运行的时候隐藏cmd窗口,不至于关掉cmd,php就停了。用到下面这个软件: RunHiddenConsole.zip,-:​​​ 在nginx目录下面新建start_nginx.bat,内容如下:

@echo offREM Windows 下无效REM set PHP_FCGI_CHILDREN=5REM 每个进程处理的最大请求数,或设置为 Windows 环境变量set PHP_FCGI_MAX_REQUESTS=1000echo 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.iniecho 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

也可以参考这个,另一种方式:​​​ ​

同时启动多个php版本:

@echo offtaskkill /F /IM nginx.exe > nultaskkill /F /IM php-cgi.exe > nulset PHP_FCGI_MAX_REQUESTS=1000echo 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.iniecho 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.iniecho 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 = Onshort_open_tag = Offprecision = 14output_buffering = 4096zlib.output_compression = Offimplicit_flush = Offunserialize_callback_func =serialize_precision = -1disable_functions =disable_classes =zend.enable_gc = Onexpose_php = Offmax_execution_time = 30max_input_time = 60memory_limit = 1280Merror_reporting = E_ALL;error_reporting = E_ALL & ~E_WARNING & ~E_NOTICE & ~E_STRICTdisplay_errors = Ondisplay_startup_errors = Onlog_errors = Onlog_errors_max_len = 1024ignore_repeated_errors = Offignore_repeated_source = Offreport_memleaks = Ontrack_errors = Onhtml_errors = Onvariables_order = "GPCS"request_order = "GP"register_argc_argv = Offauto_globals_jit = Onpost_max_size = 20Mauto_prepend_file =C:/Users/user/AppData/Roaming/Composer/vendor/autoload.phpauto_append_file =default_mimetype = "text/html"default_charset = "UTF-8"doc_root =user_dir =extension_dir = "ext"enable_dl = Offfile_uploads = Onupload_max_filesize = 20Mmax_file_uploads = 20allow_url_fopen = Onallow_url_include = Offdefault_socket_timeout = 60extension=php_bz2.dllextension=php_curl.dllextension=php_fileinfo.dllextension=php_gd2.dllextension=php_intl.dllextension=php_ldap.dllextension=php_mbstring.dllextension=php_exif.dllextension=php_mysqli.dllextension=php_msgpack.dllextension=php_oci8_12c.dllextension=php_igbinary.dllextension=php_redis.dllextension=php_openssl.dllextension=php_pdo_mysql.dllextension=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 = 2000pdo_mysql.default_socket=[Phar][mail function]SMTP = localhostsmtp_port = 25mail.add_x_header = Off[SQL]sql.safe_mode = Off[ODBC]odbc.allow_persistent = Onodbc.check_persistent = Onodbc.max_persistent = -1odbc.max_links = -1odbc.defaultlrl = 4096odbc.defaultbinmode = 1[Interbase]ibase.allow_persistent = 1ibase.max_persistent = -1ibase.max_links = -1ibase.timestampformat = "%Y-%m-%d %H:%M:%S"ibase.dateformat = "%Y-%m-%d"ibase.timeformat = "%H:%M:%S"[MySQLi]mysqli.max_persistent = -1mysqli.allow_persistent = Onmysqli.max_links = -1mysqli.cache_size = 2000mysqli.default_port = 3306mysqli.default_socket =mysqli.default_host =mysqli.default_user =mysqli.default_pw =mysqli.reconnect = Off[mysqlnd]mysqlnd.collect_statistics = Onmysqlnd.collect_memory_statistics = On[OCI8][PostgreSQL]pgsql.allow_persistent = Onpgsql.auto_reset_persistent = Offpgsql.max_persistent = -1pgsql.max_links = -1pgsql.ignore_notice = 0pgsql.log_notice = 0[bcmath]bcmath.scale = 0[browscap][Session]session.save_handler = filessession.use_strict_mode = 0session.use_cookies = 1session.use_only_cookies = 1session.name = PHPSESSIDsession.auto_start = 0session.cookie_lifetime = 0session.cookie_path = /session.cookie_domain =session.cookie_=session.serialize_handler = phpsession.gc_probability = 1session.gc_divisor = 1000session.gc_maxlifetime = 144000session.referer_check =session.cache_limiter = nocachesession.cache_expire = 180session.use_trans_sid = 0session.sid_length = 26session.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=1soap.wsdl_cache_dir="/tmp"soap.wsdl_cache_ttl=86400soap.wsdl_cache_limit = 5[sysvshm][ldap]ldap.max_links = -1[mcrypt][dba][opcache]opcache.enable=1opcache.enable_cli=1opcache.memory_consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.max_wasted_percentage=5opcache.use_cwd=1opcache.validate_timestamps=1opcache.revalidate_freq=2opcache.revalidate_path=0opcache.save_comments=1opcache.fast_shutdown=0opcache.enable_file_override=0opcache.optimization_level=0xffffffffopcache.inherited_hack=1opcache.dups_fix=0opcache.blacklist_filename=opcache.max_file_size=0opcache.consistency_checks=0opcache.force_restart_timeout=180opcache.error_log=D:/lnmp/logs/opcache_error.logopcache.log_verbosity_level=1opcache.preferred_memory_model=opcache.protect_memory=0opcache.restrict_api=opcache.mmap_base=opcache.file_cache=D:/lnmp/logs/opcacheopcache.file_cache_only=0opcache.file_cache_consistency_checks=1opcache.huge_code_pages=1[curl][openssl][Date]date.timezone = Asia/ShangHai;php错误日志记录error_log = D:/lnmp/logs/php_errors.logzend_extension=php_opcache.dll

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:国外网盘
下一篇:通过FeignClient如何获取文件流steam is close问题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~