The post How to Switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10 with Nginx appeared first on PixelsPress.
]]>WordPress 5.* and up comes with PHP 7.3-FPM support. If you’re running older versions of PHP-FPM, you can use the following steps to switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10 with Nginx HTTP server running WordPress.
Some themes and plugins are still not compatible with PHP 7.3-FPM so before to upgrade please make sure that your theme & plugins are compatible with PHP 7.3FPM.
Run the following commands before to install PHP 7.3-FPM packages
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Now install PHP 7.3-FPM on Ubuntu & most commonly used PHP extensions using the following command:
sudo apt install php7.3-fpm php7.3-common php7.3-zip php7.3-curl php7.3-xml php7.3-xmlrpc php7.3-json php7.3-mysql php7.3-pdo php7.3-gd php7.3-imagick php7.3-ldap php7.3-imap php7.3-mbstring php7.3-intl php7.3-cli php7.3-recode php7.3-tidy php7.3-bcmath php7.3-opcache
You can use php -v
command to check the PHP version installed on your server and output will be
PHP 7.3.11-1+ubuntu19.10.1+deb.sury.org+6 (cli) (built: Oct 28 2019 21:34:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.11-1+ubuntu19.10.1+deb.sury.org+6, Copyright (c) 1999-2018, by Zend Technologies
You can also confirm installed version of any PHP extension using apt policy
command i.e. apt policy php7.3-cli
and output will be
php7.3-cli:
Installed: 7.3.11-1+ubuntu19.10.1+deb.sury.org+6
Candidate: 7.3.11-1+ubuntu19.10.1+deb.sury.org+6
Version table:
*** 7.3.11-1+ubuntu19.10.1+deb.sury.org+6 500
500 http://ppa.launchpad.net/ondrej/php/ubuntu eoan/main amd64 Packages
100 /var/lib/dpkg/status
7.3.11-0ubuntu0.19.10.1 500
500 http://archive.ubuntu.com/ubuntu eoan-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu eoan-security/main amd64 Packages
7.3.8-1 500
500 http://archive.ubuntu.com/ubuntu eoan/main amd64 Packages
Now, PHP 7.3-FPM has been installed on your Ubuntu. The default Nginx PHP-FPM configuration file is at /etc/php/7.3/fpm/php.ini
and if we want to modify the default PHP configuration, open file for Nginx using the following command:
sudo nano /etc/php/7.3/fpm/php.ini
Make the changes on the following below lines in the file and save. The value below is great settings to apply in your environments.
max_execution_time = 180
max_input_time = 120
max_input_vars = 5000
memory_limit = 256M
cgi.fix_pathinfo = 0
file_uploads = On
upload_max_filesize = 100M
allow_url_fopen = On
date.timezone = Asia/Karachi
After making the change above, save the file and close out.
After installing PHP and related modules, all you have to do is restart Nginx to reload PHP configurations.
To restart Nginx and PHP-FPM, run the commands below
sudo systemctl restart nginx.service
sudo systemctl restart php7.3-fpm.service
Now you are having PHP-FPM 7.3 Installed and configured.
Open the Nginx site configuration and configure the PHP block to use PHP 7.3-FPM
sudo nano /etc/nginx/sites-available/yourprojectname
Then modify the PHP block session from fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
i.e.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
After that, restart Nginx HTTP server to use PHP 7.3-FPM.
sudo systemctl restart nginx.service
Finally, run the following command to remove all PHP 7.2 packages.
sudo apt-get purge `dpkg -l | grep php7.2| awk '{print $2}' |tr "\n" " "`
Once you will run the above command, It will prompt you to accept the changes to your system. Type ‘Y’ to continue; when you’re done, PHP 7.3-FPM should be enabled and PHP 7.2-FPM completely removed from Ubuntu.
The post How to Switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10 with Nginx appeared first on PixelsPress.
]]>The post How to Install WordPress on Ubuntu with Nginx, MariaDB and PHP-FPM appeared first on PixelsPress.
]]>Note: For demonstration purposes, we’re going to set up one domain on our Nginx server. The domain name we’ll use in this guide is yourdomain.com.
To get started with the installation of WordPress, follow the steps below:
To logon to MariaDB database server, run the following commands:
sudo mysql -u root -p
Then create a database called yourname_live
CREATE DATABASE yourname_live;
Now create a database user called yourname_live_user with a new password
CREATE USER 'yourname_live_user'@'localhost' IDENTIFIED BY 'your_password_here';
And grant the user full access to the database.
GRANT ALL ON yourname_live.* TO 'yourname_live_user'@'localhost' IDENTIFIED BY 'your_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
FLUSH PRIVILEGES;
EXIT;
To get WordPress latest release, go to its official download page and get it from there. The following link is from where we can find latest WordPress archive versions.
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
sudo mv wordpress /var/www/html/yourdomain.com
Now run the commands below to set the correct permissions for WordPress root directory and give Nginx control
sudo chown -R www-data:www-data /var/www/html/yourdomain.com/
sudo chmod -R 755 /var/www/html/yourdomain.com/
Finally, configure Nginx site configuration file for WordPress. This file will control how users access WordPress content. Run the following commands to create a new configuration file called yourdomain.com.conf
sudo nano /etc/nginx/sites-available/yourdomain.com.conf
Copy and paste the following content into ‘yourdomain.com.conf’ file and save it. Replace the highlighted line with your own domain name and directory root location.
#yourdomain.com configuration
server {
charset utf-8;
# set max upload size
client_max_body_size 2G;
fastcgi_buffers 64 4K;
listen 80; # Listen for ipv4
listen [::]:80; # Listen for ipv6
server_name yourdomain.com www.yourdomain.com;
root /var/www/html/yourdomain.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Save the file and exit.
After configuring the Virtual Host above, enable it by running the commands below
sudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Then open your browser and browse to the server domain name. You should see WordPress setup wizard to complete. Please follow the wizard carefully.
http://yourdomain.com
Follow the on-screen instructions. i.e. select the installation language and click Continue.
You will need to know the following
Before getting started, we need some information on the database. You will need to know the following items before proceeding.
WordPress will going to use this information to create a wp-config.php
file.
Next, you should enter your database connection details and if you’re not sure about these, contact your host.
After that, click Run the installation to complete the WordPress setup.
Next, fill in the WordPress site information and then click Install WordPress
You’re done. WordPress is installed now and ready to use.
The post How to Install WordPress on Ubuntu with Nginx, MariaDB and PHP-FPM appeared first on PixelsPress.
]]>The post How to Install PHP-FPM with Nginx on Ubuntu appeared first on PixelsPress.
]]>PHP can be installed using Ondřej Surý PPA, so install the software-properties-common package, add the ondrej PPA and update your sources using the following commands:
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
Install PHP 7.3-FPM on Ubuntu using the following command:
sudo apt install php7.3-fpm
or
sudo apt install php7.4-fpm
You can use php -v
the command to check the PHP version installed on your server and output will be
PHP 7.3.11-1+ubuntu19.10.1+deb.sury.org+6 (cli) (built: Oct 28 2019 21:34:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.11-1+ubuntu19.10.1+deb.sury.org+6, Copyright (c) 1999-2018, by Zend Technologies
In case if you have installed PHP 7.4-FPM, following will be output:
PHP 7.4.28 (cli) (built: Feb 17 2022 16:06:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
Install the most commonly used PHP extensions using the following command for PHP 7.3:
sudo apt install php7.3-common php7.3-zip php7.3-curl php7.3-xml php7.3-xmlrpc php7.3-json php7.3-mysql php7.3-pdo php7.3-gd php7.3-imagick php7.3-ldap php7.3-imap php7.3-mbstring php7.3-intl php7.3-cli php7.3-tidy php7.3-bcmath php7.3-opcache
or for PHP 7.4, run the following one.
sudo apt install php7.4-common php7.4-zip php7.4-curl php7.4-xml php7.4-xmlrpc php7.4-json php7.4-mysql php7.4-pdo php7.4-gd php7.4-imagick php7.4-ldap php7.4-imap php7.4-mbstring php7.4-intl php7.4-cli php7.4-tidy php7.4-bcmath php7.4-opcache
You can confirm the installed version of any PHP extension using apt policy
command i.e. apt policy php7.3-cli
and output will be
php7.3-cli:
Installed: 7.3.11-1+ubuntu19.10.1+deb.sury.org+6
Candidate: 7.3.11-1+ubuntu19.10.1+deb.sury.org+6
Version table:
*** 7.3.11-1+ubuntu19.10.1+deb.sury.org+6 500
500 http://ppa.launchpad.net/ondrej/php/ubuntu eoan/main amd64 Packages
100 /var/lib/dpkg/status
7.3.11-0ubuntu0.19.10.1 500
500 http://archive.ubuntu.com/ubuntu eoan-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu eoan-security/main amd64 Packages
7.3.8-1 500
500 http://archive.ubuntu.com/ubuntu eoan/main amd64 Packages
Now, PHP 7.3-FPM has been installed on your Ubuntu server.
The default PHP configuration file is at /etc/php/7.3/fpm/php.ini
or /etc/php/7.4/fpm/php.ini
and if we want to modify the default PHP configuration, open file by using the following command:
sudo nano /etc/php/7.3/fpm/php.ini
or
sudo nano /etc/php/7.4/fpm/php.ini
Make the changes on the following below lines in opened file and save. Below are recommended values being great settings to apply in your environments.
max_execution_time = 180
max_input_time = 360
max_input_vars = 5000
memory_limit = 256M
cgi.fix_pathinfo = 0
file_uploads = On
post_max_size = 192M
upload_max_filesize = 96M
allow_url_fopen = On
After making the change above, save the file and close out.
After installing PHP and related modules, all you have to do is restart PHP-FPM and Nginx to reload PHP configurations.
To restart Nginx and PHP-FPM, run the commands below
sudo php-fpm7.3 -t
sudo systemctl restart php7.3-fpm
sudo systemctl restart nginx
or
sudo php-fpm7.4 -t
sudo systemctl restart php7.4-fpm
sudo systemctl restart nginx
Now you have learned how to install and configure PHP-FPM with Nginx on your Ubuntu server.
If you have a question or facing any problems, feel free to leave a comment.
The post How to Install PHP-FPM with Nginx on Ubuntu appeared first on PixelsPress.
]]>The post How to Install Nginx on Ubuntu appeared first on PixelsPress.
]]>To get started with the installation of Nginx, follow the steps below:
Before to install server, run the following commands first to update Ubuntu:
sudo apt update
sudo apt upgrade
Next, install Nginx web server with the following command:
sudo apt install nginx
This is it, Nginx is installed and it starts automatically. You can check the Nginx service status by using the following command:
sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-11-08 13:15:24 UTC; 7s ago
Docs: man:nginx(8)
Main PID: 23018 (nginx)
Tasks: 2 (limit: 2287)
Memory: 5.7M
CGroup: /system.slice/nginx.service
├─23018 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─23019 nginx: worker process
Nov 08 13:15:24 yourdomainname.com systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 08 13:15:24 yourdomainname.com systemd[1]: Started A high performance web server and a reverse proxy server.
The other following commands used to stop, start and enable Nginx service.
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
Note: Ubuntu 22.04 uses the UFW firewall by default, which stands for “Uncomplicated Firewall.” When the firewall is enabled, it will block all incoming connections. To allow incoming connections on certain ports, you have to configure the UFW firewall.
To open ports for a Nginx web server, you have to execute the following command:
sudo ufw allow in "Nginx Full"
Now to check your current firewall configuration settings, please run the following command:
sudo ufw status verbose
and the output will be:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22 ALLOW IN Anywhere
80,443/tcp (Nginx Full) ALLOW IN Anywhere
22 (v6) ALLOW IN Anywhere (v6)
80,443/tcp (Nginx Full (v6)) ALLOW IN Anywhere (v6)
To verify that Nginx working, open your browser, write your domain name or server IP address i.e. http://YOUR_IP_OR_DOMAIN
and you will see the following default Ubuntu Nginx welcome page.
You have learned how to install Nginx on Ubuntu server. You can repeat the steps we outlined above and install it on additional new Ubuntu servers.
If you are facing any problems, feel free to leave a comment.
The post How to Install Nginx on Ubuntu appeared first on PixelsPress.
]]>The post How to Install WordPress 5.2.3 on Ubuntu with Apache2, MariaDB and PHP 7.2 appeared first on PixelsPress.
]]>To get started with the installation of WordPress, follow the steps below:
To logon to MariaDB database server, run the following commands:
sudo mysql -u root -p
Then create a database called yourname_live
CREATE DATABASE yourname_live;
Now create a database user called yourname_live_user with a new password
CREATE USER 'yourname_live_user'@'localhost' IDENTIFIED BY 'your_password_here';
And grant the user full access to the database.
GRANT ALL ON yourname_live.* TO 'yourname_live_user'@'localhost' IDENTIFIED BY 'your_password_here' WITH GRANT OPTION;
Finally, save your changes and exit.
FLUSH PRIVILEGES; EXIT;
To get WordPress latest release, go to its official download page and get it from there. The following link is from where we can find latest WordPress archive versions.
cd /tmp wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz sudo mv wordpress /var/www/html/yourprojectname
Now run the commands below to set the correct permissions for WordPress root directory and give Apache2 control
sudo chown -R www-data:www-data /var/www/html/yourprojectname/ sudo chmod -R 755 /var/www/html/yourprojectname/
Finally, configure Apahce2 site configuration file for WordPress. This file will control how users access WordPress content. Run the following commands to create a new configuration file called yourprojectname.conf
sudo nano /etc/apache2/sites-available/yourprojectname
Copy and paste the following content into ‘yourprojectname.conf’ file and save it. Replace the highlighted line with your own domain name and directory root location.
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/yourprojectname ServerName example.com ServerAlias www.example.com <Directory /var/www/html/yourprojectname/> Options FollowSymlinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/yourprojectname/> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php [PT,L] </Directory> </VirtualHost>
Save the file and exit.
After configuring the Virtual Host above, enable it by running the following commands
sudo a2ensite yourprojectname sudo a2enmod rewrite sudo systemctl restart apache2.service
Now open your browser and browse to the server domain name. You should see WordPress setup wizard to complete. Please follow the wizard carefully.
http://your_domain_name.com
Follow the on-screen instructions. i.e. select the installation language and click Continue.
You will need to know the following
Before getting started, we need some information on the database. You will need to know the following items before proceeding.
WordPress will going to use this information to create a wp-config.php
file.
Next, you should enter your database connection details and if you’re not sure about these, contact your host.
After that, click Run the installation to complete the WordPress setup.
Next, fill in the WordPress site information and then click Install WordPress
You’re done. WordPress is installed now and ready to use.
The post How to Install WordPress 5.2.3 on Ubuntu with Apache2, MariaDB and PHP 7.2 appeared first on PixelsPress.
]]>The post How to Install PHP 7.2 on Ubuntu 16.04 / 18.04 / 18.10 appeared first on PixelsPress.
]]>PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It is one of the most popular languages and freely available for redistribution and modifications. It can be run on almost any web server ( e.g. Nginx, Apache) and every OS platform (Linux, Mac OS, Windows).
To get started with the installation of PHP, follow the steps below:
PHP 7.2 can be installed using Ondřej Surý PPA, so install the software-properties-common package with the following command:
sudo apt-get install software-properties-common
Now add the ondrej PPA and update your sources using the following commands:
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
Install PHP 7.2 on Ubuntu & most commonly used PHP extensions using the following command:
sudo apt-get install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-curl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-xml php7.2-intl php7.2-ldap php7.2-imagick php7.2-json php7.2-cli
You can use the following command to check the PHP version installed on your server:
php -v
You should receive the following output:
PHP 7.2.17-1+ubuntu18.10.1+deb.sury.org+3 (cli) (built: Apr 10 2019 10:51:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.17-1+ubuntu18.10.1+deb.sury.org+3, Copyright (c) 1999-2018, by Zend Technologies
Now, PHP 7.2 has been installed on your Ubuntu server, and if we want to modify the default PHP configuration, open file for Apache2 using the following command:
sudo nano /etc/php/7.2/apache2/php.ini
Make the changes on the following below lines in the file and save. The value below is great settings to apply in your environments.
max_execution_time = 180
max_input_time = 360
max_input_vars = 5000
memory_limit = 256M
file_uploads = On
upload_max_filesize = 100M
allow_url_fopen = On
date.timezone = Asia/Karachi
After making the change above, save the file and close out.
After installing PHP and related modules, all you have to do is restart Apache2 to reload PHP configurations.
To restart Apache2, run the commands below
sudo systemctl restart apache2.service
To test PHP 7.2 settings with Apache2, create a phpinfo.php file in Apache2 root directory by running the following command:
sudo nano /var/www/html/phpinfo.php
Then type the content below and save the file.
<?php phpinfo(); ?>
Save the file and browse to your server hostname followed by /phpinfo.php
. You should see PHP default test page.
The post How to Install PHP 7.2 on Ubuntu 16.04 / 18.04 / 18.10 appeared first on PixelsPress.
]]>The post How to Install MariaDB on Ubuntu appeared first on PixelsPress.
]]>To get started with the installation of MariaDB, follow the steps below:
To install MariaDB server, run the following commands:
sudo apt update
sudo apt install mariadb-server
After installing MariaDB, you can check the MariaDB status by using the following command:
sudo systemctl status mariadb
Output
mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-04-19 19:11:25 UTC; 1 day 13h ago
Main PID: 638 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 28 (limit: 502)
Memory: 80.3M
CGroup: /system.slice/mariadb.service
└─638 /usr/sbin/mysqld
You can check the MariaDB version with the following command:
mariadb -V
You can stop, start and enable the MariaDB when Ubuntu is rebooted with the following commands:
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
Now use mysql_secure_installation to secure the installation of MariaDB server i.e.
sudo mysql_secure_installation
The script will prompt you to determine which actions to perform by answering the following questions.
In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!
Now that MariaDB is installed, to verify whether the database server was successfully installed, run the following commands
sudo mysql -u root -p
type the root password when prompted…
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 190
Server version: 10.1.29-MariaDB-6ubuntu2 Ubuntu 18.10
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
If you see a similar message as shown above, then the MariaDB was successfully installed.
Now you have learned how to Install MariaDB server on Ubuntu and you also know how to connect to the MariaDB server from the command line.
If you have questions feel free to leave a comment below.
The post How to Install MariaDB on Ubuntu appeared first on PixelsPress.
]]>The post How To Set Up Apache2 Virtual Hosts on Ubuntu appeared first on PixelsPress.
]]>Apache2 Virtual Hosts can run more than one website on a single server machine. With Virtual Hosts, you can specify the multiple site document roots, define a separate security policy for each site, use different SSL certificates and much more.
To get started with the set up of Apache2 Virtual Hosts, follow the steps below:
The first step that we are going to take is to create a directory structure that will hold the website data and will be serving to visitors. The document root
is the directory where the website data for a domain name is stored. You can define the document root
to anywhere you want but in this article, we will use the default document root
which is /var/www
and our directory structure will be
/var/www/
├── yourdomain1.com
│ └── public_html
├── yourdomain2.com
│ └── public_html
├── yourdomain3.com
│ └── public_html
We will create a directory here for the virtual hosts we plan on making. Within each of these directories, we will create a public_html
folder that will hold our actual website data. This gives us some flexibility in our hosting.
You can create directories by using the following command:
sudo mkdir -p /var/www/yourdomain1.com/public_html
sudo mkdir -p /var/www/yourdomain2.com/public_html
sudo mkdir -p /var/www/yourdomain3.com/public_html
The -p
flag tells mkdir
to create any necessary parent directories along the way:
Since the commands above are executed as a sudo user, the newly created files and directories are owned by the root user.
To avoid any permission issues we can reassign the ownership of the domain document root
directory to the apache user (www-data
):
sudo chown -R www-data:www-data /var/www/yourdomain1.com/public_html
sudo chmod -R 755 /var/www/yourdomain1.com/public_html
On Ubuntu, Apache2 Virtual Hosts configuration files are located in /etc/apache2/sites-available
directory. They can be enabled by creating symbolic links to the /etc/apache2/sites-enabled
directory, which Apache2 reads during the startup.
Open your editor of choice and create the basic Virtual Host configuration file in /etc/apache2/sites-available/yourdomain1.com.conf
with the following code.
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /var/www/yourdomain1.com/public_html>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerName yourdomain1.com
ServerAlias www.yourdomain1.com
ServerAdmin webmaster@yourdomain1.com
DocumentRoot /var/www/yourdomain1.com/public_html
ErrorLog ${APACHE_LOG_DIR}/yourdomain1.com-error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain1.com-access.log combined
</VirtualHost>
To enable the new virtual host file we need to create a symbolic link from the virtual host file to the sites-enabled
directory, which is read by apache2 during startup. To enable the virtual host is by using the a2ensite
helper i.e.
sudo a2ensite yourdomain1.com
sudo systemctl restart apache2.service
Once done, test the configuration for any syntax errors with:
sudo apachectl configtest
If there are no errors you will see the following output:
Syntax OK
Now that you have your virtual hosts configured, you can test your set up by opening any browser and browse to the server domain name. You should see that everything is working correctly.
You should now have the ability to set up an Apache2 Virtual Host configuration to host multiple domains on Ubuntu server. You can repeat the steps we outlined above and create additional virtual hosts for all your domains.
If you are facing any problems, feel free to leave a comment.
The post How To Set Up Apache2 Virtual Hosts on Ubuntu appeared first on PixelsPress.
]]>The post How to Install Apache2 on Ubuntu appeared first on PixelsPress.
]]>Below are the steps we need to follow to install Apache2:
Before to install Apache2 server, run the following commands first to update Ubuntu:
sudo apt update
sudo apt upgrade
Next, install Apache web server:
sudo apt install apache2
That’s it, Apache2 is installed and active. You can check the Apache2 service status by using the following command:
sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-04-16 00:35:04 UTC; 1h 30min ago
Process: 1376 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Process: 1381 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 1396 (apache2)
Tasks: 11 (limit: 502)
Memory: 84.1M
CGroup: /system.slice/apache2.service
├─1396 /usr/sbin/apache2 -k start
├─2159 /usr/sbin/apache2 -k start
├─2160 /usr/sbin/apache2 -k start
├─2161 /usr/sbin/apache2 -k start
├─2162 /usr/sbin/apache2 -k start
├─2163 /usr/sbin/apache2 -k start
├─2164 /usr/sbin/apache2 -k start
├─2165 /usr/sbin/apache2 -k start
├─2166 /usr/sbin/apache2 -k start
├─2167 /usr/sbin/apache2 -k start
└─2198 /usr/sbin/apache2 -k start
Apr 16 00:35:04 yourdomain.com systemd[1]: Starting The Apache HTTP Server...
Apr 16 00:35:04 yourdomain.com systemd[1]: Started The Apache HTTP Server.
The other following commands used to stop, start and enable Apache2 service.
sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
Note: Ubuntu 22.04 uses the UFW firewall by default, which stands for “Uncomplicated Firewall.” When the firewall is enabled, it will block all incoming connections. To allow incoming connections on certain ports, you have to configure the UFW firewall.
To open ports for a Apache2 web server, you have to execute the following command:
sudo ufw allow in "Apache Full"
Now to check your current firewall configuration settings, please run the following command:
sudo ufw status verbose
and the output will be:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22 ALLOW IN Anywhere
80,443/tcp (Apache Full) ALLOW IN Anywhere
22 (v6) ALLOW IN Anywhere (v6)
80,443/tcp (Apache Full (v6)) ALLOW IN Anywhere (v6)
To verify that Apache2 working, open your browser, write your domain name or server IP address i.e. http://YOUR_IP_OR_DOMAIN/
and you will see the following default Ubuntu Apache welcome page.
/etc/apache2
directory.apache2.conf
is the main configuration file. It puts the pieces together by including all remaining configuration files when starting up the web server./etc/apache2/ports.conf.
is always included from the main configuration file. It is used to determine the listening ports for incoming connections, and this file can be customized anytime./etc/apache2/sites-available
directory. The configuration files found in this directory are not used by Apache unless they are linked to the /etc/apache2/sites-enabled
directory.*-available/
counterparts. These should be managed by using our helpers a2enmod, a2dismod, a2ensite, a2dissite, and a2enconf, a2disconf. See their respective man pages for detailed information.yourdomain.com
then the virtual host configuration file should be named /etc/apache2/sites-available/yourdomain.com.conf
/etc/apache2/conf-available/
directory. Files in the conf-available
directory can be enabled by creating a symlink to the /etc/apache2/conf-enabled/
with the a2enconf command and disabled with the a2disconf command./var/log/apache/
directory. It is recommended to have different access and error log files for each vhost./var/www/html
. You can make your own virtual hosts under /var/www.
You have learned how to install Apache2 on Ubuntu server. You can repeat the steps we outlined above and install Apache2 on additional new Ubuntu servers.
If you have a question or facing any problems, feel free to leave a comment.
The post How to Install Apache2 on Ubuntu appeared first on PixelsPress.
]]>