PHP formatting in VSCode on remote Workspace without using Composer - php

My Setup: Ubuntu 20 with PHP and Composer
My Editor: VSCode with SSH FS extension to access remote workspace.
My Task: do some PHP stuff, mainly Wordpress Themes
My Problem: no PHP Formatter extension works on the remote Workspace
I tried to use: PHP-CS-fixer, Prettier with PHP plugin, phpfmt, phpcs, PHP Formatter...
Some of them will even not work on my local Workspace.
I can't install new Code on the remote Server (Composer), so i need a way to format PHP files just out of the Box like HTML or JS.
But meanwhile i think, this is not possible.

Solution: use Ubuntu to connect to the server and mount that folder in workspace, let VSC think it is a real local folder :-)

The problem with most formatting extensions is that they expect the files to be on a local drive, as in being mounted outside VS Code, including network shares by any NodeJS program (and therefore VS Code extensions). The extension uses the extension API's FileSystemProvider to provide FS access to VS Code. It is only recently that they added a way for one extension to use file systems provided by other extensions, and it's even more recent that they started pushing extensions to make use of this.
Sadly enough, not every extension developer might start using it, and it's especially tricky for extension that use native/external programs. That includes most language-servers and formatters.
For your use case, there are two solutions though:
Mount the folder on the OS level (e.g. sshfs) and just open it as a regular directory in VS Code, as another answer suggested
Use VS Code's Remote SSH, which actually runs the extensions on the server, therefore skipping the whole "files aren't on a local drive" problem

Related

Visual Studio - Cannot validate since a PHP installation could not be found, FTP to server

I get the error when I open my VS. I´m working with, or on, files directly on the server, using SimpleFTP to synch between computer/Server. That means the files are loaded, and saved, directly from/to my server (yes, they are cached om the computer...).
This also means that a have the PHP installed on the server - not my computer/PC. Is it possible to use the server-installation of PHP, or do I need to install a PHP extension on my PC?
If I can use the server PHP installation - How do I set the path? I´m running Raspberry/Apache...
Hopefull for any respons...
using FTP you can only transfer/sync files. For running php command line is necessary. Better approach is to use ssh. On vscode using Remote - SSH official extension you can access complete developer environment.

PHP Server on Amazon Linux EC2

I recently created a PHP server on an Amazon EC2 Linux AMI instance and I am struggling to figure out how do to upload the PHP code to in order to be displayed on the browser from a .php file type setting.
The only option that was availiable to me to write PHP code and have it displayed was through creating a script directly from the Linux Terminal using the following commands
>SamplePage.php #this creates the php file
nano SamplePage.php #this opens the editor to start writing the code in the terminal.
However is there a visual interface that I could use to upload php code files/documents/pictures. So that I can click and drag the .php file on to the server without typing it on the terminal?
Does the phpMyAdmin do that? Or is is only for used managing MySQL (database) tasks and not for uploading PHP files/graphs/pictures needed to develop a fully integrated site?
By the way, here are the instructions I used to create the LAMP server with PHP as well as MySQL.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html
phpMyAdmin is a web-interface for managing databases.
You could check if there is already some ftp-server installed. Like vsfpt (just an example, there are a lot more free & open source ftp-servers available). if you encounter any problems with that a good place to ask questions related to hosting and servers is ServerFault
You could also transfer the files via ssh-connection with the help of scp (See: How to copy files from one machine to another using ssh or How to upload local system files to Amazon EC2 using ssh). Another option would be to use a visual ssh-client.
There is also server-management software available that offer a visual file-manager as a website, like plesk, but since you already setup most of the stack this would be hard to do on top of that.
There are many IDEs and Editors that have support for SSH and SCP. Either built in or through plugins. For example: Eclipse, Netbeans, Atom and VSCode. All of which are free and can be configured to support PHP development.

which server to install for phpEclipse and how to do it?

I know this is a newbie question, but i want to study php. i have phpeclipse and its running well, the problem is when i run a simple html file with the default server the page says cant display this page and thats it. i dont know if i need to install a new server or is there something wrong with the server configurations. ive tried installing tomcat on my computer but i cant see it under windows->preferences->server->runtime enviroments->add. iv also tried under the same page to fetch geronimo v2.2 and 3.0 and the dependencies were wernt satisfied. iv also tried the repository for zend debugger. what do i need to do in order to compile and see php and html pages with php eclipse?
You don't need to compile PHP.
Depending on your operating system and PHP version there are a few options.
As of PHP 5.4+ you can run your application using PHP's built in server, on the command line, if you cd into your website root directory (i.e. where the index file is) and then run the following
php -S localhost:8989
Then if you navigate to http://localhost:8989 in your browser you should see your application.
If you are unable to run the inbuilt web server, you need to look at Apache2. Most PHP websites run inside the Apache 2 web server. You will generally need a *AMP (WAMP/LAMP) environment.
L/W (Linux / Windows)
A pache (Web server)
M ySQL (Database)
P HP
Hope this is enough of a pointer ;)

Installing PDFTK on a shared web server

My web sites are hosted on Total Choice Hosting using some kind of Linux (I don't know what precise variety) and Apache. I don't have command line access - I can run command line programs only via exec() in PHP, or via CRON jobs.
Can I install and use PDFTK on a system like this?
If so, what exactly do I have to do? Which files do I have to copy where? Do I have to rebuild PDFTK from source, or is there an executable version somewhere?
Since (as I understand it) PDFTK is based on iText, which is written in Java. Maybe I'd be better off using the original iText package?
Or is there a better way of doing what I want to do (which is basically to merge and flatten a PDF file (blank form) with a FDF file (field values) into a new PDF file (the completed form) and download it to the user)? Is there some native PHP or Python or Perl code to do this?
Thanks - Rowan
A quick glance reveals that the PDFTK source is C++ and it looks like they use GCJ to compile some 3rd party Java code to native code. If you find a pre-built version of PDFTK that matches your OS and architecture you should be able to just upload the binary to your system and run it from PHP using exec. There are some builds available on the install page.
There are some native PHP libraries available for creating and manipulating PDFs. Check out TCPDF, Zend_Pdf, and FPDF to see if any of those are usable. Each one should support what you want to do, its just a matter of choosing the right solution.
Using PDFTK may be the fastest option since it is compiled code, but it is the least portable option since it would require the server have that software installed on it, where the PHP solutions could be distributed with your code.
If you are on a shared host you cant install PDFtk because you don't have access to root to install anything. You need to have a host that has it preinstalled. I use bluehost.com but there up-time is not the best. It works for now but I am going to move to another host once my site is complete. I have had several outages that have lasted for over a day.

How to get started with sql and php?

I was wondering how to link a SQL database on my PHP code.
I am using a database on my local server that I set up and I have already created a database, I tried writing a PHP script with ++notepad, but when I clicked on the script, it opened the browser and displayed a blank page. What am I doing wrong? I created my databases using phpMyAdmin.
You need to be running a web server locally which supports PHP (like Apache). It it the web server which does the PHP processing. At the same time you will have to run a MySQL (or any other) database engine too, so your PHP code can connect and query it. (I'm assuming you've already installed PHP.)
I would recommend you install XAMPP which includes Apache, PHP, MySQL and a bunch of other stuff. It one of "Apache friends". Once you install XAMPP you would have a folder htdocs in the xampp folder. Create a folder for you project myproject and place your PHP script script.php in there. Now if MySQL and Apache are running following should behave as you expect.
http://127.0.0.1/myproject/script.php
For the tutorial, to begin with you can use W3Schools. Brief and to the point. They have both a PHP tutorial and a SQL tutorial.
This is a very good book to start with:
PHP and MySQL
Web Development
Luke Welling and Laura Thomson
You have to play with php/sql code practically. Only reading cant help!
go for w3shools as mentioned above :)
start with simple code and then go to the complexity. all the best.. :)
There are multiple ways on how to do that.
One of the most modern ways to do that, is to use PDO to connect to the DB with PHP.
To run PHP on your PC(which i assume is your workstation), you need the supporting software for it, for php to run you need the PHP software installed, and likewise if you want to run the server software you need apache, however you can go for a single install package which will install almost everything for you to run your php script, download and install the wamp.
to install wamp which stands for (windows, apache, mysql, PHP) if you are running windows, and lamp for linux or mamp for mac, all of which are free softwares, you can download wamp from the following link. http://www.wampserver.com/en/download.php that is the first step which you need to do.
step 2: once wamp is installed the default directory of installation is C:/wamp (i reccomend do not change the location of the installation), you need to start the wamp server by just opening or double clicking the software which you just installed.
step3: navigate to the default directory where you should be storing your PHP files and that is C:/wamp/www note that you should be keeping all your PHP files here apart from this location if you store it anywhere else it wont simply run at all, and that it should and must have the .php extension.
step4: create or save the php files in this location(c:/wamp/www) i for example will assume you have created a file test.php in the www folder. now to access this file open your web browser and type http://localhost/test.php there you go, you will have the access to your PHP file (Note: PHP files cannot be run by simply double clicking the file, you have to follow this procedure in order to run the PHP files)
step5: open the test.php in any of your text editor like notepad, or i recommend use an IDE (Netbeans is free and worth a try), and write your code in the following format.
<?php
your PHP code should go here.
?>
when i started writing the code i started by following a nice tutorial which i found in zend.com, it has one of the best examples, and moreover the tutorial is meant for the beginners. hope this helps you..
http://devzone.zend.com/tag/PHP101

Categories