How to setup php mysql on windows

Chocolatey to the rescue

Yes. Because the first thing that significantly changes between Windows and Linux or macOS is the package manager, they have apt, yum, yaourt, homebrew. Windows has nothing by default (but not for long, the future looks bright!). But here comes Chocolatey. Yes, it’s a package manager. Not official, it does not contain all the software you want. But well, it provides already a lot! For instance, you can install PHP, but also phpMyAdmin and MariaDB (which replace MySQL). To install Chocolatey, just follow the getting started, or run this command in a terminal (launched in mode administrator).

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 

Installing PHP

Actual installation

Now you have Chocolatey, we can install PHP. Run this in a terminal in administrator mode (right click on terminal / open as administrator):

Using PHP directly

You may ask why not installing a webserver like Apache or Nginx as well, the short answer is: you don’t need one. To run your project, use in the terminal the following command:

  1. php -S will start the PHP server (for development only)
  2. localhost:1337 represents the host and the port to listen on, if you want to expose the server you will probably need to use 0.0.0.0:1337
  3. The server points to the current directory by default, use the option -t to specify a folder
Читайте также:  Java encoding string to utf 8

You access your website on http://localhost:1337! ✨

If you’re using a router (a single entry point like many frameworks nowadays), you can also specify one:

php -S localhost:1337 index.php 

Bonus track: install composer

Composer is the package manager of PHP. And guess what, it’s also available in choco!

In a terminal as administrator:

Installing MariaDB

Just like PHP. It is super-super-easy, open a terminal in administrator (or use wsudo 😎) and type:

You’re all set. MariaDB is now available on your computer.

Installing phpMyAdmin

Installation

MariaDB will work with PHP as a replacement for MySQL perfectly. You can also use any MySQL client for that. For example, you can use PHPStorm internal client or MySQL Workbench!

But most of us are used to a very specific client (which is incredibly simple to use): phpMyAdmin.

Let’s install it, it’s just like the 2 previous tools!

choco install phpmyadmin # Do not forget to run it as administrator 

Configuration

phpMyAdmin requires some PHP extensions to be enabled before it works. This is documented in the readme of the package.

Go in the install directory of PHP (for me it’s C:\Tools\php. ), you can find it with the command php —ini . And copy/paste php.ini.development to php.ini .

Now edit this file and add (or uncomment) the following lines:

extension=mysqli extension=openssl 

Running phpMyAdmin

You’re all set. Just run the phpMyAdmin command (it runs a php server for you!), in your terminal type the following:

And that’s all folks! You have setup a complete workspace to build an application in PHP that uses MariaDB with phpMyAdmin client for MySQL! ✨

You can now access phpmyadmin in your browser on http://localhost:3333.

Ok, and why not WAMP?

WAMP is old. Outdated. For example, you can’t even get the very last version of PHP with WAMP.

But it also adds a webserver (apache), the default configuration is not bad to learn PHP, but when it comes to run modern applications. Well, it becomes a pain to configure properly.

The method I explain here is easy but also has a serious advantage: you understand what you’re doing (when WAMP is a complete package with a complex overhead).

Источник

How to setup php mysql on windows

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include:

For compiling, simply use the —with-mysql[=DIR] configuration option where the optional [DIR] points to the MySQL installation directory.

Although this MySQL extension is compatible with MySQL 4.1.0 and greater, it doesn’t support the extra functionality that these versions provide. For that, use the MySQLi extension.

If you would like to install the mysql extension along with the mysqli extension you have to use the same client library to avoid any conflicts.

Installation on Linux Systems

Note: [DIR] is the path to the MySQL client library files (headers and libraries), which can be downloaded from » MySQL.

ext/mysql compile time support matrix

PHP Version Default Configure Options: mysqlnd Configure Options: libmysqlclient Changelog
4.x.x libmysqlclient Not Available —without-mysql to disable MySQL enabled by default, MySQL client libraries are bundled
5.0.x, 5.1.x, 5.2.x libmysqlclient Not Available —with-mysql=[DIR] MySQL is no longer enabled by default, and the MySQL client libraries are no longer bundled
5.3.x libmysqlclient —with-mysql=mysqlnd —with-mysql=[DIR] mysqlnd is now available
5.4.x mysqlnd —with-mysql —with-mysql=[DIR] mysqlnd is now the default

Installation on Windows Systems

PHP 5.0.x, 5.1.x, 5.2.x

MySQL is no longer enabled by default, so the php_mysql.dll DLL must be enabled inside of php.ini . Also, PHP needs access to the MySQL client library. A file named libmysql.dll is included in the Windows PHP distribution and in order for PHP to talk to MySQL this file needs to be available to the Windows systems PATH . See the FAQ titled «How do I add my PHP directory to the PATH on Windows» for information on how to do this. Although copying libmysql.dll to the Windows system directory also works (because the system directory is by default in the system’s PATH ), it’s not recommended.

As with enabling any PHP extension (such as php_mysql.dll ), the PHP directive extension_dir should be set to the directory where the PHP extensions are located. See also the Manual Windows Installation Instructions. An example extension_dir value for PHP 5 is c:\php\ext

Note:

If when starting the web server an error similar to the following occurs: «Unable to load dynamic library ‘./php_mysql.dll'» , this is because php_mysql.dll and/or libmysql.dll cannot be found by the system.

PHP 5.3.0+

The MySQL Native Driver is enabled by default. Include php_mysql.dll , but libmysql.dll is no longer required or used.

MySQL Installation Notes

Crashes and startup problems of PHP may be encountered when loading this extension in conjunction with the recode extension. See the recode extension for more information.

Note:

If you need charsets other than latin (default), you have to install external (not bundled) libmysqlclient with compiled charset support.

Источник

How to setup Apache, PHP and MySQL on Windows 10

In this tutorial, you will learn about how you can setup Apache, PHP and MySQL server on Windows 10.

If you are planning to install Apache, MySQL and PHP on Windows 10, you have two options:

  1. you can download and install a free web development environment (WampServer, XAMPP)
  2. you can create your own environment by installing Apache, PHP and MySQL manually

For beginners I recommend the first option. For the second option you have to decide as to which version of each application will be installed. In this tutorial I am going to setup

Download the installation packages:

Apache 2.4 setup on Windows 10

  • Unzip the downloaded files to the C:\Apache24 directory if possible (this is the default ServerRoot directory in the Apache configuration file)
  • You can unzip to another location, but remember the path, you will have to change the SRVROOT variable in the http.conf file later
  • Install the Visual C++ Redistributable for Visual Studio 2015-2019 x64
  • After unzipping and installing the Visual C++ Redistributable package go to the C:\Apache24\conf directory and open httpd.conf in any text editor
  • If you unzipped the files to other location as C:\Apache24, change the path to your location in the line below:
#ServerName www.example.com:80 ServerName localhost
  • You are ready to go. I recommend to change the following lines too:
  • Change AllowOverride None to AllowOverride All to enable .htaccess files in your projects:
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None
#LoadModule rewrite_module modules/mod_rewrite.so

and remove the # from the beginning to enable the module:

LoadModule rewrite_module modules/mod_rewrite.so
  • To serve index.php file automatically if a directory is requested append index.php to the DirectoryIndex variable
 DirectoryIndex index.html index.php 

To test the installation, open up the command prompt, go to C:\Apache24\bin and run Apache by typing httpd.exe:

run apache from command prompt

If there is no error, open up a browser of your choice and go to http://localhost where you will see this page:

apache it works

To run Apache automatically on startup, register it as a service. Open the Command Prompt as administrator (right click -> Run as administrator) and type in these lines:

register apache as a service

Check Apache service in Services and click Start the service:

apache running

PHP 7.4 installation on Windows 10

  • Unzip the downloaded package to C:\php74
  • Go to the C:\php74 directory
  • Rename php.ini-development to php.ini
  • Add PHP 7.4 to system environment variable in Command Prompt:
  • Open the C:\Apache24\conf\httpd.conf apache configuration file again and add these lines to the end of the file:
PHPIniDir "C:/PHP74" AddHandler application/x-httpd-php .php LoadModule php7_module "C:/PHP74/php7apache2_4.dll"
  • To test the installation, create a file named phpinfo.php in C:\Apache24\htdocs directory and copy these lines to the file:

phpinfo

  • Open a browser of your choice and open http://localhost/phpinfo.php

MySQL 5.7 installation on Windows 10

  • Download the installer
  • Run the installer
  • In the first step pick server-only and hit Next

mysql installation server only

  • Download and install Microsoft Visual C++ 2013 Redistributable Package if you don’t have it already
  • After installing Microsoft Visual C++ 2013 Redistributable Package click Next again
  • If you downloaded the smaller package, click Execute in the third step and wait while the download ends
  • Click Next, the next step is Product Configuration
  • In the Product Configuration window click Next and pick the Standalone MySQL Server option in the first step
  • Click Next
  • In the Type and Networking step you can leave everything as it is (Config Type: Development Computer, Port: 3306), click Next again
  • Set your MySQL Root Password and go to the next step
  • Leave everything as it is in the next two steps (Next, then execute)
  • The installation is done, click Finish
  • Open Services and verify that the service named MySQL57 is running

mysql service running

  • If you are not comfortable with the command line, you can download and install MySQL Workbench, or install phpmyAdmin to manage your databases through a graphical user interface

Источник

Оцените статью