Ubuntu 22.04 LTS (debian) Apache2 http2 + PHP 8.2

[Updated 2023-07-21]
Commands to launch and to set up my preferred environment in ubuntu.

sudo su
add-apt-repository ppa:ondrej/php --yes
apt update && apt upgrade -y && apt autoremove -y

# Install all php related components.
apt install -y php8.2-fpm php8.2 libapache2-mod-php8.2 php8.2-common  php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl php8.2-bcmath unzip php8.2-dom apache2 composer libapache2-mod-fcgid certbot python3-certbot-apache 

apt autoremove -y

Optionally to setup ZSH and the Z plugin

$> sudo apt install -y zsh #optional for ZSH
$> zsh
#pick option #2, to setup.

# install Z plugin
$> curl https://raw.githubusercontent.com/agkozak/zsh-z/master/zsh-z.plugin.zsh > zsh-z.plugin.zsh
$> echo source ~/zsh-z.plugin.zsh >> .zshrc
$> source ~/zsh-z.plugin.zsh

#set current user to use zsh as default
$> sudo chsh -s $(which zsh) $(whoami)

Setup apache.

### SETUP YOUR FQD - fully qualified domain
$> DOMAIN_NAME=example.com

Paste below carefully…

sudo mkdir -p /var/www/$DOMAIN_NAME/public
cd /var/www/$DOMAIN_NAME
sudo chown -R $(whoami):www-data .


sudo tee /etc/apache2/sites-available/$DOMAIN_NAME.conf << END
<VirtualHost *:80>
    ServerName $DOMAIN_NAME
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/$DOMAIN_NAME/public
    ErrorLog \${APACHE_LOG_DIR}/error.log
    CustomLog \${APACHE_LOG_DIR}/access.log combined

    Protocols h2 http/1.1

	<Directory /var/www/$DOMAIN_NAME/public>
		AllowOverride All
		Order Allow,Deny
		Allow from All
		DirectoryIndex index.php
	</Directory>
</VirtualHost>
END

sudo a2dissite 000-default
sudo a2ensite $DOMAIN_NAME.conf 
sudo a2dismod php8 #may fail... fine.
sudo a2dismod php8.0 #may fail... fine.
sudo a2dismod php8.1 #may fail... fine.
sudo a2dismod php8.2 #may fail... fine.
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo a2enmod http2
sudo a2enmod proxy
sudo a2enmod proxy_fcgi
sudo a2enconf php8.2-fpm
sudo a2enmod rewrite
sudo systemctl restart apache2

Probably want to ensure that your DNS settings are working. Run certbot, or put in your SSL certs manually.

other tidbits of script

###
### WARNING, this command can be dangerous.
### REVIEW initial crontab -l first, and only if you know for suer
### run the command below, and will populate.
### Handy cron stuff... INITIAL install only... REVIEW
###
echo '@daily apt update
@daily apt autoremove -y' | sudo crontab




###
### MySQL support for php
###
apt install php8.2-mysql mysql-server php8.2-pdo


###
### Postgresl SQL support for php
###

apt install php8.2-pgsql
sudo -i -u postgres
createuser --interactive


### Postgresql itself
apt install postgresql postgresql-contrib
sudo systemctl start postgresql.service


### Restart apache:
$> sudo systemctl reload apache2

Troubleshooting:

Ensure the firewall is open to ports 80/443

apache2.conf:

SetHandler application/x-httpd-php


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *