cURL is free software that allows you to transfer between servers. The cURL project offers two sub-projects:
- curl — This is the command line tool you can run on your local computer, or your DreamHost server. It offers several command options for you to send and receive data. 'curl' uses 'libcurl'.
- libcurl — This is a library that supports many different protocols. It's very common for the PHP programming language to use this library. View the following article for further details:
This article only shows how to use the command-line tool.
The following examples must be run in an SSH terminal application. View the following article for further information on how to log into a terminal.
Viewing the curl version installed
The following shows how to view the version of curl you're using. This may change depending on if you're running commands on your DreamHost server, or your local computer.
[server]$ curl --version curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
DreamHost runs version 7.35.0 on servers running Ubuntu 14 (Trusty) and version 7.58.0 on servers running Ubuntu 18 (Bionic). Servers running Debian Stretch run 188.8.131.52.
Return the code of a specific webpage
This will return the source-coding of a specific page.
[server]$ curl http://example.com
Save the code of a specific webpage in a new file
If you just run curl example.com, the code displays in your terminal. To save it to a new file name instead, use the -o flag. This uses the lowercase 'o' character.
The syntax would be curl -o <new-file-with-saved-code> <website-url>
[server]$ curl -o example.com-CODE http://example.com
Save the code of a specific webpage to a file of the same name
If you do not want to save to a new file name, you can save to a file that's the same as the page you're accessing. For example, if you're accessing 'example.com/index.html', this will create a new file titled 'index.html' with the saved code. Use the -O flag with a capital 'O' character.
The syntax would be curl -O <website-url>
[server]$ curl -O https://example.com/index.html
Testing a connection to a remote site
At some point, you may notice that your site is not communicating with another website. An example may be when you're attempting to download a WordPress plugin and seeing it fail.
The following steps help you test your connection to WordPress:
- Log into your server via SSH.
- Run the following command within your domain's directory:
[server]$ curl -v https://wordpress.org/ * About to connect() to wordpress.org port 443 (#0) * Trying 184.108.40.206... connected * Connected to wordpress.org (220.127.116.11) port 443 (#0) * successfully set certificate verify locations:
This first responds with connection data, then the full code of the page you entered.
The above shows a successful connection. If it failed, you'd see the failure in the response instead.
You can also use cURL to check headers from a website using the '-I' flag:
[server]$ curl -I http://example.com/index.php HTTP/1.1 200 OK Date: Tue, 29 May 2018 20:55:09 GMT Server: Apache Last-Modified: Mon, 25 Jul 2016 22:45:30 GMT ETag: "2f3-5387d8a979b59" Accept-Ranges: bytes Content-Length: 755 Vary: Accept-Encoding Content-Type: text/html
This returns a default list of headers. If you want a specific header not shown, you must manually specify it using the '-H' flag. For example, run the following to check if gzip is enabled:
[server]$ curl -I -H 'Accept-Encoding: gzip,deflate' http://example.com/index.php HTTP/1.1 200 OK Date: Tue, 29 May 2018 20:57:31 GMT Server: Apache Last-Modified: Mon, 25 Jul 2016 22:45:30 GMT ETag: "2f3-5387d8a979b59" Accept-Ranges: bytes Vary: Accept-Encoding Content-Encoding: gzip Content-Length: 428 Content-Type: text/html
If gzip is enabled, you'll see this line in the output:
It's possible that when you run 'curl' on a website URL, you'll see a 'Moved Permanently' response. For example:
[server]$ curl http://www.example.com <html> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://example.com">here</a>.</p> </body></html>
This usually just means the URL does (or doesn't) use the 'www' subdomain before it. Try again with (or without) www.
Otherwise, you can use the '-L' flag to redirect you anyway.
[server]$ curl -L http://www.example.com