1

I would like to run PHP along with MYSql in VS Code as I would run using 'xammp'. I came across some extensions to use like IIS-Express and vscode-database but don't know how to configure and link them together.And which PHP would be suitable i.e. Thread safe or non Thread Safe.

PS: I am completely new to learn PHP and VS Code and want to use VS Code for every language I learn :)

Gama11
  • 31,714
  • 9
  • 78
  • 100
user7776333
  • 31
  • 1
  • 1
  • 5

1 Answers1

0

IIS Express is an extension that will basically run your project folder as a website. It's an extremely handy tool that I couldn't live without. Usage is simple, and noted below. I should also point out that IIS Express is only available for Windows and will not work on Linux or OSX.

  1. File > Open Folder
  2. Select the folder with your PHP and HTML within
  3. Install the IIS Extension from the extension menu. (Or with the command palette using "ext install iis-express")
  4. Open the command palette (CTRL + SHIFT + P)
  5. Type "IIS Express: Run Website"
  6. This starts the web server and will open a browser and connect to your website for testing.
  7. To stop the server, simply type the command a second time.

More information can be found here.


After looking around, it seems vscode-database does not host an actual database, but rather, gives you a way to test your queries in the editor. The information page for vscode-database doesn't make that very clear, though. So for MySQL functionality, you may want to look at running MySQL in a "portable mode". Instructions for this can be found here.

After getting that setup, you would just connect to it in php like any other MySQL database.

Community
  • 1
  • 1
Tyler C
  • 573
  • 5
  • 17
  • Thank you for the Answer. Can u tell me how to configure both extensions to work together (using mysql along with it) and which PHP type to go with as mentioned in the question. – user7776333 Mar 28 '17 at 13:28
  • For MySQL, you will still need a separate software for that. I couldn't find an extension that would add it. IIS Express just handles serving the web pages. You could run XAMMP alongside it if you wanted to or use a standalone MySQL in a "Portable" configuration. You can see here for info on how to do that. http://dba.stackexchange.com/questions/140187/is-there-a-portable-mysql If that works for you I'll update my answer with it. – Tyler C Mar 28 '17 at 15:59
  • I am sorry for being a complete noob but I have started vscode and php a day back. I saw a extension named vscode-database which is for MySQL. And I have only installed PHP and I configured PHP validation and now i don't know how how to configure tasks.json file. And one more dumb question, Is it necessary to get pho debugging application to make php work in vscode. – user7776333 Mar 28 '17 at 16:37
  • Everyone has to start somewhere, I never saw that database utility before so thanks for that one. Looks like it doesn't actually host an instance of MYSQL though. From what I can see it looks more like something to test your SQL commands with. (Still a useful tool) For your Json file, I'm sorry but you may want to open another stack overflow question for that one as I'm just not familiar with it. For the last question, you shouldn't need the pho debugger to make it work in visual studio. – Tyler C Mar 28 '17 at 16:44
  • I managed to configure tasks.json file and now PHP is working in VS Code. But I am facing some problems, first I wrote a simple code which worked fine. I just used echo "hello!"; in php tags and when i tried to add inside the echo to get bold text it just gave tags as such in the output. And then I tried to run program with IIS Express as to try output in browser but I got error message- "Running the contributed command: 'extension.iis-express.start' failed". – user7776333 Mar 28 '17 at 18:56
  • I'll be able to test it later tonight. I use Linux at work so I won't be able to test till later. Does it give additional info when it tells you it failed? – Tyler C Mar 28 '17 at 20:16
  • I just get a small popup at top stating a error message. – user7776333 Mar 28 '17 at 20:24
  • It was working for me. I tried the same thing you did. I would check the logs and see what you get. You can find them here: http://stackoverflow.com/questions/5798264/iisexpress-log-file-location If that doesn't help I would post another new question with the logs included to get the attention of someone who knows IIS a bit better than I do. – Tyler C Mar 29 '17 at 16:21
  • No log files are being created. Seems extension needs to be configured by user to set path directory for IIS Express where iisexpress.exe is located. – user7776333 Mar 30 '17 at 15:29
  • Same issues are being reported [here](https://github.com/warrenbuckley/IIS-Express-Code/issues/20) – user7776333 Mar 30 '17 at 16:13
  • It may just be part of the bug. I linked this issue over there so that someone who knows a bit more can see. – Tyler C Mar 30 '17 at 19:53
  • @user7776333 if you are experiencing this problem still. Can you move discussion over to GitHub issue for IS VSCode extension repo I created please. – Warren Buckley Mar 30 '17 at 21:53
  • @Warren Buckley The issue is already reported by someone there before. Should I report issue again? – user7776333 Mar 31 '17 at 14:15
  • Not as a new issue, but you should add as a comment to that same issue. – Tyler C Mar 31 '17 at 14:33
  • Yes please add as much detail to the issue: Version of VS Code OS Path to IISExpress on your machine The folder path that you are attempting to run the site from, wondering if file permissions issue when extensions tries to auto create .vscode/IISExpress.json file ? It's really hard for me to debug as it does not output any errors for me to help. So I can only suggest you clone the repo down and run it with the source code with debugger attached to see where it fails exactly. As I don't have your machine & setup I can't repro here until I know the cause of the problem. – Warren Buckley Mar 31 '17 at 20:10
  • Running the php file on placing in the directory C:\inetpub\wwwroot works by entering localhost/test.php (test is the file name) in browser. But on opening folder in vscode and running via extension I get same error. Seems extesnsion needs to be linked with IIS Express in my case. IIS Express is placed in default directory i.e. C:\Program Files\IIS Express and I am running Windows 10, IIS Express 10, Vscode 1.10.2 and no log files are being created in IIS Express folder placed in Documents. – user7776333 Apr 01 '17 at 18:16
  • And I have done these steps today upto 1.3 as mentioned in the [Microsoft Website](https://technet.microsoft.com/en-us/library/hh994592(v=ws.11).aspx). And folder which is being used by VSCode for php is in documents. – user7776333 Apr 01 '17 at 18:26
  • @WarrenBuckley And I don't see any IISExpress.json file in my folder where I am working. Is it supposed to be somewhere else? – user7776333 Apr 01 '17 at 18:32
  • @user7776333 please post those on the github page linked above. – Tyler C Apr 01 '17 at 19:20
  • Commented on github. @TylerC do you have any IISExpress.json file in your work folder? – user7776333 Apr 03 '17 at 18:24
  • Now the extension is working but only running index.html even if running any other file. And after some research, I disabled default file in IISExpress and enabled directory browsing but still same problem. – user7776333 Apr 09 '17 at 13:32