This is a toy project intended as a learning experience into creating a LAMP stack (Linux, Apache, MySQL, PHP) web application from scratch. The application gives users the ability to curate a gallery of rock photos.
Follow these instructions to install the required software dependencies for developing and running the application on a local machine.
It is recommended to install dependencies through a package manager such as apt (Debian based Linux), Homebrew (Mac OS) or Chocolatey (Windows) since this would automatically take care of downloading and installing the whole ancestry of dependencies necessary. Homebrew and Chocolatey are probably not installed on systems by default, follow the instructions in the links to install the appropriate package manager.
NOTE: On windows it is possible to install Apache, MySQL and PHP all in one go with:
choco install wamp-server
Git is version control software used for application development.
- Official documentation.
- Atlassian's beginner friendly overview.
sudo apt install git
brew install git
choco install git
To check if git was installed successfully, the following should display a version message:
git --version
Apache HTTP Web Server, otherwise known as Httpd, is the name of the open source web server developed by the Apache Software Foundation.
- Official documentation.
sudo apt install apache2
Recent versions of Mac OS X come with a pre-installed version of Apache 2.4, although it is also possible to uninstall and re-install Apache using Homebrew if desired (for consistency):
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd
choco install apache-httpd
To check if Apache was installed successfully, start the server:
sudo apachectl start
Then, in a browser, go to http://localhost:80. Apache should serve a default information page.
MySQL is a database server used for storing information relevant to the application.
- Official documentation.
- Beginner friendly tutorials.
sudo apt install mysql-server
brew install mysql
choco install mysql
To check if MySQL was installed successfully, the following should display a version message:
mysql --version
PHP is an interpreted programming language. To generate web content the server would use the interpreter and pass to it a file to execute (ie. index.php) the PHP interpreter would run the code and produce the output html that gets sent back to the client. To use PHP with Apache we need the recent version of the PHP interpreter, and the module to serve as the glue between PHP and Apache. We will also use an extension that will expose functions for connecting to and making queries against the MySQL database.
- Official documentation
sudo apt install php libapache2-mod-php php-mysql
Should already be installed:
php --version
Otherwise:
brew install php
choco install php
To check if the PHP interpreter was installed successfully, the following should display a version message:
php --version
To check that Apache is using the PHP module, clone and build the application and make sure content is displayed properly in the browser.
The application at present does not use the MySQL server. To test that PHP is able to use the mysqli
extension to connect and query MySQL:
- Following guides on mysqltutorial.org:
- Connect to the MySQL server through the command line as the root user.
- Create a database called
test_db
- Create a user
test_user
with passwordtest_pass
- Grant
test_user
all permissions ontest_db
database
- Create a file
test-mysql.php
with the following contents:<?php $mysqli = new mysqli('localhost', 'test_user', 'test_pass', 'test_db'); if(!$mysqli->connect_errno){ echo "[SUCCESS]"; } else { echo "[ERROR] - " . $mysqli->connect_errno . " - " . $mysqli->connect_error; } ?>
- execute the script:
php test-mysql.php
Cloning will bring all the files from github onto your local computer inside a 'rocks' folder within the folder where
the git clone
command was issued. It is recommended that you create a new folder (ie. workspace) into which you would
clone any repositories. In order to clone the repository you need to be added as a contributor (contact me).
Using https will require you to authenticate (with your account password) whenever you connect to your account through the command line (ie. to clone a repository).
git clone https://github.com/VasilyF/rocks.git
Using ssh will allow you to automatically authenticate yourself whenever connecting to github from the command line (ie. to clone a repository), you will not have to enter a password each time.
Follow these steps to generate an SSH key and add it to your account.
git clone https://github.com/VasilyF/rocks.git
The application can be built on UNIX based systems (Linux/Mac OS) using the general-build.sh script.
Windows: currently no build script exists, need to build off apache2-general.conf
Prior to running the script, some local environment variables need to be set up. Since Apache is installed differently on each operating system, in order to start the server it is necessary to specify:
- The absolute path to the apache2 (could also be called httpd) binary executable, this is the server program itself
the following are likely places where it would be installed but check and/or do some googling to find it.
- /usr/sbin/apache2
- The directory under which all the Apache modules (shared libraries) are stored.
the following are likely places where it would be installed:
- /usr/lib/apache2/modules
- /usr/libexec/apache2/modules
Create a new file called (exactly) envvars-local.sh
in the directory rocks/apache/general/
and paste the following
contents into the file:
export APACHE_BIN=</usr/sbin/apache2>
export APACHE_MODULES_DIR=</usr/libexec/apache2/modules>
Replace the contents inside the angle brackets (excluding brackets) with the actual paths of (1) and (2) respectively.
Note: when specifying the path to the modules directory (2) the trailing '/' should be omitted.
The build script build-general.sh is meant to be executed from the rocks/
directory (root directory of project).
It places all the server related content (log files, config files, documents to serve) into /srv/apache2/rocks
.
It could be used as follows to start, stop and restart the server:
sudo ./build-general.sh start
sudo ./build-general.sh stop
This is useful to incorporate changes made in the code into the content being served by Apache.
sudo ./build-general.sh restart
Further resources are available in the github wiki.
This project is licensed under the MIT License - see the LICENSE.md file for details.