How to Install PHP 8 on Ubuntu
Making Connection With Server
Get the DNS name of instance.
Putty Suite of softwares (Puttygen and Putty are important) create putty private key(.ppk) from from Amazon provided .pem key with the help of Puttygen.
Also use filezilla for SFTP connection also on port 22
click on edit->settings->SFTP->Add key file-> press ok
click of file->site manager->new site->select protocol as SFTP(SSH file transfer protocol)->In Host past your Public IPv4 DNS->Port 22->Logon type Normal->user ubuntu->password empty->click on connect
How to Install PHP with apache module on Ubuntu 20.04
sudo apt install php libapache2-mod-php -y
sudo systemctl restart apache2
sudo systemctl status apache2
// keep the service running even if we reboot the machine
sudo systemctl enable apache2
Installing php extensions
sudo apt install php-mysql php-gd php-cli php-common php-curl php-xml php-mbstring php-opcache php-json -y
https://linuxize.com/post/how-to-install-apache-on-ubuntu-18-04/
Point Domain to EC2 Instance
- Create an Elastic IP Address Assosiate the elastic ip to running instance of ec2.
- Create a new hosted zone Route 53
- Create an A Record and Enter the ‘Elastic Ip Address’
- Create another Alias A Record.
- Add Names Servers in Godaddy Manage DNS. DNS name of server will be changed after associating the elastic ip to it.
Also add records of email servers in Route 53 Public DNS.
for example adding zoho mail MX records, SPF, and others. Detail instruction are in another article. Route 53 services can also be used to completly transfer your domain from godaddy.
Install MariaDB on Ubuntu 20.04
sudo apt install mariadb-server -y sudo systemctl status mariadb
after installation type
sudo mysql_secure_installation
and press enter because we have not set any root password.
then set new root password, Remove anonymous users, Disallow root login remotely, Remove test database and access to it and also Reload privilege tables now.
sudo systemctl restart mariadb
sudo systemctl enable mariadb
Setup Database for wordpress website
sudo mysql -u root -p
type the root password that we set up earlier.
now for creating database type the following
CREATE DATABASE <database name>;
for example
CREATE DATABASE khalidwaleed;
create a new username and password for our newely created database. In the this example the user name is “ahmad” and password is “kakarr”.
CREATE USER "ahmad"@"%" identified by "kakarr";
now assign all privileges on database to newely create username.
GRANT ALL PRIVILEGES on khalidwaleed.* to "ahmad"@"%";
Create a directory which will hold our WordPress files:
sudo mkdir -p /var/www/khalidwaleed.com
Install SSL Certificate on Ubuntu Server 20
sudo apt update
sudo apt install certbot -y
sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
sudo mkdir -p /var/lib/letsencrypt/.well-known
sudo chgrp www-data /var/lib/letsencrypt
sudo chmod g+s /var/lib/letsencrypt
change the ownership of permission with the following command
sudo chmod -R 777 /etc/apache2/conf-available/
Create file here /etc/apache2/conf-available/
with the name of letsencrypt.conf
content of letsencrypt.conf file are
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
AllowOverride None
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
crete file here /etc/apache2/conf-available/ with the name of ssl-params.conf content of ssl-params.conf file are
ssl-params.conf
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder off
SSLSessionTickets off
SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"
Header always set Strict-Transport-Security "max-age=63072000"
Before enabling the configuration files, make sure both mod_ssl and mod_headers are enabled by issuing:
sudo a2enmod ssl
sudo a2enmod headers
Next, enable the SSL configuration files by running the following commands:
sudo a2enconf letsencrypt
sudo a2enconf ssl-params
Enable the HTTP/2 module, which will make your sites faster and more robust:
sudo a2enmod http2
sudo systemctl reload apache2
Use the following command to create ssl certificates for as many sites you want.
sudo certbot certonly --agree-tos --email developer@khalidwaleed.com --webroot -w /var/lib/letsencrypt/ -d khalidwaleed.com -d www.khalidwaleed.com
sudo certbot certonly --agree-tos --email developer@khalidwaleed.com --webroot -w /var/lib/letsencrypt/ -d ec2-54-90-43-60.compute-1.amazonaws.com -d www.ec2-54-90-43-60.compute-1.amazonaws.com
If the SSL certificate is successfully obtained, certbot will print the following message:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Your cert will expire on 2020-10-06. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Now that you have the certificate files, edit your domain virtual host configuration as follows:
config for wordpress apache and ssl
best is if you copy the below example config to other file and do your changes there.
<VirtualHost *:80>
ServerName khalidwaleed.com
ServerAlias www.khalidwaleed.com
Redirect permanent / https://khalidwaleed.com/
</VirtualHost>
<VirtualHost *:443>
ServerName khalidwaleed.com
ServerAlias www.khalidwaleed.com
Protocols h2 http/1.1
<If "%{HTTP_HOST} == 'www.khalidwaleed.com'">
Redirect permanent / https://khalidwaleed.com/
</If>
DirectoryIndex index.html index.php
DocumentRoot /var/www/khalidwaleed.com
# DocumentRoot /var/www/khalidwaleed.com/public_html
ErrorLog ${APACHE_LOG_DIR}/khalidwaleed.com-error.log
CustomLog ${APACHE_LOG_DIR}/khalidwaleed.com-access.log combined
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/khalidwaleed.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/khalidwaleed.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/khalidwaleed.com/chain.pem
# Other Apache Configuration
<Directory /var/www/khalidwaleed.com>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
sudo systemctl reload apache2
To Test SSL
https://www.ssllabs.com/ssltest/
Permission Issues Solution
sudo chown -R -v ec2-user /var/www/ or sudo chown -R -v ubuntu /var/www/
for safety you can chmod 775 like this:
sudo chmod 775 /YOUR_DIRECTORY
sudo chmod -R 777 /etc/php/ sudo chmod -R 777 /var/www/khalidwaleed.com
Download Wordpress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xf latest.tar.gz
intall unzip if not installed with command
sudo apt install unzip
unzip by th following method if its .zip file.
sudo unzip latest.zip
now move all the content which was in wordpress folder to previously created folder named like domain name.
sudo mv /tmp/wordpress/* /var/www/khalidwaleed.com/
now ls -al
you will see that all the file have root ownership, but appache server is run by www-data:www-data
user. so we have to change the owenership to www-data:www-data
user, for that run the following command.
sudo chown -R www-data: /var/www/khalidwaleed.com
cd into
/etc/apache2/sites-available
upload the config file of website.
sudo chmod -R 777 /etc/apache2/sites-available
sudo a2ensite khalidwaleed.com
sudo systemctl restart apache2
First Things to Do after installing wordpress
increase php limit
This Method worked on ubuntu 20 on aws ec2 instance
All the possible solution i listed in another article.
Installing Wordpress
Document root of the apache webserver is /var/www/html/
sudo cp -R wordpress/* /var/www/html/
Now change directory cd /var/www/html/
sudo chown www-data:www-data -R /var/www/html/
sudo chown www-data:www-data /var/www/khalidwaleed.com/php.ini
go to the /var/www/html. then remove the index.html with the following command
sudo rm -rf index.html
now open the public ip address
the wordpress installation wizard will start. to setup database for this wordpress installation type