[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:misc:approach_to_web_development_on_slackware [2020/11/21 20:01 (UTC)] – [Web Dev primarily HTML and PHP] captain_sensiblehowtos:misc:approach_to_web_development_on_slackware [2020/12/01 16:54 (UTC)] (current) – [Structure of HTML & PHP] captain_sensible
Line 7: Line 7:
  
 There will be some embedded information on HTML and PHP, what they do and what they do not do. I will probably throw in some anecdotal  info from my experience. There will be some embedded information on HTML and PHP, what they do and what they do not do. I will probably throw in some anecdotal  info from my experience.
 +
 +==== Structure of HTML & PHP ====
  
      
Line 35: Line 37:
  
 There are many alternatives to working with HTML documents using a text editor, but as good as any in my opinion is geany available from [[slackbuilds.org]].It has basic text highlighting and gets the job done. There are many alternatives to working with HTML documents using a text editor, but as good as any in my opinion is geany available from [[slackbuilds.org]].It has basic text highlighting and gets the job done.
 +
 +
 +==== Using Built in PHP dev Server to render HTML ====
 +
 +
  
 Now, if we were working with geany and saved the above text as a file say  index.html to your  Desktop, you then  have two choices; open and edit with a text editor or open it as intended with a web browser. If you do that, all you will see is "hello world" Now, if we were working with geany and saved the above text as a file say  index.html to your  Desktop, you then  have two choices; open and edit with a text editor or open it as intended with a web browser. If you do that, all you will see is "hello world"
Line 45: Line 52:
 webPlay webPlay
 └── index.html └── index.html
- 
 </code> </code>
  
Line 97: Line 103:
  
    
-A single index.html is about as simple as you can get; if you uploaded it say via cPanel on hosting, and then you pointed your website domain to that hosting, as instructed by your hosting company then you will have a simple, but working one page web site.+A single index.html is about as simple as you can get; if you uploaded it say via cPanel on hosting, and then you pointed your website domain to your hosting, as instructed by your hosting company then you will have a simple, but working one page web site.
  
-More sophisticated web systems such as WordPress still have somewhere within them index.php (with WP its located at the web root). In these cases, the index.php is often referred to as the "bootstrap" not to be confused with front-end Twitter Bootstrap.+More sophisticated web systems such as WordPress still have somewhere within them one or more index.php (with WP its located at the web root). In these cases, the index.php file is often referred to as the "bootstrap" not to be confused with front-end Twitter Bootstrap.
  
-Before we move on to PHP let's have a last look at HTML and how to link one page to another. Go to Geany ->file->new with template->file_html5.html. That produces a ready made html5 template. All you have to do is name it and save it somewhere. Save it to /Desktop/webPlay as about_me.html.+Before we move on to PHP let's have a last look at HTML and how to link one page to another. Go to geany ->file->new with template->file_html5.html. That produces a ready made html5 template. All you have to do is name it and save it somewhere. Save it to /Desktop/webPlay as about_me.html.
  
 Open it up and in the <body> </body> write a few words. Open it up and in the <body> </body> write a few words.
Line 126: Line 132:
  
 Click on the line that says //about_me// and you will see that the HTML document about_me.html is now rendered. You now have the basis for a few pages on your web site. Some will pooh-pooh this, but it's better than the option of no web site, if you are a small business. Without a web site in today's world, you can't be found. Click on the line that says //about_me// and you will see that the HTML document about_me.html is now rendered. You now have the basis for a few pages on your web site. Some will pooh-pooh this, but it's better than the option of no web site, if you are a small business. Without a web site in today's world, you can't be found.
 +
 +
 +==== Making use of HTML presentation but with PHP functionality ====
  
  
Line 159: Line 168:
 </code> </code>
  
-Refresh your browser and now what do you see?Quite a lot!+Refresh your browser and now what do you see? Quite a lot of information concerning PHP!
 When I first did this it demonstrated the potential of PHP.  When I first did this it demonstrated the potential of PHP. 
 +
 +==== Introducing Databases into the mix  ====
 +
 +
 Next we will have a simple look at using a database.When you mention anything about databases most people immediately think MySQl or Maria;so you can't do anything with a database on your Desktop since you need a daemon. Well actually you can since sqlite3 is server-less. Next we will have a simple look at using a database.When you mention anything about databases most people immediately think MySQl or Maria;so you can't do anything with a database on your Desktop since you need a daemon. Well actually you can since sqlite3 is server-less.
 Assuming our Terminal Emulator is in webPlay lets create a database from the command line. Actually lets first check we have the tools in place: Assuming our Terminal Emulator is in webPlay lets create a database from the command line. Actually lets first check we have the tools in place:
Line 245: Line 258:
  
  
-So here we just did a retrieval of data; its one small step from there to insert, update all part of what is referred to as "crud" operations. html files are just static files that have markup on how the static content is presented. php on the other hand is a rich fully functional programming language that you can either use in an OOP way. In other words create classes which have methods or in a procedural way.+So here we just did a retrieval of data; its one small step from there to insert, update all part of what is referred to as "crud" operations. HTML files are just static files that have markup on how the static content is presented. php on the other hand is a rich fully functional programming language that you can either use in an OOP way. In other words create classes which have methods or in a procedural way.
  
-A couple of other things to mention php, is a scripting language; an "engine" such as Zend processes  the code, then renders output to the browser. +A couple of other things to mention PHP, is a scripting language; an "engine" such as Zend processes  the code, then renders output to the browser. 
  
-So what i have demonstrated here is that you can go a long way developing php on your Desktop.You may have noticed  that no mention was made of the word chmod nor permissions. Everything we did was in user space, so you don't have to worry about that. With files located in our user space we have both read and write permissions to them. I mention it here, since later that's going to be a problem when we look at xampp and apache, +So what i have demonstrated here is that you can go a long way developing PHP on your Desktop.You may have noticed  that no mention was made of the word chmod nor permissions. Everything we did was in user space, so you don't have to worry about that. With files located in our user space we have both read and write permissions to them. I mention it here, since later that's going to be a problem when we look at xampp and apache, 
 which is another approach for working with web development.  which is another approach for working with web development. 
  
 +
 +==== PHP framework ====
  
 Before we look at xampp and apache i'm going to mention composer [[https://getcomposer.org/|composer ]] Before we look at xampp and apache i'm going to mention composer [[https://getcomposer.org/|composer ]]
  
-When your working with single html or php files, you will find you the need to update them that's not too much of a problem. When you work with more complicated web applications say CodeIgniter, new releases come out and then you have 3rd party software installed as well which have dependencies.Things can soon get out of hand. The use of composer helps updating and managing dependencies. +When your working with single HTML or PHP files, you will find you the need to update them that's not too much of a problem. When you work with more complicated web applications say CodeIgniter, new releases come out and then you have 3rd party software installed as well which have dependencies.Things can soon get out of hand. The use of composer helps updating and managing dependencies. 
  
 I've used it in 2 ways.   I've used it in 2 ways.  
Line 306: Line 321:
 </code> </code>
    
-A little bit about php frameworks. A few html or php files is ok for a small website but php frameworks come in handy where you are going to do a lot of work with data. Frameworks have a design of logic that splits  what you see, what does the  processing, and what connects to database into whats called MVC (model,view,controller).+A little bit about PHP frameworks. A few HTML or PHP files is ok for a small website but PHP frameworks come in handy where you are going to do a lot of work with data. Frameworks have a design of logic that splits  what you see, what does the  processing, and what connects to database into whats called MVC (model,view,controller).
  
-php built in server or using spark have their limitations; if you insist on wanting to use MySQl or Maria then you have to consider something like xampp or apache. +PHP built in server or using spark have their limitations; if you insist on wanting to use MySQl or Maria then you have to consider something like xampp or apache. 
  
 Now xampp from apachefriends [[https://www.apachefriends.org/index.html|xampp ]]is basically a bundled unit of a web server and supporting files. Now xampp from apachefriends [[https://www.apachefriends.org/index.html|xampp ]]is basically a bundled unit of a web server and supporting files.
Line 314: Line 329:
 It comes with an installer and I have previously tried it on Slackware. Although it comes with an installer it is not installed on your system but is put in /opt and the way i view it is that it is an "embedded system" It comes with an installer and I have previously tried it on Slackware. Although it comes with an installer it is not installed on your system but is put in /opt and the way i view it is that it is an "embedded system"
  
-There are pro's and cons. Its doesn't use your system php as far as i understand it, so your own php might be more up to date than xampp, then there are issues like updating. From my limited understanding a web server does not come as default with other distros, so for them they have the choice: should I install apache or give xampp a go, maybe thinking at least I won't bork my system- its quite understandable.+There are pro's and cons. Its doesn't use your system PHP as far as i understand it, so your own PHP might be more up to date than xampp, then there are issues like updating. From my limited understanding a web server does not come as default with other distros, so for them they have the choice: should I install apache or give xampp a go, maybe thinking at least I won't bork my system- its quite understandable. 
 + 
 + 
 +==== Setting up a Development Environment using Apache ====
  
  
Line 323: Line 341:
 </code> </code>
  
-Thats where we are now going to move our CI4 to. I must at this point put in a disclaimer that i'm writing from my experience of getting things going. I have for a few months been writing a light C.M.S system on top of CodeIgniter 4.0.4; i've had no glitches, no crashes or anything else detrimental- so i'm assuming from empirical observation I must have half a clue- others might point out how it could be bettered. +Thats where we are now going to move our CI4 to. I must at this point put in a disclaimer that I'm writing from my experience of getting things going. I have for a few months been writing a light C.M.S system on top of CodeIgniter 4.0.4; I've had no glitches, no crashes or anything else detrimental- so I'm assuming from empirical observation I must have half a clue- others might point out how it could be bettered. 
  
 Ok this is one way  I use CodeIgniter in apache: Ok this is one way  I use CodeIgniter in apache:
Line 336: Line 354:
 # mv CI4.zip /var/www/htdocs  # mv CI4.zip /var/www/htdocs 
 </code> </code>
 +
 +===  Approach To permission problems ===
  
  
-Now i will talk generally about problems  with permissions for developers. For those coming from Windows,who have done web development they get a bit of a shock when they move to Linux. As a "normal user" you don't have any authority to do any editing of code of a web app directory located within htdocs  located at /var/www/htdocs . Thats because they are within  your root system. +Now i will talk generally about problems  with permissions for developers. For those coming from Windows,who have done web development they get a bit of a shock when they move to Linux. As a "normal user" you don't have any authority to do any editing of code of a web app directory located within htdocs  located at /var/www/htdocs . That'because they are within  your root system. 
  
 Now this is where perhaps the bone of contention sets in;you want to get on editing and developing but you don't want to mess your system up either.You could do su->password-># i.e shift to root but that wouldn't be a good idea, when all sorts of strange things could happen. With root permission you could delete or edit something you didn't want to do. So whats the answer? Well there are a few approaches. Now this is where perhaps the bone of contention sets in;you want to get on editing and developing but you don't want to mess your system up either.You could do su->password-># i.e shift to root but that wouldn't be a good idea, when all sorts of strange things could happen. With root permission you could delete or edit something you didn't want to do. So whats the answer? Well there are a few approaches.
Line 409: Line 429:
 secrets when I show you my local WP ;it looks like this: secrets when I show you my local WP ;it looks like this:
  
-{{:howtos:misc:wp_users.jpg?600|}}+{{:howtos:misc:wp_users.png?600|}}
  
 Its an extract of how WP uses Sqlite (yes you can opt for sqlite  instead with WP)   WordPress seems to be poorly written and a word of warning; in a default install its possible to display user login credentials via a simple get request to the domain!So the security of connecting to a database adds nothing to the security of your user credentials with WP Its an extract of how WP uses Sqlite (yes you can opt for sqlite  instead with WP)   WordPress seems to be poorly written and a word of warning; in a default install its possible to display user login credentials via a simple get request to the domain!So the security of connecting to a database adds nothing to the security of your user credentials with WP
Line 485: Line 505:
  
 Note the 127.0.0.9 in address bar and that I can now work with framework and edit as user andrew , without risk of messing up system as root. If you follow this through and you get a problem its probably either your php version is < than 7.3 or I did something somewhere forgot about it and  forgot to mention . Note the 127.0.0.9 in address bar and that I can now work with framework and edit as user andrew , without risk of messing up system as root. If you follow this through and you get a problem its probably either your php version is < than 7.3 or I did something somewhere forgot about it and  forgot to mention .
 +
 +
 +
  
  
 ====== Sources ====== ====== Sources ======
 +
 +
 <!-- If you are copying information from another source, then specify that source --> <!-- If you are copying information from another source, then specify that source -->
 <!-- * Original source: [[http://some.website.org/some/page.html]] -of -> <!-- * Original source: [[http://some.website.org/some/page.html]] -of ->
 <!-- Authors are allowed to give credit to themselves! --> <!-- Authors are allowed to give credit to themselves! -->
-<!-- * Originally written by [[wiki:user:xxx User X]] -->+ Originally written by [[wiki:user:captain_sensible  captain_sensible]] 
 <!-- * Contributions by [[wiki:user:yyy | User Y]] --> <!-- * Contributions by [[wiki:user:yyy | User Y]] -->
  
 howtos:misc:approach_to_web_development_on_slackware ()