Open PHP Local Server from VB.NET application

Asked

Viewed 433 times

1

I wanted to know if it is possible to open a local PHP server from a VB.NET application, it can be a very basic server, like Vertrigoserv, why is it only to run some basic code even through the application.

  • Are you using Apache, IIS or NGINX to run PHP on your machine? Or haven’t decided this yet?

  • I’m using Apache

  • you want to make a software that starts apache server or you want to make an HTTP request?

  • I want to start apache server from my application

  • Just one more question your Apache is using Fastcgi or Apachehandler?

1 answer

1


If I understand, you have a WAMP server installed on your machine (I assume it’s Apache, Mysql and PHP)

I will assume that your Apache is using Apachehandler instead of Fastcgi in the "Server API "

In any Windows call method (for example CMD), you should call the program and pass the arguments if necessary.

To call any program on . NET you can use the ProcessStartInfo

Steps to follow:

  1. Locate the program httpd.exe (should be in a folder like C:\Apache\Apache2.4\bin\httpd.exe)

  2. If you are using Mysql, find the mysqld.exe, must be something like C:\mysql\mysql5.2\bin\mysqld.exe

  3. And locate the my.ini Mysql (if actually using mysql in your scripts), the path should look like C:\mysql\mysql5.2\my.ini

Now that we have the paths, we must create a method for each process (can even reuse the same method, but this is another story):

Suppose the apache path is something like C:\Apache\Apache2.4\bin\httpd.exe, we must execute a command type this (to run it as a service, it is not necessarily required):

"C:\Apache\Apache2.4\bin\httpd.exe" -k runservice

To use with ProcessStartInfo:

Dim startInfo As New ProcessStartInfo
startInfo.FileName = "C:\Apache\Apache2.4\bin\httpd.exe"
startInfo.Arguments = "-k runservice"

' Para ocultar a janela do processo
p.WindowStyle = ProcessWindowStyle.Hidden

Process.Start(startInfo)

To call Mysql (if necessary for your scripts) you should use something like:

C:\mysql\bin\mysqld.exe --defaults-file=C:\mysql\my.ini --console

The method must be something like:

Dim startInfo As New ProcessStartInfo
startInfo.FileName = "C:\mysql\bin\mysqld.exe"
startInfo.Arguments = "--defaults-file=C:\mysql\my.ini --console"

' Para ocultar a janela do processo
p.WindowStyle = ProcessWindowStyle.Hidden

Process.Start(startInfo)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.