HALF PRICE!
Udemy
course when you register on learnphalcon
The examples on this site are currently tested to work on Phalcon V3.4 and Phalcon Devtools V3.2 Some issues may arise when using later versions.

Please get in touch or post a comment below the post if you encounter a problem.

As we're approaching deploying an application on a Minimum Viable Product basis I'm going to keep the installations to the quickest and simplest install of each version of the product. Once you start becoming comfortable with the LAMP stack it is advised to return and use the secure installation version of the mysq-server install. In the meantime, to stick with the basics type:

sudo apt install mysql-server

To start the service type

sudo service mysql start

Now to login to mysql as root type

mysql -u root

You will be greeted with the mysql> command prompt. From here you can type sql commands.

To set up a new user - at the mysql> command prompt type

create user 'tennisclubapp'@'localhost' identified by '_tc_123_';

As this new user you have just set up will not have database creation permissions you will have to set up your tennis club database now and grant your new user permissions to that database. To set up the database typ

create database tennisclub;

To grant the user you have just created privileges on your new database type

grant all privileges on tennisclub.* to 'tennisclubapp'@'localhost';

To exit the mysql command prompt type 'quit'. The 'identified by' clause indicates the password for the account.

Next we will install phpmyadmin. Many readers will be familiar with this sql client which comes bundled with xampp. Its a web-based sql client which allows for quick and easy access to MySQL server installations. To install phpmyadmin - from the command shell prompt type

sudo apt install phpmyadmin

To verify that phpmyadmin is running correctly visit http://your_server_ip_address/phpmyadmin - you should see a page like this.


Use the username and password you create above to login. If successful you will see the myphpadmin console which looks like this.

Before we move on this is a good opportunity to go ahead and create the tennisclub database fromo the script we've been using all along. Some readers may have created their own databases. If you don't have a script you can use MySQL export functionality which will provide you with a database create sql script. For now you can use the script below. In previous versions of my application I used database scripts with varying upper case and lower case characters. This is fine on Windows but Linux is case sensititve, both for the database tables themselves but also with the scaffolded code that was generated from those database tables. I found that it is easier to stick to lower-case only database scripts.

Readers of the blog who may have already generated the tennisclub application are advised to re-scaffold controllers and models. This can be done by deleting all the models from the models folder and all the controllers from the controllers folder and then simply re-running the scaffold command.

This script is the same as the one we've been using all along apart from the fact that it is now all lowercase (Jun 2019). Also, the first line which creates the database removed as we don't have privileges to do this.

use tennisclub;

create table member(
	id integer auto_increment,
	firstname varchar(30),
	surname varchar(30),
	membertype varchar(6),
	dateofbirth date,
	primary key(id)
);

create table court
(
	id integer auto_increment,
	surface varchar(30),
	floodlights boolean,
	indoor boolean,
	primary key(id)
);

create table booking
(
	id integer auto_increment,
	bookingdate date,
	starttime time,
	endtime time,
	memberid integer,
	courtid integer,
	fee decimal(18,3),
	primary key(id),
	foreign key(memberid) references member(id),
	foreign key(courtid) references court(id)
);


insert into member (firstname,surname,membertype,dateofbirth) values ('oliver','kerr','senior','2000-01-31');
insert into member (firstname,surname,membertype,dateofbirth) values ('morgan','bartlett','senior','1985-10-28');
insert into member (firstname,surname,membertype,dateofbirth) values ('rebecca','house','senior','1993-08-01');
insert into member (firstname,surname,membertype,dateofbirth) values ('leslie','hammond','senior','1999-03-03');
insert into member (firstname,surname,membertype,dateofbirth) values ('axel','gibson','senior','2007-09-29');
insert into member (firstname,surname,membertype,dateofbirth) values ('bo','bradshaw','senior','1979-12-19');

insert into court(surface, floodlights, indoor) values('savannah',1,1);
insert into court(surface, floodlights, indoor) values('grass',1,0);
insert into court(surface, floodlights, indoor) values('savannah',1,1);
insert into court(surface, floodlights, indoor) values('savannah',1,1);
insert into court(surface, floodlights, indoor) values('grass',0,0);
insert into court(surface, floodlights, indoor) values('grass',0,0);

insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-01-07','09:00:00','11:00:00',2,3,10.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-02-11','16:00:00','17:00:00',5,3,10.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2016-11-16','10:00:00','12:00:00',4,2,20.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-04-06','14:00:00','16:00:00',2,5,10.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-01-17','17:00:00','18:00:00',5,6,10.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-05-06','15:00:00','17:00:00',3,6,15.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-04-27','09:00:00','11:00:00',2,3,10.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2016-05-05','16:00:00','17:00:00',5,3,10.00);
insert into booking (bookingdate,starttime,endtime,memberid,courtid,fee) values ('2017-03-23','10:00:00','12:00:00',4,2,20.00);		

Paste this into the query window and press 'Go' as follows.


You have now successfully installed a LAMP stack - Linux, Apache, MySQL and PHP. You are well on the way to successfully deploying your first PhalconPHP application. Before we move on from the Database we need to set up an identical user and password on our local database and set our phalcon application to use these credentials. This will mean a that our local and remote systems will be basically identical and will allow for seamless updates.

Connect to your local database using your preferred MySQL client (mine is heidiSQL). Execute the following command to create the identical database user on the localystem as follows

create user 'tennisclubapp'@'locahost' identified by '_tc_123_';

Make sure you use the same user name and password as you did earlier.


Now apply these credentials to your local phalcon config file - open the file xampp\htdocs\config\config.php and change the username and password as follows


Your local and remote systems now have identical databases and use identical credentials. When you upload your code it should work identically on both local and remote systems without any modifications. This is important to the streamlined of the deployment process which we are creating.