Config apple-app-site-association file with WordPress - php

I’m trying to implement iOS Universal Links, I need to serve an apple-app-association file at the root of my WordPress.
How could I serve my apple-app-association file with Content-type: "application/pkcs7-mime" in WordPress?
I tried to directly upload it, but of course it didn't work because I need to modify the Content-type of the apple-app-association to: Content-type: "application/pkcs7-mime"

Since the apple-app-site-association file is not a WordPress file, you have to configure the content type at the server level. This is different depending on environment (Apache vs. nginx, for example). This can be hard, if your host doesn't allow access to low level configuration.
Apache configuration
Modify the /etc/apache2/sites-available/default-ssl (or equivalent) file to include the snippet:
<Directory /path/to/root/directory/>
...
<Files apple-app-site-association>
Header set Content-type "application/pkcs7-mime"
</Files>
</Directory>
nginx configuration
Modify the /etc/nginx/sites-available/ssl.example.com (or equivalent) file to include the location /apple-app-assocation snippet:
server {
...
location /apple-app-site-association {
default_type application/pkcs7-mime;
}
}
Source: https://gist.github.com/anhar/6d50c023f442fb2437e1#modifying-the-content-type
In theory I believe it is possible to do the Apache configuration via a .htaccess file, but I've never tried.
You may prefer to look into a free hosted deep link service like Branch (full disclosure: I'm in the Branch team) or Firebase Dynamic Links to handle all of this for you.

In case anyone is in the same situation I was where my website is hosted on Bitnami WordPress (e.g. through AWS), your root directory path is /opt/bitnami/apps/wordpress/htdocs. Once you've copied your association file there, the place to make the configuration change for the content type header described in Alex's answer is /opt/bitnami/apps/wordpress/conf/httpd-app.conf. Finally, you'll need to restart Apache for the configuration change to kick in, using the command sudo apachectl -k graceful. You can verify that your setup is correct using this validator tool.
See my post here for more details.

The easiest way to have the apple-app-site-association file delivered with content type application/json or application/pkcs7-mime in Apache is to add an .htaccess file in the same directory with the following contents:
<Files apple-app-site-association>
ForceType application/json
</Files>
or
<Files apple-app-site-association>
ForceType application/pkcs7-mime
</Files>
Then you don't have to add it to your server configuration.
Credit goes to http://redquark.com/wp/?p=209

For AWS / lightsail
you can simply connect via ssh extension from vscode -
(just configure ssh config with pem file - should look like this)
Host bitnami-wordpress
HostName 111.1.1.1 (your external ec2 ip address)
User bitnami
IdentityFile /Users/USERNAME/your-ec2-pem-file.pem
Now just open up the /opt/bitnami/wordpress folder
Just drag and drop the apple-app-site-association file into this directory
Open .htaccess / add this at bottom.
<Files apple-app-site-association>
Header set Content-type "application/pkcs7-mime"
</Files>
TROUBLESHOOTING
if you get a permissions problem saving file - you can save it as a different name. eg. 2.htaccess
open a new terminal -
then remove old file (you'll likely need to change permissions to appropriate user. For lightsail - bitnami it's sudo chown -R bitnami:daemon .htaccess
rm .htaccess
mv 2.htaccess .htaccess
(WARNING ONLY FOR AWS) sudo chown -R bitnami:daemon .htaccess
sudo apachectl -k graceful

I was able to upload the file after adding the following to wp-config.php file:
define('ALLOW UNFILTERED UPLOADS', true);
Now when I have the file uploaded I again removed the line for security reasons and I can further update the content of apple-app-site-association file through FTP.

Related

How to setup/access page in subdirectory of separate project for a Laravel/OctoberCMS website?

I have a website running an OctoberCMS theme that I built. It's running on a server from DigitalOcean. I need to add a separate project (namely code from Matomo analytics) on the same server and access a public page (e.g. my_site.com/matomo). I'm new enough to Laravel and server configurations that I'm unsure of how I need to configure the index.php files or maybe something like .htaccess so that I can access my_site.com/matomo.
Here's my file structure
/var/www/html/
index.php (serves the pages of my project)
artisan
bootstrap/
config/
modules/
plugins/
server.php
storage/
themes/
vendor/
matomo/ (for installing the analytics for the site)
index.php
matomo.php
piwik.php
config/
a number of other files I can enumerate if necessary
I've followed the instructions from matomo but to no avail. When I try to go to my_site.com/matomo I just get a 404 from my website with my theme's formatting for it.
I know this shouldn't be hard. Thanks!
EDIT: The home page of my website is at my_site.com, as desired. The various pages are at my_site.com/page_name. This is configured fine for my purposes.
Now, for Matomo, the instructions say:
Open your FTP client and upload the Matomo files in ‘binary mode’ to the desired location on your web server. For example using the Filezilla FTP client, you can enable Binary mode transfer in the top menu Transfer > Transfer type > Binary). All files can be uploaded to a “analytics” sub-directory in your public www folder, for example http://yourdomain.org/analytics/ or you could setup Matomo in its own subdomain and upload all the files at http://analytics.example.org/
If you have SSH access to your server, you can use it instead of FTP as it is much faster: run
wget https://builds.matomo.org/matomo.zip && unzip matomo.zip
So, I used the wget option to add it to what I believe is the "public www folder", /var/www/html. So the instructions lead me to believe I can go to my_site.com/analytics/ and then view the GUI webpage for further install and setup. However, this doesn't work as it takes to a 404 page that's setup for the rest of my site. I also don't know that I'd expect it to work as none of the files or folders in Matomo are named "analytics" -- I've also tried my_site.com/matomo for the record. So, this is to say, I don't know where the Matomo page is presented.
I don't have any experience with Matomo, but from the question I understood that you want to install two software X as CMS and Y as Matomo.
Your web server(I assume Apache is the web server) will serve all request to the following path: /var/www/html/index.php. Which belong to software X. Your request my_site.com/matomo will be served to software X, and because X doesn't expect this request it will output 404 Not Found error.
The first solution: which is the bad solution and harder solution is to edit /var/www/html/index.php and combine it with Y index.php if request have matomo in the URL.
The second solution: which is the optimal and better solution is to separate X and Y. It could be done in several ways:
You can combine all X files in a folder under /var/www/html/x, and all Y files in folder under /var/www/html/y. Then you can access x using the following URL my_site.com/x and y using my_site.com/y.
If the first way in not possbile because you need to have X as root URL like my_site.com. Then you can combine all Y file under the following folder /var/www/html/matomo. Then you need to create sub domain (virtual host for Y).
Create virtual host using Ubuntu and Apache:
sudo touch /etc/apache2/sites-available/matomo.my_site.com.conf
Then edit the file using your favorite text editor I will use nano
sudo nano /etc/apache2/sites-available/matomo.my_site.com.conf
and past the following code:
<VirtualHost *:80>
ServerAdmin admin#my_site.com
ServerName matomo.my_site.com
DocumentRoot /var/www/html/matomo/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Change my_site.com to your domain.
Then you need to enable the virtual host
sudo a2ensite /etc/apache2/sites-available/matomo.my_site.com.conf
Then restart apache to see the result.
sudo systemctl restart apache2
Your matomo will be under the following URL matomo.my_site.com
If you are not using Ubuntu or Apache, tell me what are you using to update my answer.
You don't need to fix anything in index.php. Analytics counters can be added to the layout (~/themes/mytheme/layout/mylayout.htm) of the page between the
<head>
...
</head>
or
<body>
...
</body>
according to the instructions of your meter
See https://github.com/octobercms/october/issues/1615. You need to add the folder you want to allow access to as an exclusion to the October CMS .htaccess, and then also disable the line that disables running any PHP file other than index.php.
So replace RewriteEngine On with
RewriteEngine On
# Allow access to Matomo
RewriteRule ^(matomo)($|/) - [L]
and then comment out RewriteCond %{REQUEST_FILENAME} \.php$ so it becomes # RewriteCond %{REQUEST_FILENAME} \.php$.

How to secure .env file in laravel 5.4?

I am Working with laravel 5.4. And i have problem with .env and composer.json file. Anyone can access from any browser and anyone can see my database credentials so please help me to protect this files.
you can add following code to your .htaccess (make sure your .htaccess file should be in root folder not in public)file to deny the permission of .env file
<FilesMatch "^\.env">
Order allow,deny
Deny from all
</FilesMatch>
Simply you add below code to your .htaccess file to set permission of .env and composer.json file.
<Files .env>
Order allow,deny
Deny from all
</Files>
<Files composer.json>
Order allow,deny
Deny from all
</Files>
And below line for disabling directory browsing
Options All -Indexes
Remember that once your server is configured to see the public folder as the document root, no one can view the files that one level down that folder, which means that your .env file is already protected, as well your entire application. - That is the reason the public folder is there, security. - The only directories that you can see in your browser if you set the document root to the public folder is the folders that are there, like the styles and scripts.
You can make a test like this:
Enter in your project directory with the terminal and hit this:
php -t public -S 127.0.0.1:80
The -t means the document root, where the PHP built-in web server will interpreter as the document root. - see bellow:
-t <docroot> Specify document root <docroot> for built-in web server.
Now try to access the .env file, and you will see that you will get a 404 that the resource as not found.
Of course it's just an example, you will need to configure your sever to do the same.
Nobody can view these files via the browser because the root of your website is located at /public and the composer.json and .env files are outside of this scope.
The only way to view these files is actually connecting to the web server and going to the corresponding folder.
Make sure it is on your .gitignore and you create it locally on your server.

Why does renameing .htaccess file allow for drupal 7 install on remote server?

I'm installing drupal 7 on a remote server. After running tar -xvzf on the install file and moving all the files to a folder just under the public_html folder I enter the site url in to a browser. The result is a 500 server error. If I then rename the .htaccess file to hide.htaccess.hide the install process will begin. I've experimented w/ the line:
RewriteBase /drupal
with various paths/folders that make sense but always still a 500 error.
Questions:
What is the .htaccess file doing to prevent the install?
What is the issues if any of doing the rename?
By default apache allow to override limited settings throught .htaccess file, the .htaccess file provided by drupal overrides more items than allowed to you need to enable to allow override all setting in your vhost config file like...
AllowOverride All
AccessFileName .htaccess
Please refer to following links more details
How to Set AllowOverride all
https://www.drupal.org/getting-started/clean-urls

Laravel – Include external Project

In a Laravel project I have to include multiple projects, so that they are accessible at /example.
These projects have the structure of
/example
- index.php
- main.css
- app.js
(Usually there are more files then that.)
I have tried to use Redirect::to("example/index.php"), however this breaks all the <link>'s & <src> (where I would need to prepend /example to all of them.
This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.
What is the best way to include such external projects?
This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.
That's an excellent approach. Rather keep Laravel as Laravel and host the stuff just outside of your Laravel project.
Since you're using Apache, here's how to create a Virtual Host for that external project.
Please note - I'm assuming that your project lives in /var/www.
Decide on a URL for that project - I would use example.mylaravelproject.com. But anything will do.
Confirm the path of your project folder. For this example, we'll assume it's /var/www/example/
Run the following command (assuming you're using Ubuntu) - sudo nano /etc/apache2/sites-available/example.mylaravelproject.com.conf
Ensure the new file has the following contents:
<VirtualHost *:80>
ServerAdmin <your email address here>
ServerName example.mylaravelproject.com
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file
Run the following command sudo a2ensite example.mylaravelproject.com.conf
Run sudo nano /etc/apache2.conf
Make sure that this line appears somewhere in this file (preferrably in a <Directory> tag - AddType application/x-httpd-php .php
Then restart Apache by issuing the following command sudo service apache2 restart
Technically now your site has a valid vhost and should be working.
If you're doing this on a local environment and want to access your example project via the browser, you'll need to complete a few more steps:
sudo nano /etc/hosts - again, assuming that you're running Ubuntu
Add this line somewhere to your project: localhost example.mylaravelproject.com
Save and close that file. You should now be able to access that url via your browser.
If these steps don't work, it's likely that Apache isn't parsing the PHP files. If that's the case, try these links for some good answers on making Apache parse PHP:
Apache 2 server on ubuntu can't parse php code inside html file
Apache Virtual Host not parsing PHP

How to block access folder that not has index file

I using xampp for my project. Now i have a problem
Example i have a project like
myproject\
|-subfolder\
| |---example.php
|-index.php
Now, if i process subfolder in my address like
localhost/myproject/subfolder
i will get a list of files in subfolder (b/c subfolder haven't index file).
Have anyway to block access that (not used index file? ). That should show any message instead of list files in the folder
thanks
You should configure your apache httpd.conf file, change something like:
Options FollowSymLinks Indexes
To:
Options FollowSymLinks
And restart your apach service.
You will have to create a specific file to show the message:
For instance
localhost/myproject/subfolder/message.html
This will then show the message and not all the files.
This is the Index feature of Apache and is designed to help with easy file navigation. Obviously this is undesirable on some servers. To turn it off you need to edit Apache's config file which is usually found in /etc/apache2/apache2.conf on Ubuntu or /etc/httpd/conf/httpd.conf on CentOS / RedHat but could be somewhere else, you did not specify operating system in question. Anyway, find it and edit it.
Search for Indexes in this file and change the value to -Indexes.
Then restart Apache with the following command:
sudo service apache2 restart
(on Ubuntu)
sudo service httpd restart
(on CentOS or RedHat)
Directory listing should now be switched off for all your folders.

Categories