Keith Smith was first introduced to programming at the University of Arizona in 1983. From 1986 to 1990 Keith was an xBase developer. In 2000 Keith built his first website from scratch by hand. In 2006 Keith become a freelance PHP developer. Today Keith wants to teach you everything he knows about PHP programming.
In this article we cover taking an Ubuntu 24.04LTS server and expanding it into a full blown Linux, Apache, MySQL, and PHP (LAMP) web server.
What is a LAMP Stack
A LAMP stack is a popular framework for building and deploying web applications. The acronym stands for:
Linux serves as the operating system.
Apache handles the HTTP/HTTPS web requests.
MySQL manages and stores data – the data engine.
PHP is a programming language that processes the business logic and generates dynamic content.
A LAMP stack is a comprehensive web server that is very popular today, and has been so for 20-plus years.
The LAMP stack is widely used because it provides a robust and reliable platform with open-source components, meaning it’s cost-effective and highly customizable.
My LAMP Development Configuration
I have a Windows 10 laptop that runs VirtualBox virtualization software.
I created an Ubuntu 24.04LTS guest on VirtualBox in preparation for creating a complete LAMP server.
If you have been following along on my YouTube channel or on my blog, you have an idea of what we are doing and where we are going.
I use these local LAMP servers for developing and testing PHP programs.
Ultimately these PHP applications will be moved to a commercial LAMP server.
Prerequisites
You will need to have access to an Ubuntu 24.04LTS server and you will need to have sudo privileges.
I have created a clone of a Ubuntu 24.04LTS server in preparation for creating a LAMP server.
In this article and, associated YouTube video, I will demonstrate all the Linux command line commands necessary to take a bare Ubuntu 24.04LTS server into a full featured LAMP server.
Step 1 is to Update and Upgrade System Packages
The first thing you need to do is update the server to the latest package index. And then upgrade any local packages that need to be updated. And finally remove any non-used packages and Kernels.
This consists 3 commands:
1. sudo apt update
2. sudo apt upgrade
3. sudo apt autoremove
The command sudo apt update – is used to update the list of available packages and their versions from the repositories defined in your system’s configuration files. It doesn’t actually install or upgrade any packages; it simply fetches the latest package information so that you can later install or upgrade packages with up-to-date information or code.
Running apt update regularly ensures that your system has the latest package information.
The sudo apt upgrade command is used to upgrade installed packages.
At this point run the 4 below commands:
1. sudo apt update
2. sudo apt upgrade
3. sudo apt autoremove
4. sudo reboot
sudo apt autoremove is used to remove any old packages and old Kernels.
After running sudo apt autoremove, I would recommend a reboot to ensure everything is loaded properly.
Run sudo reboot to reboot your server.
Step 2 Install the Apache Web Server
This consists 5 commands:
1. sudo apt install apache2
2. sudo systemctl start apache2
3. sudo systemctl stop apache2
4. sudo systemctl enable apache2
5. sudo systemctl status apache2
Run the command sudo apt install apache2 to download and install the Apache2 HTTP server along with any dependencies it requires.
1. sudo systemctl start apache2 – Starts Apache.
2. sudo systemctl stop apache2 – Stops Apache.
3. sudo systemctl enable apache2 – Sets Apache to be started when the server starts up.
4. sudo systemctl status apache2 – Provides the status of Apache.
systemctl is responsible for initializing and managing system services and resources during boot and runtime.
The output of sudo systemctl status apache2 will look something like this:
● apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Fri 2024-09-06 21:49:22 UTC; 17min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 799 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 968 (apache2)
Tasks: 6 (limit: 4614)
Memory: 19.7M (peak: 19.9M)
CPU: 437ms
CGroup: /system.slice/apache2.service
├─968 /usr/sbin/apache2 -k start
├─995 /usr/sbin/apache2 -k start
├─996 /usr/sbin/apache2 -k start
├─997 /usr/sbin/apache2 -k start
├─998 /usr/sbin/apache2 -k start
└─999 /usr/sbin/apache2 -k start
Sep 06 21:49:15 firstinstall systemd[1]: Starting apache2.service - The Apache HTTP Server...
Sep 06 21:49:22 firstinstall apachectl[859]: AH00558: apache2: Could not reliably determine the server's full>
Sep 06 21:49:22 firstinstall systemd[1]: Started apache2.service - The Apache HTTP Server.
Verify Apache is configured properly by entering the following command in a browser URL http://<your server's IP Address>/
Step 3 Activate and Configure the Uncomplicated Firewall (UFW)
This consists of 6 commands:
1. sudo ufw enable
2. sudo ufw disable
3. sudo ufw status
4. sudo ufw app list
5. sudo ufw allow ‘Apache Full’
6. sudo ufw allow ‘OpenSSH’
Ubuntu uses the Uncomplicated Firewall (UFW).
The Uncomplicated Firewall is a wrapper that makes it easier to manage the Linux built-in iptables firewall. In other words, iptables is the actual firewall.
For our purposes, we will use a subset of the UFW commands. Basically, all we need from UFW is to open the Apache server’s ports, along with opening the OpenSSH ports. UFW can do a lot more than we will cover here.
Enable and start UFW: sudo ufw enable This activates the firewall with default settings.
1. sudo ufw disable turns off the firewall.
2. sudo ufw status shows whether UFW is active and displays the rules currently in place.
In Ubuntu, the Uncomplicated Firewall (UFW) simplifies the process of managing firewall rules. UFW has predefined application profiles for commonly used services.
To allow the Apache web server port 80 (not secured/HTTP) and port 443 (secured/ HTTPS) issue the command sudo ufw allow ‘Apache Full’
To allow the OpenSSH port to be opened, issue the command sudo ufw allow ‘OpenSSH’
At this point you can run sudo ufw status to verify how UFW is configured.
To verify Apache is still available access http://<your server’s IP>/ in your web browser.
Step 4 Install the MySQL Data Server
We will cover 6 commands:
1. sudo apt install mysql-server
2. sudo systemctl start mysql
3. sudo systemctl stop mysql
4. sudo systemctl enable mysql
5. sudo systemctl status mysql
6. sudo mysql_secure_installation
To install the MySQL package and all of its dependencies run ”sudo apt install mysql-server“.
Run sudo systemctl enable mysql to ensure MySQL starts on every reboot.
The command sudo systemctl start mysql starts the data engine.
The command sudo systemctl stop mysql stops the data engine.
sudo systemctl enable mysql sets MySQL to start on boot.
sudo systemctl status mysql provides the status of the MySQL data engine.
sudo mysql_secure_installation is a shell script that secures your MySQL installation. We will not cover this in this article.
To install PHP run the command sudo apt install php libapache2-mod-php php-mysql
on the command line.
To verify the PHP programming language has been installed, run the command php -v.
Step 6 Install Command-Line PHP
We will cover 2 commands:
1. sudo apt install php-cli
2. php -v
To install the PHP command line package issue the command sudo apt install php-cli.
To verify issue the command php -v
Step 7 Test Your LAMP Stack
Test PHP
Vi instructions:
1) To utilize vi issue the command “vi <file-name>”.
2) Once a file is opened using vi, press the “i” to go into insert mode.
3) Then copy the below-provided code and then place your cursor into vi and press the CTRL P keyboard combination. This will insert the text into the file being edited by vi.
4) Press the “esc” key to put vi into command mode.
5) Then press the colon key “:” Look to the lower left of the vi editor.
6) Then press the “w” key followed by the “q” key. The lowercase “w” is for write and the lowercase “q” is for quit.
Enter the command sudo vi /var/www/html/info.php
Cut and paste the following code into the file being edited.
<?php
phpinfo();
?>
Test using a browser by entering the following in the URL of the browser and then press the enter key. http://<your-ip-address>/info.php
Test PHP/MySQL Connection
Enter the command sudo mysql
Enter the command ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
Enter the command exit;
Enter the command sudo vi /var/www/html/test-db-connection.php
Cut and paste the following into the file test-db-connection.php
Test the connection using a browser by entering the following in the URL of the browser and then pressing the enter key. http://<your-ip-address>/test-db-connection.php
If you would like to check the status of MySQL enter the command sudo systemctl status mysql
Test Command line PHP
Cut and paste the following 3 lines into the file test-cli.php
Enter the command sudo vi /var/www/html/test-cli.php
Cut and paste the following.
<?php
echo "PHP CLI is working!\n";
?>
On the command line issue the command “php /var/www/html/test-cli.php”.
Troubleshooting
The command sudo systemctl status mysql will display the current status of the MySQL service, including whether it is active, inactive, or failed. If MySQL is running properly, you should see an output indicating that the service is active and running. If it’s not running or has issues, the status output will provide some details on the problem.
Conclusion
In this article, I covered how to install Apache, MySQL, and PHP on Linux, a LAMP Stack on Ubuntu 24.04LTS Server. Then we test that the configuration to verify it is working correctly. I use Ubuntu 24.04 LTS, Apache2, MySQL and PHP to build web apps.
This article will cover the steps necessary to clone a virtual machine (VM) on VirtualBox.
I am a PHP developer and use virtual machines running Linux for development and testing.
My configuration consists of a Windows 10 laptop with VirtualBox running on it. VirtualBox is virtualization software that allows one the ability to add guest virtual machines (VMs).
In my case, I use this configuration to build website hosting configurations. I create these web hosting servers using Linux, Apache, MySQL, and PHP (LAMP).
I start by creating a Ubuntu 24.04LTS server as a VM on VirtualBox. Then I create a LAMP setup as a VM and then clone it for a project.
LAMP stands for Linux, Apache, MySQL, and PHP.
There are 7 steps to create a clone.
Step 1 is to stop the VM to be cloned, if it is running.
Step 2 Right mouse click on the VM to be cloned
Step 3 Click on Clone from the drop-down menu
Step 4 Give the clone a name. Fill in the path. And in the MAC address policy drop-down select “Generate new MAC address for all network adapters”. For the clone to be a viable server on your network it needs a different MAC address from the server that is being cloned. The clone will also need a different IP address from the server that is being cloned.
Step 5 Select Full clone for “Clone type” as full.
How to Determine What IP Address Your Server is Using
If you are using VirtualBox, once the VM is activated, you will have the opportunity to log in. Once logged in you can use the commands “ip a” and/or ifconfig”. Both provide the same information.
Ifconfig was not available on my server so I had to install it by installing “net-tools”.
To install net-tools issue the command:
sudo apt install net-tools
After installing net-tools you will be able to issue the command ifconfig.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:9a:86:38 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.80/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe9a:8638/64 scope link
valid_lft forever preferred_lft forever
This output gives us the same information.
An Example of a Dynamic (DHCP) IP Address Configuration
Log into your server.
Issue the following command: “cd /etc/netplan” and press the enter key.
Then issue the command “vdir” and press the enter key.
There should be a file that end in .yaml in that directory.
Mine is : 50-cloud-init.yaml
At that point enter “sudo vi 50-cloud-init.yaml”. Make sure you use your file’s name in place of mine.
Sudo allows you to become the root user/superuser. Vi is my Linux command line editor of choice.
At this point, the configuration file will be opened in vi.
Your file should look very similar to the following:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
dhcp4: true
version: 2
Issue the following command: “cd /etc/netplan” and press the enter key.
Then issue the command “vdir” and press the enter key.
There should be a file that end in .yaml in that directory.
Mine is: 50-cloud-init.yaml
At that point enter “sudo vi 50-cloud-init.yaml”. Make sure you use your file’s name in place of mine.
Sudo allows you to become the root user/superuser. Vi is my Linux command line editor of choice.
At this point, the configuration file will be opened in vi.
Your file should look very similar to the following:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
addresses:
- 192.168.1.80/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
routes:
- to: default
via: 192.168.1.1
version: 2
This is the configuration for a static IP address.
Backup Current Network Configuration before Starting
Backing up your configuration files before changing them is a good habit to get into.
This is easy to do. For example, file 50-cloud-init.yaml is easily backed up by just making a copy of the file with a change to the file name. Here is the command :
1) Change the IP of the server by replacing the current IP address. This file shows an IP address of 192.168.1.80. Change it to what you would like it to be.
2) Change the name servers. This file shows Google’s name servers of 8.8.8.8 and 8.8.4.4. You can change them to other name server values.
3) Change the gateway which in this file is 192.168.1.1. Change it to another gateway if need be.
4) The subnet can be modified by editing the subnet that is part of the IP address. In this case the IP along with the subnet is 192.168.1.80/24. Notice the “/24”. That is the subnet for this configuration. You can modify the “/24” to increase or decrease the number of IP addresses that are available in the configured network.
Step 2 :
In the static configuration file “/etc/netplan/50-cloud-init.yaml” you will notice that there is some notes. These notes must be followed. They are listed as follows:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
The notes say we must create a file “/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg” and write the following into it: “network: {config: disabled}”, in the folder /etc/cloud/cloud.cfg.d/.
This can be accomplished by issuing the command “sudo vi /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg”.
If the file is empty add the line: “network: {config: disabled}” and save it.
If you are using vi press the “i” key to place vi into insert mode, then copy and paste the line. Then press the escape key to move vi into command mode. Then press the colon key followed by “wq”. Then press the enter key.
The “wp” are for write and quite.
At this point issue the command “sudo netplan try”. If there are no errors you can issue “sudo netplan apply”.
If there are no errors you have success.
Potential Error That Might Occur During This Process
If your configuration file is not indented properly, you will get an error.
Here is what it might look like :
“Error in network definition: expected mapping (check indentation)
ethernets:”
The error tells you where the error is located. In this case, it is an indentation error.
Edit the configuration file and verify it is configured correctly.
Then issue the command “sudo netplan try”. If all is correct you might see a message that the configuration will automatically be accepted.
If not issue the command “sudo netplan apply”.
Verifying the IP Has Been Changed
To verify the configuration has taken place you can issue the commands “ip a” and/or “ifconfig”.
I would recommend that you power off your server and then power it back on and then verify the IP is correct.
Conclusion
In this article, we learn how to clone an existing guest on VirtualBox. We learn how to give the clone a unique MAC address and a unique IP address. We learn what an IP is, why it is important, and how to manage IP addresses on an Ubuntu 24.04LTS Server. We learn how to identify a static IP address configuration and a dynamic IP address configuration. Then we learn how to change the static IP from one address to another. We learn the Linux commands “ip a”, “ifconfig” and learn a bit about the Linux editor vi. And finally, we learn it is a good practice to back up a configuration file before we modify it.
This article will cover the steps necessary to change a static IP to another static IP.
I am a PHP developer and use virtual machines running Linux for PHP development and testing.
My configuration consists of a Windows 10 laptop with VirtualBox running on it. VirtualBox is virtualization software that allows one to add guest virtual machines (VMs).
In my case, I use this configuration to build website hosting configurations. I create these web hosting servers using Linux, Apache, MySQL, and PHP (LAMP).
What is an IP Address
Simply stated an IP address is the address of a device on a network and/or internet. An IP is like the address of your house or your phone number on your phone.
What Is a Static IP Address
A static IP is an IP address that does not change. There are two types of IP addresses. 1) There is dynamic which is given by the router and 2) static which is configured never to change.
The Benefits of a Static IP
In the case of web servers, they must have static IP addresses. The static IP is required because of how servers work and how other devices interact with them.
This article is about changing a static IP address on the Ubuntu 24.04LTS server.
Step 1 is to identify how the server is configured.
How to Determine What IP Address Your Server is Using
If you are using VirtualBox, once the VM is activated, you will be able to log in. Once logged in you want to use the commands “ip a” and ifconfig”. Both provide the same information.
Ifconfig was not available on my server so I had to install it by installing “net-tools”.
To install net-tools issue the command:
sudo apt install net-tools
After installing net-tools you will be able to issue the command ifconfig.
The command “ip a” will provide the same information, just in a different format.
An Example of a Dynamic (DHCP) Configuration
Log into your server.
Issue the following command: “cd /etc/netplan” and press the enter key.
Then issue the command “vdir” and press the enter key.
There should be a file that ends in .yaml in that directory.
Mine is : 50-cloud-init.yaml
At that point enter “sudo vi 50-cloud-init.yaml”. Make sure you use your file’s name in place of mine.
Sudo allows you to become the root user/superuser. Vi is my editor of choice.
At this point, the configuration file will be opened in vi.
Your file should look very similar to the following:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
dhcp4: true
version:
If your file looks like this one your network is configured for dynamic IP allocation or Dynamic Host Configuration Protocol (DHCP). This means you will need to read and follow this article : How to Change IP Address From DHCP to Static in Ubuntu
An Example of a Static Configuration
Log into your server.
Issue the following command : “cd /etc/netplan” and press the enter key.
Then issue the command “vdir” and press the enter key.
There should be a file that ends in .yaml in that directory.
Mine is : 50-cloud-init.yaml
At that point enter “sudo vi 50-cloud-init.yaml”. Make sure you use your file’s name in place of mine.
Sudo allows you to become the root user/superuser. Vi is my editor of choice.
At this point, the configuration file will be opened in vi.
Your file should look very similar to the following:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
addresses:
- 192.168.1.80/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
routes:
- to: default
via: 192.168.1.1
version: 2
This is the configuration for a static IP address.
Backup Current Network Configuration Before Starting
It is a good habit to get into – backing up your configuration files before changing them.
This is easy to do. For example, file 50-cloud-init.yaml is easily backed up by just making a copy of the file with a change to the file name. Here is the command :
Cp is the copy command. Notice I added “-original” to the back up file name.
So now we should have two files in the directory :
1) 50-cloud-init.yaml – the working configuration file
2) 50-cloud-init.yaml-original – the original configuration file that is a backup of the original configuration.
You can verify by using the vdir command, which lists the contents of the directory we are in.
Making a backup of the original backup file could save you some pain if you need to figure out how the server was originally configured.
Changing a Static IP
This is a two-step process assuming your server is already configured with a static IP.
Step 1 :
Issue the command “sudo vi /etc/netplan/50-cloud-init.yaml” on the command line. Replace your file name for mine.
You can make several changes to this file :
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
addresses:
- 192.168.1.80/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
routes:
- to: default
via: 192.168.1.1
version: 2
1) Change the IP of the server by replacing the current IP address. This file shows an IP of 192.168.1.80. Change it to what you would like it to be.
2) Change the name servers. This file shows Google’s name servers of 8.8.8.8 and 8.8.4.4. You can change them to other name server values.
3) Change the gateway which in this file is 192.168.1.1. Change it to another gateway if need be.
4) The subnet can be modified by editing the subnet that is part of the IP address. In this case, the IP along with the subnet is 192.168.1.80/24. Notice the “/24”. That is the subnet for this configuration. You can modify the “/24” to increase or decrease the number of IP addresses that are available in the configured network.
Step 2 :
In the static configuration file “/etc/netplan/50-cloud-init.yaml” you will notice that there is some notes. These notes must be followed.
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
This can be accomplished by issuing the command “sudo vi /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg”.
If the file is empty add the line : “network: {config: disabled}” and save it.
If you are using vi press the “i” key to place vi into insert mode, then copy and paste the line. Then press the escape key to place vi into command mode. Then press the colon key followed by “wq”.
The “wq” is for write and quit.
At this point issue the command “sudo netplan try”. If there are no errors you can issue “sudo netplan apply”.
If there are no errors you have success.
Potential Error That Might Occur During This Process
If your configuration file is not indented properly, you will get an error.
Here is what it might look like :
“Error in network definition: expected mapping (check indentation)
ethernets:”
The error tells you where the error is located. In this case, it is an indentation error.
Edit the configuration file and verify it is configured correctly.
Then issue the command “sudo netplan try”. If all is correct you might see a message that the configuration will automatically be accepted.
If not issue the command “sudo netplan apply”.
Verifying the IP Has Been Changed
To verify the configuration has taken place you can issue the commands “ip a” and/or “ifconfig”.
I would recommend that you power off your server and then power it back on and the verifying the IP is correct.
Conclusion
In this article, we learn what an IP is, why it is important, and how to manage IP addresses on an Ubuntu 24.04LTS server. We learned how to identify a static and a dynamic configuration. Then we learned how to change the static IP from one address to another.
I am a PHP programmer using Ubuntu for Linux, Apache, MySQL, and PHP (LAMP ) servers, and I need a static IP address on that server.
If for some reason the server is configured with Dynamic Host Configuration Protocol (DHCP) I will need to convert the IP configuration to static.
Under DHCP the router assigns an IP address to the device. This IP may change on subsequent reboots.
In this article, I will show you how to convert a DHCP configuration to a static IP configuration on Ubuntu server 24.04LTS.
I have a Windows laptop that runs VirtualBox and the Ubuntu server is a guest on VirtualBox.
The first thing to do is to determine the network interface name.
To do so I need to ensure VirtualBox and the Ubuntu server are up and running.
To access a Ubuntu server I use PuTTY to Secure Shell (SSH) into the server. This will require you to know the existing IP address or domain name of the server.
Since I created the server as a VirtualBox guest it is easy for me to gain (SSH) access by simply launching the server.
Step 1 is to log into the Ubuntu Server on the command line. Since this is a server it will not have a Graphical user interface (GUI).
Step 2 is to update the server’s repository. We do so by entering the below command on the command line.
sudo apt update
Step 3 is upgrading those packages. This means if there are packages that can be upgraded to a newer version they will be upgraded.
sudo apt upgrade
Step 4 is to remove any old and non-used packages and any old Kernels.
sudo apt autoremove
Step 4 is to install net-tools. Net-tools is a collection of networking utilities.
We need two bits of information 1) the network device is enp0s3, and 2) the IP address of this server is 192.168.1.112.
We can also use the command “ip a”. It will return something like this:
$ ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:fd:65:fc brd ff:ff:ff:ff:ff:ff
inet 192.168.1.112/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fefd:65fc/64 scope link
valid_lft forever preferred_lft forever
This tells us the same two things:
For this server, the network device is enp0s3. Yours might be eth0 or something to that effect.
The IP of this server is 192.168.1.112
Netplan is the default network management tool. Netplan was introduced to Ubuntu in 2016.
In the directory /etc/netplan/ we will find a file named something like “50-cloud-init.yaml”
From a DHCP configuration:
File: /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s3:
dhcp4: true
version: 2
Notice the line “ This file is generated from information provided by the datasource Changes to it will not persist across an instance reboot.”.
Then there is the second to the last line that says we must create a file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg. And the last line says we must write “network: {config: disabled}” into that file and save it.
From a static configuration :
File: /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
enp0s3:
addresses:
- 192.168.1.83/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
routes:
- to: default
via: 192.168.1.1
We change the server to a static IP by editing it’s configuration. To do so enter the following command: (not the file name might be different)
sudo vi /etc/netplan/50-cloud-init.yaml, and create a configuration like this:
8.8.8.8 and 8.8.4.4 are Google’s name servers, which you can keep or use your own.
192.168.1.1 is the gateway and you need to replace it with your own.
Then create the file /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg and add to it “network: {config: disabled}” and save it.
Once you have completed these steps test the configuration with the command “netplan try”. If there are no errors, issue the command “netplan apply”.
To confirm the configuration is working, issue the command “ip a”. If this shows the correct IP address then power down your server and then power it on again. Issue the command “ip a”. If this shows the correct IP address, you have successfully changed your Ubuntu 24.04LTS network configuration from dynamic to static.
Note if your remote connection loses its connection, the changes you have made may have taken effect and you will need to establish a new remote connection.
Conclusion
In this article, we have taken an Ubuntu 24.04LTS server that was initially configured with a dynamic network connection configuration (DHCP) to a static IP. This required editing the network configuration and changing it to a static configuration. We also created a file that disabled the network from automatically reverting back to the original configuration.
I asked ChatGPT 3.5 “Can AI write PHP code?”. ChatGPT 3.5 is a free version of Artificial Intelligence.
I’ve been a freelance PHP developer since 2006. I consider myself to be a senior developer.
Here is what ChatGPT responded:
Yes, AI can be trained to generate PHP code. PHP is a widely used scripting language for web development, so some models and tools can assist in generating PHP code snippets or even more complex scripts.
However, it’s important to note a few things:
1.**Quality and Intent**: The quality of AI-generated code can vary. AI can produce syntactically correct code based on training data, but it might not always produce efficient or well-structured code that adheres to best practices or security guidelines without careful oversight.
2.**Use Cases**: AI-generated PHP code can be useful for generating boilerplate code, automating repetitive tasks, or even suggesting solutions based on specifications. It can help developers save time and focus on higher-level aspects of development.
3.**Limitations**: AI models are trained on existing data and patterns. They might struggle with highly specialized or novel requirements that deviate significantly from the data they were trained on.
4.**Human Oversight**: Regardless of AI assistance, human oversight, and validation are crucial. Developers should review and test all generated code to ensure it meets project requirements and standards.
In summary, AI can write PHP code and assist developers in various ways. Still, it is most effective as a tool to augment human creativity and expertise rather than replace it entirely.
I’ve been experimenting with ChatGPT 3.5 for maybe 6 weeks as of the writing of this article. I am interested in article writing and PHP code creation.
Before we get started, let’s discuss what is known as prompts. Prompts are the way to interact with ChatGPT 3.5. The better the prompt the better the reply from ChatGPT 3.5.
It is a learning experience.
The other thing that needs to be discussed immediately is the more PHP programming experience the developer has, increases the potential for using and implementing PHP code produced by ChatGPT 3.5.
Recently my local Linux group discussed using AI to generate code. The consensus was that in the short term, there would be little change. The short term is maybe the next 3 years.
The group felt that at some point the junior and mid-range PHP developers would be displaced.
The group also found this scenario interesting in that as the senior developers retire or exit programming there would be no one to replace them, as the juniors and mid-range developers would be non-existent. It might take 6 to 10 years to create a senior developer.
Let me give you a few examples.
If I ask AI to “create a login script in PHP using the MySQL database”. ChatGPT responded:
Creating a login script in PHP using MySQL involves several steps, including connecting to the database, querying user credentials, and validating the login. Below is a basic example of how you can implement this:
1.**Create a MySQL Database:**
First, you need a MySQL database with a table to store user information. Here’s an example SQL to create a `users` table:
CREATE TABLE users (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT NULL, — Hashed password
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Note: Always hash passwords before storing them in the database for security reasons.
Use PHP’s `password_hash()` function for this purpose.
2.**PHP Login Script:**
Create a PHP script (`login.php`) that handles the login process. Here’s an example:
<?php
session_start();
// Database connection parameters
$host = 'localhost';
$db = 'your_database';
$user = 'your_username';
$pass = 'your_password';
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Check if form was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
// Prepare the SQL statement
$stmt = $conn->prepare("SELECT password FROM users
WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
// Check if user exists
if ($stmt->num_rows > 0)
{
$stmt->bind_result($hashedPassword);
$stmt->fetch();
// Verify the password
if (password_verify($password, $hashedPassword))
{
// Set session variables
$_SESSION['username'] = $username;
header("Location: welcome.php"); // Redirect to welcome page
exit();
} else {
$error = "Invalid username or password.";
}
} else {
$error = "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<?php if (isset($error)): ?>
<div style="color: red;">
<?php echo $error; ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required>
<br>
<label for="password">Password:</label>
<input type="password" name="password" id="password" required>
<br>
<button type="submit">Login</button>
</form>
</body>
</html>
Instructions:
Database Setup: Ensure you have a MySQL database with a users table containing username (VARCHAR) and password (VARCHAR) fields. Use password_hash() when storing passwords.
Testing: Access login.php in your web browser, enter your credentials and check the behavior on both successful and failed logins.
Redirect Page: Create a welcome.php file to greet the user after login.
Security Notes:
Ensure your site uses HTTPS to protect user credentials.
Implement measures against SQL injection (this script uses prepared statements, which helps).
Consider adding Cross-Site Request Forgery (CSRF) protection for your forms.
Secure session management practices should be followed.
Feel free to customize the layout and logic to fit your application’s needs!
I ask “Should a cookie be implemented?” AI responds:
Implementing cookies can enhance user experience, especially for remembering user sessions or preferences. However, it’s important to handle them securely. Here are some points to consider regarding cookies in the context of a login system:
When to Use Cookies
Remember Me Functionality: Allow users to stay logged in even after closing their browser. This is usually done by storing a cookie with a token.
User Preferences: Save user-specific settings, like theme or language.
Security Considerations
Secure and HttpOnly Flags: Set the Secure flag for cookies to ensure they are only sent over HTTPS. The HttpOnly flag prevents client-side scripts from accessing the cookie, reducing the risk of XSS attacks.
SameSite Attribute: Use the SameSite attribute to help protect against CSRF attacks by controlling how cookies are sent with requests.
Token-Based Authentication: If you implement a “Remember Me” feature, use a securely generated token stored in the cookie, linked to the user’s session on the server.
Example of Implementing Cookies
Here’s a modified version of the login script that includes a “Remember Me” feature:
Updated login.php
<?php
session_start();
// Database connection parameters
$host = 'localhost';
$db = 'your_database';
$user = 'your_username';
$pass = 'your_password';
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
// Check if form was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$rememberMe = isset($_POST['remember_me']);
// Prepare the SQL statement
$stmt = $conn->prepare("SELECT password FROM users
WHERE username = ?");
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
// Check if user exists
if ($stmt->num_rows > 0)
{
$stmt->bind_result($hashedPassword);
$stmt->fetch();
// Verify the password
if (password_verify($password, $hashedPassword))
{
// Set session variables
$_SESSION['username'] = $username;
// Handle "Remember Me" functionality
if ($rememberMe)
{
// Generate a token
$token = bin2hex(random_bytes(16));
// Store the token in the database with the username
$stmt = $conn->prepare("UPDATE users SET
remember_token = ? WHERE username = ?");
$stmt->bind_param("ss", $token, $username);
$stmt->execute();
setcookie("remember_me", $token, time() +
(86400 * 30), "/", "", true, true); // 30 days
}
header("Location: welcome.php"); // Redirect to welcome page
exit();
} else {
$error = "Invalid username or password.";
}
} else {
$error = "Invalid username or password.";
}
$stmt->close();
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<?php if (isset($error)): ?>
<div style="color: red;"><?php echo $error; ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required>
<br>
<label for="password">Password:</label>
<input type="password" name="password"
id="password" required>
<br>
<label for="remember_me">
<input type="checkbox" name="remember_me"
id="remember_me"> Remember Me
</label>
<br>
<button type="submit">Login</button>
</form>
</body>
</html>
Additional Steps
Database Changes: Ensure your users table has a remember_token column to store the token.
Token Validation: On subsequent visits, check if the cookie is set. If it is, validate the token against the database and log the user in automatically.
Logout Logic: Clear the cookie and remove the token from the database when a user logs out.
Conclusion
Using cookies responsibly can enhance user experience, but always prioritize security by following best practices.
ChatGPT can make mistakes. Check important info.
Summary
I asked ChatGPT to create a PHP login script as an example and to answer the question “Can AI write PHP code?”. It does a great job. This experiment reinforces my statement that to effectively use AI to generate code, requires a senior developer.
Upon request, AI-generated login cookie code with lots of comments and explanations.
All in all, I think using AI, as a senior developer, might reduce development time by 30% – 50% – a big savings.
I did not mention that AI can have what is referred to as hallucinations. It would be worth your time to understand AI hallucinations.
Some say a full-stack PHP developer is someone who can program both on the client-side and the server-side. The server side is programming in PHP and the client-side is programming in the browser using JavaScript.
Others define a full-stack developer as someone who can troubleshoot both the software layer and the server layer.
I like both definitions. I think a full-stack PHP developer is someone who has, at least, enter-level PHP web server system administrative skills and the ability to deal with the full programming stack.
Lets Break That Down
There are two parts to this – The software layer and the Linux PHP hosting layer.
I believe all PHP developers should have a basic familiarity with Linux. I think a PHP programmer should use Linux on their desktop (unless there is a reason not to) and have the skills to configure a basic LAMP or LEMP testing server.
The PHP web server Consists of:
LAMP stands for:
Linux – The operating system.
Apache – The web server.
MySQL – The data engine.
PHP – The programming language.
LEMP stands for:
Linux – The operating system.
NGINX – The web server.
MySQL – The data engine.
PHP – The programming language.
Notice the difference is Apache vs NGINX web servers.
The software layer consists of:
Hypertext Markup Language (HTML) – HTML is the bones or structure of the website.
Cascading Style Sheets (CSS) – CSS gives a website its look and feel
JavaScript, JavaScript library or framework, and AJAX – JavaScript and the associated frameworks and AJAX are used to create interactive web pages.
The PHP programming language – PHP is a server-side programming language which means it runs on the server and sends output to the browser.
Structured Query Language (SQL) – SQL is used by the developer to talk to the MySQL data engine.
There is a lot to know. Knowing and being able to work with all that has been outlined above, in my opinion, makes one a full-stack developer.
What a Full-Stack PHP developer is can depend on who is defining what a Full-Stack PHP Developer is. There are two definitions 1) a PHP programmer that can program both on the server-side and on the client-side, and 2) a PHP developer than can troubleshoot both the client-side software, the server-side software, AND the PHP web hosting server itself.
I believe a PHP developer must have basic Linux hosting skills. This does not mean this developer needs to be a production server administrator. What I am saying is this PHP developer should be able to configure a LAMP or LEMP stack for testing.
In this article, I will cover the Hedgehog Concept and how it will help you determine if you should become a PHP programmer.
My name is Keith Smith. I have been a freelance PHP programmer since 2006 and I have evaluated my career choices several times using the Hedgehog Concept.
I first become aware of the Hedgehog Concept through the book “Good to Great” by Jim Collins. The book was copyrighted in 2001 and I read it in 2005 at the suggestion of my employer. Interestingly my employer at the time was not following the teachings of this book.
The book “Good to Great” is about how businesses move from good to great and the book shares many findings. One of which is the Hedgehog Concept.
Hedgehog Concept
In a nutshell, the Hedgehog Concept leads us to that one big thing we should focus on. In business, it is the service, product, or concept that is right for that particular business. For instance, Walgreens is on almost every corner. How they got there is the reason they moved from good to great – they focused on what they could be the best at.
The Hedgehog concept can be used personally to evaluate our best career path at any given point.
Using this same set of principles will guide us to the one thing we should focus on.
The Fox and the Hedgehog
The Hedgehog Concept is based on an old Greek parable “The fox knows many things, but the hedgehog knows one big thing.”. Jim Collins took that parable and turned it into 3 questions that take us from being a fox that knows a lot of things to a Hedgehog who does great things because he is focused on his one big thing.
In this article, I am going to focus on how we can determine our personal Hedgehog Concept.
Our Personal Hedgehog Concept
I am only going to cover the Hedgehog Concept and how it is applied to us. We will look at it as our personal Hedgehog Concept, or what is the single or dominant thing we were encoded to do.
We are encoded with many abilities, however, one will more than likely be our personal Hedgehog Concept.
The Three Questions of the Hedgehog Concept
There are three principles or questions that make up our personal Hedgehog Concept.
What are you deeply passionate about?
What are you genetically encoded to do?
What drives your economic engine?
What Are You Deeply Passionate About?
Passion is an indicator of what you should be doing. If you are passionate about a particular area absent one of the other two indicators, this particular passion is not your one big thing. The area that you are passionate about and fulfills the other two indicators probably is your one big thing – or the thing you should concentrate on.
What Are You Genetically Encoded to Do?
Each of us is unique. Each of us was created with special skills and abilities – things we are naturally good at. By the time you become a teenager, you should start seeing your strengths and the things you are a natural at. Some are good at art, some are good at writing, some are good at business, etc.
What Drives Your Economic Engine?
This is a big one. You are looking for something you are passionate about that can drive your economic engine.
Putting All Three Together
Having passion about something you are a natural at, that also drives your economic engine is your one big thing – your Hedgehog Concept
I would recommend taking some time to go through this exercise before you decided on what you would like to do for a career.
A Real-Life Story
Let me share a story and why I think going through this process is important.
About 10 years ago a young man approached me at a men’s gathering and said he wanted to become a PHP programmer. I asked why. He told me that I was successful so he thought he would do what I do. That answer gave me a lot of insight. I was looking for passion. He was looking for a job or a skill that could create success.
At that point I suggested he determine his personal Hedgehog Concept and then if he determined becoming a PHP programmer was what he should pursue, then come back and we would talk. He never returned.
My Advice to Any Aspiring Programmer
Do not choose a career path just because those skills are in demand and because the pay is good.
Every one of us is encoded with certain abilities. And every one of us has a set of passions. We need to take the time to look deep inside to determine our correct path.
I’ve heard it said, “Do what you are passionate about and the money will follow.”. If you choose the wrong path you might end up less than satisfied or in the end, being miserable.
Let me give you an example. Registered Nurses (RN) get paid well and are in high demand. I have the ability to become an RN, however, I would be miserable because I am not passionate about being an RN. It’s just not me.
Summary
This article is about using the Hedgehog Concept to determine if you should become a PHP Programmer. By using the Hedgehog Concept we can determine our career path and lead a more fulfilling and richer life.
Checking your laptop battery from the command line is rather easy using the upower command. This article is an introduction to the Linux upower command and an example from my Linux laptop which is used as a PHP Programming test server.
Background
I have 2 laptops that I use as test servers. They were cheap so I bought one for my wife and one for me. We never really used them so I converted them into PHP programming test servers.
Originally I took the batteries out and stored them away from the computers because we were not using them as portal devices.
Theses computers are probably 4 years old. One battery is dead. Surprisingly the other battery appears to be in like new condition. It has been about 8 months since I changed the good battery and today it is showing 35% charged. It has been setting in my desk drawer.
The local Linux community tells me to keep my battery charged between 30 and 70 percent. They say anything below 30% will add extra wear to the battery as will any charge over 70%.
Currently I do not need the battery, however I may want to load something Like Mint Linux on this computer and use it as a mobile Linux computer. Therefore I would like to keep the battery in good condition and that is why I periodically charge the battery.
Monitoring Laptop Battery Charge
My laptop is running Ubuntu 16.04lts and I had to add the upower package. From the command line it is rather easy – two steps.
sudo apt-get update sudo apt-get install upower
This morning I put the good battery into my laptop and ran “upower -i” /org/freedesktop/Upower/devices/battery_BAT0 from the command line. Here is the output:
Notice my battery is at 37% change. Amazing!! I was expecting the battery to be dead.
To determine just the state of the battery, time to fully charge, and the percentage of charge, run the following command on the command line.
Since I am only charging my battery to 70%, I expect a much shorter charge time than what a full charge would take. It show it would take 1.7 hours for to fully charge.
Upower Man Page
You can learn more by running “man upower” on the Linux command line. The man page does not give much information, however for my needs, I do not need anything more than is documented in this article.
Conclusion
You may need to install the upower package which is very simple. I provide the command necessary to install the package from the command line on Debian and it’s derivative Linux distributions, such as Ubuntu 16.04lts.
If you need a simple way to monitor your laptop battery from the command line upower may be all you need.
This article explains what the CodeIgniter framework is and gives insight as to how CodeIgniter works.
CodeIgniter is Object Oriented, Model-View-Controller, a Rapid Application Development framework for PHP, that has a small footprint, is blazing fast, has a short learning curve, and is easy to install. CodeIgniter does this by providing commonly needed functionality, helpers, and libraries.
What is CodeIgniter
CodeIgniter was created by Rick Ellis the owner of Ellis Labs. The first release was on February 28, 2006. CodeIgniter was wildly successful and very popular within the PHP community.
CodeIgniter has a lot going for itself.
Small Footprint
Version 3.1.11 is only 16 megabytes in size. That is small. In the early days, CodeIgniter was less than 4 megabytes.
Version 2.2.6 is about 4K compressed and is 5.1 megabytes uncompressed.
Blazing Fast
Most report CodeIgniter is lightning fast. It is compatible with shared hosting which it’s pears cannot say. The CodeIgniter framework puts little stress on the hosting server.
Excellent Documentation
The manual covers, in detail, every aspect of how to use CodeIgniter to build websites and web applications. All features and functionality are well documented.
It is worth noting that in the upper right corner of the page there are three lines next to the search box. Clicking the three lines changes the layout to the old-style layout which is much more helpful.
Once clicked, a tab will appear in the upper right area named “Table of Contents”. If clicked, it will display a full menu that will give you access to every bit of the documentation.
Easy to Use
Ease of use is one of CodeIgniter’s hallmarks. It was created early before PHP added several features that are complicated. CodeIgniter 3 is simpler than CodeIgniter 4. CodeIgniter 4 embraces the PHP features that make it more complicated. For the one-man-band, those features are not necessary.
Easy to Install
To install CodeIgniter all that is required is to download the zip file and upload it to your server and unzip it. And point your web browser to the instilled Codeigniter and it should show you the welcome page.
Object-Oriented
Even though CodeIgniter is Object-Oriented, an inexperienced programmer will probably not notice since everything is well structured and well documented.
Model-View-Controller
As you probably already know CodeIgniter is Model-View-Controller. This design pattern is widely used and respected. It helps structure one’s code and makes it easier for multiple developers to work on the same project.
What is a Controller – This is the boss of the other two. It is the brain. This is where most of the programming logic is placed.
What is a View – Is the display layer. This is where the HTML, Cascading Style Sheets (CSS), JavaScript, AJAX, and content come together to create what shows in your browser.
What is a Model – This is where all the database functionality lives. These functions are called by the controller so the data can be processed and then sent to the view.
License
The current owner, British Columbia Institute of Technology, uses the MIT License. Here is what it says:
Copyright (c) 2014 – 2019, British Columbia Institute of Technology
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Currently, there is two versions of CodeIgniter. Version 3 and 4.
Some of the differences are:
CodeIgniter 4 is not backward compatible.
Version 4 has added support for Namespaces.
Autoloading support has been added to version 4
Life Cycle
According to the Codeigniter forums, Codeigniter 3 will be supported for about 2 more years.
The repository will live on. The only real issue with using Codeigniter 3 after community support ends is PHP version upgrades and security issues will go unaddressed.
Loosely Coupled
CodeIgniter is referred to as loosely coupled because only a controller is required. The model and view are not required to make a working website. Though, this is not the default configuration.
CodeIgniter Release History
VERSION
RELEASE DATE
END of LIFE
1
February 28, 2006
Unknown End of Life
2
January 2011
October 2015
3
October 2015
Currently Supported
4
February 24, 2020
Currently Supported
Helpers
There is about 21 helpers. Each is a set of functions that can be plugged into your code as you build your application. Helpers help the developer accomplish tasks. To get a feel for what a helper is let us look at a couple of helpers that are routinely used.
URL Helper Example
The URL helper is a set of functions that make working with URLs easier. You can read the on-line URL Helper documentation for more information.
For example, to convert the title of an article into a URL string, the helper function url_title($title) could be used. Here is some sample code:
$title = "Why I Like Ice Cream";
$url_title = url_title($title)
$url_title will contain the string “why-i-like-ice-cream”. Which can be used to create a complete URL like example.com/why-i-like-ice-cream.
The whole idea is the helpers help the developer to write less code and spend less time doing so. This is the rapid application development feature mentioned elsewhere.
Email Helper Example
The email helper makes it easier for the developer to add email functionality to his or her application.
For example, to validate an email the developer can use the valid_email() helper function.
Here is an example:
$is_email_valid = false;
if (valid_email('someemailaddress@example.com'))
{
$is_email_valid = true;
}
There are about 30 libraries in CodeIgniter 3. Libraries help the developer complete larger tasks such as sending an email. Sending email takes a lot more effort than checking the validity of an email address such as what we previously performed.
The email library is a class that provides comprehensive functionality for sending emails. A glance at the on-line Email Class (library) might be surprising given all the options and setting that are needed to send an email.
What is CodeIgniter Used for?
Codeigniter is a PHP framework that was created as a PHP rapid application development tool. In the early days, Codeigniter was used to create all sorts of websites. CodeIgniter is still capable of creating any type of website you can think of, however, today it is mostly used to create web applications.
The Installation Process
If you are familiar with the Linux utility wget you can download the zipped file directly to your server and unzip it.
It is that simple.
It is not necessary to have access to the server command line.
Installation only takes a few minutes and is just a few steps.
With wget
Use wget to download the CodeIgniter zip file into the hosting root directory.
Unzip the source file.
You may need to rename or remove the leading CodeIgniter directory.
Point your browser to your CodeIgniter install and you should see the welcome page.
Without wget
Download the CodeIgniter source file onto your local computer.
Unzip the source file locally.
Upload the files to your server using FTP. Make sure not to include the CodeIgniter leading or root directory when uploading.
Point your browser to your CodeIgniter install and you should see the welcome page.
Verify it is Working
To verify your installation is working, all you need to do is point your browser to the server where you installed CodeIgniter.
If it is installed correctly you should see the welcome page.
This is a page that comes with CodeIgniter. It gives you the path to the view and the controller. Notice the last line contains a link to the User Guide. This is a local copy. You may want to bookmark this link so you will always have access to the documentation off-line.
How Does Codeigniter work
As you have read in this article, CodeIgniter is easy to install, is blazing fast, easy to learn, is well documented, and has a short learning curve. Add to that it is Model-View-Controller.
Codeigniter is a rapid application development tool for building PHP web applications. These applications can take the form of a content management system (CMS) to an interactive web application.
Because CodeIgniter comes with so many of the needed components for building web applications, in so many ways, it is plug and play. This keeps the developer from having to recreate the wheel every time they want to build a web application.
Let start by looking at the file system. Once installed you should see a file system that looks like this:
/application
/composer.json
/contributing.md
/index.php
/license.txt
/readme.rst
/system
/user_guide
To learn CodeIgniter it would be worthwhile looking through all the directories and open the files and read through them. Do not worry if some of it or even a large portion is hard to understand. It will be a worthwhile excise that will help you as you become a CodeIgniter developer.
In this article, we will limit our discussion to 4 directories and how they work. Knowing what we will be covering will place you well on your way to becoming a CodeIgniter developer.
As a starting point, let’s look at the welcome controller, welcome view, and the routes configuration that ships with CodeIgniter 3.
The welcome controller is located in: application/controllers/Welcome.php
You can find the view at: application/views/welcome_message.php
And the routes files is located at application/config/routes.php
The default URL mapping is example.com/controller/function/argument. In the case of the URL for the welcome message, it is example.com/index.php/welcome/index.
Controller
If we look in the controller we see several lines:
1) defined(‘BASEPATH’) OR exit(‘No direct script access allowed’); – this line verifies CodeIgniter is running. If not it sends a message to the browser and stops processing. This is a security measure so the only entry point is through the index.php file located in the root directory. This will keep the bad hackers from accessing your code in ways it was not intended.
2) class Welcome extends CI_Controller – Notice the controller class name is Welcome and it extends CI_Controller. This means it inherits everything in the CI_Controller class.
3) public function index()
{
$this->load->view('welcome_message');
}
The index function is the default function in the controller. Remember the URL mapping is /controller/function/argument. If no function is listed, the default is the function named index.
In the case of the welcome URL it is /index.php/welcome/. You can drop welcome from the URL leaving it as example.com/index.php.
Two things are taking place. One is the default controller that is defined in the routes.php file is being processed and the default function in the controller is used to complete the process so the welcome page can be displayed.
The line $this->load->view(‘welcome_message’); Tells CodeIgniter to load the view file named welcome_message’) and display it.
View
The view can be located at: application/views/welcome_message.php. A quick look inside shows it contains HTML, Cascading Style Sheets, and a minor amount of PHP code.
Data can be transferred to the view file and the view file can use PHP to display this data. It is possible to process data in a view, however, all the processing should take place in the controller and model.
Basically, a view is web content or what is known as the visual layer.
Model
In this case, there is no database in use so there is no model. We will cover the model later in the article.
Router
The routes file is located at: /application/config/routes.php. There is only one line in the file that we need to evaluate here. That line is: $route[‘default_controller’] = ‘welcome’;
What this line tells CodeIgniters is the default controller is the welcome controller that is listed above. That is why you can go to the website URL such as example.com/index.php and see the welcome message.
Removing index.php from the URL
To remove the index.php from the URL (example.com/index.php) refer to the manual page at: CodeIgniter URLs and then scroll down to “Removing the index.php file”.
If you are using shared hosting it is probably already configured to remove the index.php from the URL. If it is not configured you will get a blank screen or an error message.
If an error occurs or you get a blank screen contact your hosting provider for help.
Create a Model for the Welcome Application
Create a model class named “people_model” in the application/models/ directory. Name the file People_model.php. It is a good idea to create a model for each table. This will keep the models organized and by naming the model the same name as the table it makes it easy to understand what goes with what model and it also becomes self-documenting.
The model code looks like this.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class People_model extends CI_Model {
public function get_people()
{
$query = $this→db→get('people');
return $query->result();
}
}
As you can see the three names are listed on the home page.
Everything in CodeIgniter 3 is that easy.
Related Questions
Is CodeIgniter easy to learn?
CodeIgniter is very easy to learn. If you already know how to program in PHP at the beginner level and understand the basics of Object-Oriented Programming in PHP, then you will find CodeIgniter easy to learn. CodeIgniter has the shortest learning curve of all the PHP Frameworks.
How long does it take to learn CodeIgniter?
To learn CodeIgniter might take 10 to 15 days if you spend 2 hours a day studying CodeIgniter. Hands-on is very important. If you follow the brief tutorial listed above, you will be well on your way. Learning Codeigniter comes down to understanding how to create models, views, controllers, and how to implement and use the helpers and libraries.
Is CodeIgniter Still Relevant?
CodeIgniter has lost a lot of its popularity since Rick Ellis decided to give CodeIgniter to a new home.
On July 9th, 2013, Rick Ellis, the founder of EllisLab, announced he was looking for a new home for CodeIgniter. At that time CodeIgniter was arguably the most popular PHP framework. Click here to read Ellis’ online statement – EllisLab is seeking a new owner for codeigniter
That announcement set the stage for 2 things to happen. First, it threw the Codeigniter community into chaos because the future was unknown. Because of that a lot of developers fled to other PHP frameworks. After the dust cleared it appears most of the developers moved to Laravel. The second thing put in motion was CodeIgniter would become like the other PHP frameworks. Its footprint would increase, it would become more complicated and harder to learn. Ellis said it: “
PHP as a language is maturing, and CodeIgniter deserves to take advantage of its new stabilized features.”.
This announcement was a death sentence for CodeIgniter. CodeIgniter 4 contains Namespace and utilizes PHP Composer. These two are not necessarily needed and add to the learning curve.
CodeIgniter is slowly losing what sets it apart – being blazing fast, having a small footprint, and being extremely easy to install and learn.
If you are looking at CodeIgniter as a future skillset I’d caution you to look beyond. Having said that, there are still COBOL programmers out in the wild. I suspect there will be a need for CodeIgniter developers for a while.
There is a lot to be learned from using CodeIgniter. Installing and learning how to use it is a great learning experience. I learned a lot from using CodeIgniter and looking at its source code to understand how things work..
I learned about Model-View-Controller, and how to modularize my code. When it was all said and done I was able to analyze CodeIgniter to gain the knowledge necessary to develop my small framework.
Installing and using CodeIgniter will never be waste, it is a great learning opportunity, especially if you go into it with that mindset.
Is CodeIgniter Dead?
Some think the current owners of CodeIgniter, the British Columbia Institute of Technology, is taking CodeIgniter down the wrong path.
The downward spiral started the day Rick Ellis announced he was looking for a new home for CodeIgniter. At that very point, the future of CodeIgniter was thrown into chaos. A lot of CodeIgniter users migrated to other PHP frameworks. Most moved to Laravel.
CodeIgniter’s niche used to be that is had a small footprint, was blazing fast, was easy to install, and had a small learning curve. With version 4 in its early days, CodeIgniter is starting down the path towards trying to compete with the other PHP frameworks. Trying to compete with the other PHP frameworks is a mistake.
CodeIgniter needs to go back to its roots of having a small footprint, being blazing fast, being easy to install, and having a small learning curve.
Google trends show CodeIgniter gets about 60 searches a day.
Then when we look at the comparison of CodeIgniter vs Laravel, it looks like CodeIgniter is getting less than 10 searches a day and Laravel is around 75 searches a month.
This indicates the interest in CodeIgniter is rather low.
Conclusion
This article is a brief look at CodeIgniter.
There is two version – 3 and 4.
CodeIgniter is MVC.
It has helpers and libraries.
It is easy to learn and has a short learning curve of maybe 20 – 30 hours before the developer is ready to start building real-world applications.
CodeIgniter has a small footprint, is blazing fast, and easy to learn (version 3).
Version 4 is starting down the path away from the roots of CodeIgniter and moving out of its niche.
This article introduces phpMyAdmin and gives a brief overview of how it works.
phpMyAdmin is free, open source, and was created using the PHP programming language. It was created as a wrapper around the MySql database. PhpMyAdmin is a web interface that gives the user the ability to manage their databases from any device that runs a modern web browser.
What is phpMyAdmin
phpMyAdmin is a free software tool that is used to administer the MySql data engine. It was created in PHP. It was first released in September 1998. Being very mature, it is well documented and widely used.
Some of the things you can do with phpMySql are create and test SQL queries, manage databases, and manage users.
phpMyAdmin is very feature-rich. It is used as a web interface for the MySql data engine and its derivatives.
I use it often when I need to create a complicated SQL query. SQL stands for Structured Query Language, which is how programmers interface with databases.
In the next section, we will dig a little deeper.
How Does it Work
Login – To get started one must log in with a MySql username and password. This will give the user access to any databases they have permission to use.
The phpMyAdmin Home Page – Once logged in you will see the phpMyAdmin Home Page that will look like the following.
In the upper left area is where you can find the main menu.
Main Menu Functionality
To return to the home page click the “phpMyAdmin” text.
The “home” icon returns to the home page as well.
The next icon which looks like a door with a green arrow, is the logout button.
The round icon that contains a question mark links to the local phpMyAdmin documentation.
The icon that looks like a page with a smaller page over it is linked to the MySql reference manual.
The gear is liked to the settings pages.
The green icon causes the page to refresh when clicked.
Top Menu Functionality
The top menu will be referred to as tabs in this article.
Databases – Linked to the databases page.
SQL – Linked to one of the two query building pages. This is the less feature-rich version of the two SQL pages.
Status – Linked to a stats page.
User account – Links to the user account overview page.
Export – Linked to the export database page.
Import – Linked to the import page.
Settings – Linked to a page that provides for import and export configuration.
Replication – Linked to the replication configuration page.
Variables – Linked to the server variables and settings page.
Charsets – Linked to the character settings and collation page.
Engines – Links to the storage engine page.
Plugins – Links to the plugins page.
Home Page List of Databases and Tables
On the left side of the home page, you will see a list of databases. By clicking on a database, it will expand to display the tables within that database.
Manage Users
Create a User:
Click the “home” icon, click the “User accounts” tab, then click “Add user account” which is about in the middle of the form.
Complete the form.
Modify a user account:
Click the “home” icon, click the “User Accounts” tab, then click the “Edit privileges” link that is on the same line as the user account you want to modify.
On this page you can:
Edit the user’s privileges.
Add privileges to other databases.
Grant or revoke global privileges.
Change the user’s password.
Change the login information (username, hostname, password).
Remove a user:
Click the “home” icon.
Click the “User Accounts” tab.
Click the checkbox next to the user you want to remove.
Then select “Drop the databases that have the same names as the users” if you want to remove the database with the same name as the user.
Click the “Go” button.
About User Privileges
User privileges are what access the user is given. Such as what databases they can see and modify and from where, such as being restricted to the local server.
Manage Databases
Create a database.
Click the “home” icon, click the “Databases” tab.
Enter the Database Name, select the collation, and click the “Create Button” button.
A form will be displayed that allows you to enter the table’s name and the number of fields the table will contain. Complete the form and click on the “Go” button.
Complete the form and click the “Save” button.
Modify Databases.
From the left column of the home page select the database you would like to modify by clicking on the database name.
The center panel will show all the tables in the database. From this form, you can branch-off to perform other actions to include creating a new table.
Delete or drop a database.
From the left column select the database you would like to drop by clicking on the database name.
Then click the “Operations” tab.
Under “Remove database” click “Drop the database (DROP)”
Manage Tables
Click the home icon, then click the “Databases” tab. You will see a form like the one above.
Click the Database you wish to manage. This will take you to the “Structures” tab. You will be on a form like the one below. This is where you manage your tables.
You can now:
Browse – This allows you to “Edit”, “Copy” or, “Delete” each record. You will see the columns along with their data. You can also export data from this screen.
Structure – From this screen, you can modify the structure of each field – Change, “Drop”, or you can perform other operations.
Search – This allows you to search your data.
Insert – This is a form that allows you to add a record to the selected table.
Empty – This feature will remove all the records in the table. Be careful with this option.
Drop – Allows for the entire table to be removed/destroyed. Be careful with this option.
Note you can also use the list of tables in the left panel to drill down from your database to a table, and the table’s fields.
About Collation
Collation defines how to sort or how to weigh items in relevance to other items. For more information read the MySql documentation on supported character sets and collations [https://dev.mysql.com/doc/refman/8.0/en/charset-charsets.html] Notice MySql recommends you test your selected collation to ensure you are getting the results you desire.
Import Data
From the top menu click on “Import”.
A form will appear. Click “Choose File”, which will open dialog page for selecting the file you want to import. To the right of “Choose File”, you will see the max file size that you can import. The value can be adjusted. Modifying this value is outside the scope of this article.
Select the “Character Set”.
Set or unset Partial Imports.
Set or unset Enable foreign key check.
Set the file format.
Set the SQL compatibility mode or leave it at its default of none.
Set or unset “Do not use AUTO_INCREMENT for zero values”.
Click the “Go” button.
Export Data
From the top menu click on “Export”.
Select the “Export method”:
Quick – display only the minimal options.
Custom – display all possible options.
Select the “Format” from the drop-down.
Click the “Go” button.
SQL Queries
SQL stands for Structured Query Language. This is another area you will want to become familiar with. SQL is your bread and butter when it comes to working with databases. I use the SQL box to build complex SQL statements.
There are two ways to get to the query interface.
Click the “home” icon, then click the “SQL” tab to get to the plain SQL interface:
From almost any page you can click the table under a database on the left column and then click the “SQL” tab. That will bring up an SQL interface that has a lot of features you will probably find useful. From here you can click any of the buttons that are directly below the query box. The cool part of this is it will create the type of query you want to create based on the table you selected. This is a great way from a beginner to learn SQL.
The buttons I want to point out are:
<Select *> – Will create a wild card select (a select pulls data).
<Select> – Will create a select listing all the fields in the table.
<Insert> – Will create an insert query. This query contains all the fields of the table (an insert creates a new record and populates it).
<Update> – Will create an update query. This query contains all the fields of the selected table and place holders for the data that is to be updated (an update query is used to update data).
<Delete> – Will create delete query ( a delete removes a record).
<Clear> – Will clear the text box.
<Format> – This will format the query so it can be used within a program.
phpMyAdmin Documentation
There is a lot to know. This article does not cover everything. This link will take you to the phpMyAdmin documentation where you can learn more.
Conclusion
There are a number of tools you can use to manage your MySql data, each has different features you might find useful.
The nice thing about phpMyAdmin is it is a web application, meaning it runs in a browser. That means you can access phpMyAdmin from any device that runs a modern browser.
phpMyAdmin is very feature-rich and is a great tool for programmers and system administrators.