COAP:COAP-3110/week6
Week 6 learning goals
- Plugin installation and management (continued)
- Migrating from a development server to a hosting company
- A first glance at the REST protocol
Monday
Plugin installation continued.
Wednesday
Web hosting providers
Free hosting exists (see below). Prices for low cost hosting start around 3 Euros / month, but you have to add fees for a domain name to that if you want your own.
Well-known free (read the fine print)
- Host-ed (free, without domain name)
- AwardSpace (free, without domain name). Test site used by the instructor: http://coap3110-demo.atwebpages.com/
- 000webhost (free, without domain name, not recommended). The test site used by the instructor (http://coap3110.comuf.com/) seems to show that 000webhost doesn't work as advertised.
You can search the web for alternatives, e.g. read TechRadar, but be careful. Cross-check information about a provider.
Well-known cheap, HostGator is best according to PC Mag
- HostPapa (3 Euros/month)
- GoDaddy ($4-5 / month)
- Hostgator (3.5$ / month), also cheap dedicated hosting for $80/month
Recommended local (Geneva, Switzerland)
- Infomaniak (10 CHF / month). Probably one of the best in that range (quality/speed)
- HostPoint (10CHF/month, 30 day trial)
Domain name registration
- Most hosting companies will provide that service
- You many check if they are accredited with ICANN (i.e. first-level registrars)
Moving a platform from a local server to a hosting organization
- Moving a Wordpress from a local server to an other target is fairly easy most of the time. However, many things can go wrong ...
- Consider googling for tutorials, e.g. "move wordpress site from localhost to remote server" (or similar).
Executive summary:
- Create a new database and a new database user on the target site.
- Move all PHP files (or install a new system)
- Dump the SQL (data), repair data in the SQL, e.g. web addresses, then import the *.sql on the target
- Adapt the
wp-config
configuration file (database name, database user, etc.)
Local preparation
- Dump the whole database to a *.sql file, e.g.
w.sql
. - Since free/cheap provider may work with and older version of MariaDb/MySQL: Edit the SQL and replace
utf8mb4
byutf8
. - Important: Repair all URLs that point to your old host, e.g. replace
http://localhost/w/
by the new absolute URL, e.g.http://coap3110-demo.atwebpages.com/w/
(Remark: I really cannot understand why Wordpress is doing this) - Create a copy of the
wp-config.php
file and edit some settings (see below).
New host preparation
Most often, the hosting company will not let you create random database names since a same MySQL or MariaDB server is shared with many many users. You will have to use a specific tool from the control panel to create databases and database users.
(1) Carefully read the FTP (File transfer) instructions
- You will need a hostname for file upload (not necessarily the same as your website name), a username and a password.
- You may have to deposit your files in a specific directory that is exposed to the web and that represents the "root" of your domain.
- You may have to install an FTP client on your machine. We recommend WinSCP (Windows) and Cyberduck (Mac), but there are many other alternatives.
- Most cheap hosting companies only allow for unencrypted FTP (port 21). Good FTP clients like WinSCP will suggest secure "SFTP" transfer per default. You will have to change that to "FTP"
Write down:
- Name of FTP server
- Name of web directory
- FTP user name and password (if different from the user name for the provider's web site)
(2) Create a new database
On free hosting platforms, you probably only will be allowed to use a single database and you cannot change its name. Usually, you cannot use Phpmyadmin for database creation, try to figure out how to do it through the administration interface. Database names also might include a prefix tied to your username.
- The database server usually will not sit on "localhost" (same machine as PHP), but on another server.
Write down:
- full name of the database (may require min/max characters)
- database user name,
- database user password (may require different types of characters)
- database server name (not localhost)
(3) Create your sub-domain on the new host if needed.
Usually a free provider requires you do that. In other other words, you will then have an URL like your_subdomain.provider.com
. Write that down.
Transfer php files, configuration file and database dump
(1) Move all the PHP files from local to new target
- Your target directory may not be writable. The administration interface allows to unlock a directory. Make sure to do this recursively.
- Copy the whole WordPress directory to the new host, using an FTP or SFTP client or a WebClient (depending on the hosting company). Carefully evaluate what your target directory should be. If you only plan to host a single wordpress site, then you could copy the contents of the Wordpress directory to the target's web root directory. Otherwise copy the directory, e.g.
/.../web_directory/w
(2) Create a new configuration file
On the local host (again):
- Create a backup copy of wp-config.php, e.g.
wp-config.local.php
- Create a new copy of wp-config.php, e.g.
wp-config.new.php
- Edit config.new.php and configure it with the parameters for the new host.
(3) Import the database to the new host
- Make sure to select the right database first (if you got a choice) on the host.
- Import the *.sql database file to the target site, using PhPMyAdmin or another client
(4) Copy the local wp-config.new.php
file to the target site and rename it to wp-config.php
Example taken from 000webhost.com:
As you can see the hosting organization may force you to adopt some prefix, i.e. the a3966289
would represent your user id.
define('DB_NAME', 'a3966289_w');
/** MySQL database username */
define('DB_USER', 'a3966289_user');
/** MySQL database password */
define('DB_PASSWORD', 'XXXXXXXX');
/** MySQL hostname */
define('DB_HOST', 'mysql5.000webhost.com');
Trouble
- Your provider may use an old mysql version that does not support the extend utf8mb4 character set. Open the *.sql file in a text editor and replace
utf8mb4
byutf8
. If that is the case, you also need to make change in wp-config.php. - You forgot to replace the absolute URLs in the SQL code, for example, your new WP site may attempt to access "localhost". If you are in doubt with respect to your domaine name, execute a phpinfo.php file that includes a
phpinfo();
statement.
A first glance at REST
According to Wikipedia, “A Web service is a service offered by an electronic device to another electronic device, communicating with each other via the World Wide Web. In a Web service, Web technology such as HTTP, originally designed for human-to-machine communication, is utilized for machine-to-machine communication, more specifically for transferring machine readable file formats such as XML and JSON. In practice, the Web service typically provides an object-oriented Web-based interface to a database server, utilized for example by another Web server, or by a mobile application, that provides a user interface to the end user. Another common application offered to the end user may be a mashup, where a Web server consumes several Web services at different machines, and compiles the content into one user interface.”
There exist several types of web services, e.g. the more traditional stack built around SOAP.
Currently, REST is the most popular mechanism used by more light-weight portals and more generally speaking all sorts of services that deal with information, as opposed to commercial transactions for example.
Hands on
(1) Please install the Wordpress plugin:
- WordPress REST API (V2)
(2) Get a list of posts from one of your colleagues web site.
(3) Retrieve all COAP 3110 pages from edutechwiki
- http://edutechwiki.unige.ch/mediawiki/api.php
- http://edutechwiki.unige.ch/mediawiki/api.php?action=help&modules=query
Modify: