You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
5.8 KiB
204 lines
5.8 KiB
# cms - Content Management System
|
|
|
|
Original Author: Matt Doyle <https://www.elated.com/cms-in-an-afternoon-php-mysql/>
|
|
|
|
Updates: Robert S.
|
|
```
|
|
Note: I use the hash sign # to note a comment, do not run it in the terminal.
|
|
Note: I use the dollar sign $ for the Linux prompt commands to run.
|
|
Note: I use the greater-than sign > for the MySQL prompt commands.
|
|
Note: The apt-get package mgr is used by debian Linux like Ubuntu.
|
|
Note: To stay as logged in as root you may do $ sudo -i
|
|
then type exit to quit out of sudo -i from root when done as root.
|
|
```
|
|
|
|
## Make web group
|
|
```
|
|
# You'll want a web group to be created.
|
|
$ sudo groupadd www-data
|
|
```
|
|
|
|
## Make a Regular user account, if only the root account exists currently.
|
|
```
|
|
# Log in as Root user here
|
|
# replace newuser with a name you desire like jellybeansara
|
|
$ sudo adduser newuser
|
|
$ sudo usermod -aG www-data newuser
|
|
$ sudo usermod -aG sudo newuser
|
|
```
|
|
|
|
## Git clone repo to pull it
|
|
```
|
|
$ sudo mkdir -p /var/www
|
|
$ sudo chgrp www-data /var/www
|
|
# If not Root user do next command, else if root replace $USER with newuser name like jellybeansara.
|
|
$ sudo chown $USER /var/www
|
|
$ sudo chmod 775 /var/www
|
|
$ sudo apt-get update && sudo apt-get install git
|
|
# AS a normal user NOT Root, we will sudo or doas for that from most of the time:
|
|
$ cd /var/www
|
|
$ git clone https://git.mysnippetsofcode.com/bobs/cms
|
|
$ cd cms
|
|
```
|
|
|
|
## SETUP MySQL as Root, run:
|
|
```
|
|
# Assign an empty password for MySQL root, it will be changed later...during mysql_secure_installation script.
|
|
# Install the server:
|
|
$ sudo apt-get install mysql-server
|
|
$ sudo systemctl start mysql
|
|
$ sudo systemctl enable mysql
|
|
|
|
# Lets make a sercure password for use with MySQL root account.
|
|
$ openssl rand -base64 18
|
|
|
|
# The following script will prompt you to perform various security-related actions. Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload the privilege tables.
|
|
$ sudo mysql_secure_installation
|
|
|
|
# Change this password SJ6G*WyaV7PvvEts@vxjm used below in a couple of places throughout this tutorial!
|
|
# Lets make a sercure password for use with MySQL zoombox user account.
|
|
$ openssl rand -base64 18
|
|
|
|
# Enter your password assigned during setup, create a new user for the app to use.
|
|
$ mysql -u root -p
|
|
> CREATE USER 'zoombox'@'localhost' IDENTIFIED BY 'SJ6G*WyaV7PvvEts@vxjm';
|
|
> GRANT ALL ON cms.* TO 'zoombox'@'localhost';
|
|
> create database cms;
|
|
> exit
|
|
```
|
|
## Import the tables.sql file:
|
|
```
|
|
$ pushd protected/src
|
|
$ pwd
|
|
# You should be in /var/www/cms/protected/src
|
|
# Do not use the root user for cms app!
|
|
$ mysql -u cms -p cms < tables.sql
|
|
enter this password when prompted: SJ6G*WyaV7PvvEts@vxjm
|
|
$ popd
|
|
```
|
|
|
|
You may want to edit the config.php file which is in the protected/src folder.
|
|
```
|
|
define( "BLOG_NAME", "Widgetz Newz" ); // Display Name for Titles
|
|
```
|
|
|
|
## Create the .env file in root of Project to configure your secrets!
|
|
```
|
|
$ pwd
|
|
# You should be in /var/www/cms
|
|
# DO NOT use the root user for cms app!
|
|
$ nano .env
|
|
DB_TYPE=mysql
|
|
DB_HOST=127.0.0.1
|
|
DB_NAME=cms
|
|
DB_USERNAME=zoombox
|
|
DB_PASSWORD=SJ6G*WyaV7PvvEts@vxjm
|
|
ADMIN_USERS=zug:SunSet@XQWET,zig:546Poker@xzyWhy
|
|
```
|
|
(for Nano editor) Press ctrl+x to Save and Exit. Y to save. Enter to the default filename...
|
|
|
|
Note: the admin username is: zug
|
|
|
|
Admin password is: SunSet@XQWET
|
|
|
|
## Install Composer
|
|
```
|
|
# Must be a regular user here to do composer install.
|
|
$ curl -sS https://getcomposer.org/installer | php
|
|
$ sudo mv composer.phar /usr/local/bin/composer
|
|
```
|
|
|
|
## Install Composer deps
|
|
```
|
|
# Must be a regular user here to do composer install.
|
|
$ cd protected
|
|
$ pwd
|
|
# You should be in /var/www/cms/protected
|
|
$ composer install
|
|
```
|
|
|
|
## Install web server apache2 or nginx
|
|
|
|
https://unit.nginx.org/ (looks neat)
|
|
|
|
Pick just one
|
|
|
|
```
|
|
# for Apache2
|
|
$ sudo apt-get install apache2
|
|
$ sudo apt-get install libapache2-mod-php8.3
|
|
# edit default site:
|
|
$ sudo nano /etc/apache2/sites-available/000-default.conf
|
|
<VirtualHost *:80>
|
|
ServerAdmin webmaster@localhost
|
|
# Replace example.com with your actual domain or IP address:
|
|
ServerName example.com
|
|
ServerAlias www.example.com
|
|
DocumentRoot /var/www/cms/public
|
|
|
|
<Directory /var/www/cms/public>
|
|
Options Indexes FollowSymLinks
|
|
AllowOverride All
|
|
Require all granted
|
|
</Directory>
|
|
|
|
ErrorLog ${APACHE_LOG_DIR}/error.log
|
|
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
|
</VirtualHost>
|
|
$ sudo a2ensite 000-default.conf
|
|
$ sudo a2enmod rewrite
|
|
# after php deps are installed come back and run this:
|
|
$ sudo a2enmod php8.3
|
|
# Install Certbot to get SSL certs for Apache2
|
|
$ sudo apt-get update
|
|
$ sudo apt-get install certbot
|
|
$ sudo certbot --apache
|
|
$ sudo systemctl restart apache2
|
|
|
|
---------------------------OR--------------------------------
|
|
|
|
# for nginx
|
|
$ sudo apt-get install nginx
|
|
$ sudo apt-get install php8.3-fpm
|
|
# Configure nginx for cms
|
|
$ sudo nano /etc/nginx/sites-available/cms
|
|
server {
|
|
listen 80;
|
|
# Replace your_domain.com with your actual domain or IP address:
|
|
server_name your_domain.com;
|
|
root /var/www/cms/public;
|
|
|
|
index index.php index.html;
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.php?$query_string;
|
|
}
|
|
|
|
location ~ \.php$ {
|
|
include snippets/fastcgi-php.conf;
|
|
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # Adjust the PHP version if necessary
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
include fastcgi_params;
|
|
}
|
|
|
|
location ~ /\.ht {
|
|
deny all;
|
|
}
|
|
}
|
|
|
|
$ sudo ln -s /etc/nginx/sites-available/cms /etc/nginx/sites-enabled/
|
|
$ sudo nginx -t
|
|
# if test is ok, then run:
|
|
$ sudo systemctl reload nginx
|
|
# Install Certbot to get SSL certs for nginx
|
|
$ sudo apt-get update
|
|
$ sudo apt-get install certbot
|
|
$ sudo certbot --nginx
|
|
$ sudo systemctl reload nginx
|
|
```
|
|
|
|
## PHP deps
|
|
```
|
|
PHP gd and mysql must be installed:
|
|
$ sudo apt-get install php8.3 php8.3-gd php8.3-mysql
|
|
``` |