LAMP on Linux 22.04
This post contains notes to install Apache2, MySQL and PHP on a Ubuntu Server 22.04. This is not a tutorial but a checklist.
Install the required softwares
- Install apache2
apt-get install apache2
service apache2 status
- Install mysql
apt-get install mysql-server
service mysql status
mysql_secure_installation
- If required, create an mysql user for the application
CREATE USER 'phpbb'@'localhost' IDENTIFIED BY 'www';
create database www;
GRANT ALL PRIVILEGES ON www.* TO 'phpbb'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
- Install PHP 8
apt-get install php8.1-fpm php8.1 libapache2-mod-php8.1 php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl php8.1-bcmath php-json php-mbstring php-xml
- Install various tools
apt-get install unzip
- Update the apache2-php configuration to support larger uploads
upload_max_filesize = 32M
post_max_size = 48M
memory_limit = 256M
max_execution_time = 120
max_input_vars = 300
max_input_time = 1000
- Disable the default website
a2dissite 000-default
- Install the new website in /var/www/html/newsite
chown -R www-data:www-data /var/www/html/newsite
find /var/www/html/newsite -type d -exec chmod 755 {} \;
find /var/www/html/newsite -type f -exec chmod 644 {} \;
- Create the apache2 password file
apt-get install apache2-utils
htpasswd -c /etc/apache2/.htpasswd exampleuser
- Create the apache2 new website configuration file by creating the file /etc/apache2/sites-available/newsite.conf. The certificate directives will be inserted by certbot (Let’s Encrypt)
<VirtualHost *:80>
ServerAdmin admin@newsite.com
ServerName www.newsite.com
ServerAlias www.newsite.com
DocumentRoot /var/www/html/newsite
<Directory /var/www/html/newsite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@newsite.com
ServerName www.newsite.com
ServerAlias www.newsite.com
SSLEngine on
DocumentRoot /var/www/html/newsite
<Directory /var/www/html/newsite>
Options -Indexes +FollowSymLinks
AuthType Basic
AuthName "Restricted Content: You are not welcome!"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/www.newsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.newsite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
- Enable SSL
a2enmod ssl
- Enable the new web site
ena2site newsite